Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from audiorecorder import audiorecorder
|
|
7 |
import speech_recognition as sr
|
8 |
from pydub import AudioSegment
|
9 |
|
10 |
-
pre_prompt_text = "
|
11 |
|
12 |
if "history" not in st.session_state:
|
13 |
st.session_state.history = []
|
@@ -25,14 +25,14 @@ def recognize_speech(audio_data, show_messages=True):
|
|
25 |
try:
|
26 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|
27 |
if show_messages:
|
28 |
-
st.subheader("
|
29 |
st.write(audio_text)
|
30 |
-
st.success("
|
31 |
except sr.UnknownValueError:
|
32 |
-
st.warning("
|
33 |
audio_text = ""
|
34 |
except sr.RequestError:
|
35 |
-
st.error("
|
36 |
audio_text = ""
|
37 |
|
38 |
return audio_text
|
@@ -79,26 +79,30 @@ def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.
|
|
79 |
|
80 |
def text_to_speech(text, speed=1.3):
|
81 |
tts = gTTS(text=text, lang='es')
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
87 |
|
88 |
def main():
|
89 |
-
audio_data = audiorecorder("
|
90 |
|
91 |
if not audio_data.empty():
|
92 |
-
st.audio(audio_data.export().read(), format="audio/
|
93 |
-
audio_data.export("audio.
|
94 |
-
audio_text = recognize_speech("audio.
|
95 |
|
96 |
if audio_text:
|
97 |
output, audio_file = generate(audio_text, history=st.session_state.history)
|
98 |
|
99 |
if audio_file is not None:
|
100 |
st.markdown(
|
101 |
-
f"""<audio controls="controls" src="data:audio/
|
102 |
unsafe_allow_html=True)
|
103 |
|
104 |
if __name__ == "__main__":
|
|
|
7 |
import speech_recognition as sr
|
8 |
from pydub import AudioSegment
|
9 |
|
10 |
+
pre_prompt_text = "Eres una IA conductual, tus respuestas deber谩n ser breves, est贸icas y humanistas."
|
11 |
|
12 |
if "history" not in st.session_state:
|
13 |
st.session_state.history = []
|
|
|
25 |
try:
|
26 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|
27 |
if show_messages:
|
28 |
+
st.subheader("Texto Reconocido:")
|
29 |
st.write(audio_text)
|
30 |
+
st.success("Reconocimiento de voz completado.")
|
31 |
except sr.UnknownValueError:
|
32 |
+
st.warning("No se pudo reconocer el audio. 驴Intentaste grabar algo?")
|
33 |
audio_text = ""
|
34 |
except sr.RequestError:
|
35 |
+
st.error("Hablame para comenzar!")
|
36 |
audio_text = ""
|
37 |
|
38 |
return audio_text
|
|
|
79 |
|
80 |
def text_to_speech(text, speed=1.3):
|
81 |
tts = gTTS(text=text, lang='es')
|
82 |
+
audio_fp = io.BytesIO()
|
83 |
+
tts.write_to_fp(audio_fp)
|
84 |
+
audio_fp.seek(0)
|
85 |
+
audio = AudioSegment.from_file(audio_fp, format="mp3")
|
86 |
+
modified_speed_audio = audio.speedup(playback_speed=speed)
|
87 |
+
modified_audio_fp = io.BytesIO()
|
88 |
+
modified_speed_audio.export(modified_audio_fp, format="mp3")
|
89 |
+
modified_audio_fp.seek(0)
|
90 |
+
return modified_audio_fp
|
91 |
|
92 |
def main():
|
93 |
+
audio_data = audiorecorder("Presiona para hablar", "Deteniendo la grabaci贸n...")
|
94 |
|
95 |
if not audio_data.empty():
|
96 |
+
st.audio(audio_data.export().read(), format="audio/wav")
|
97 |
+
audio_data.export("audio.wav", format="wav")
|
98 |
+
audio_text = recognize_speech("audio.wav")
|
99 |
|
100 |
if audio_text:
|
101 |
output, audio_file = generate(audio_text, history=st.session_state.history)
|
102 |
|
103 |
if audio_file is not None:
|
104 |
st.markdown(
|
105 |
+
f"""<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_file.read()).decode()}" type="audio/mp3" id="audio_player"></audio>""",
|
106 |
unsafe_allow_html=True)
|
107 |
|
108 |
if __name__ == "__main__":
|