Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,10 +16,10 @@ if "history" not in st.session_state:
|
|
16 |
if "pre_prompt_sent" not in st.session_state:
|
17 |
st.session_state.pre_prompt_sent = False
|
18 |
|
19 |
-
def recognize_speech(
|
20 |
recognizer = sr.Recognizer()
|
21 |
|
22 |
-
with io.BytesIO(
|
23 |
try:
|
24 |
audio_text = recognizer.recognize_google(audio_file, language="es-ES")
|
25 |
if show_messages:
|
@@ -30,7 +30,7 @@ def recognize_speech(audio_data, show_messages=True):
|
|
30 |
st.warning("No se pudo reconocer el audio. ¿Intentaste grabar algo?")
|
31 |
audio_text = ""
|
32 |
except sr.RequestError:
|
33 |
-
st.error("
|
34 |
audio_text = ""
|
35 |
|
36 |
return audio_text
|
@@ -94,8 +94,8 @@ def main():
|
|
94 |
|
95 |
with wave.open(temp_audio_file_path, 'w') as wave_file:
|
96 |
wave_file.setnchannels(1)
|
97 |
-
wave_file.setsampwidth(2)
|
98 |
-
wave_file.setframerate(44100)
|
99 |
wave_file.writeframes(audio_bytes)
|
100 |
|
101 |
audio_text = recognize_speech(audio_bytes)
|
|
|
16 |
if "pre_prompt_sent" not in st.session_state:
|
17 |
st.session_state.pre_prompt_sent = False
|
18 |
|
19 |
+
def recognize_speech(audio_bytes, show_messages=True):
|
20 |
recognizer = sr.Recognizer()
|
21 |
|
22 |
+
with io.BytesIO(audio_bytes) as audio_file:
|
23 |
try:
|
24 |
audio_text = recognizer.recognize_google(audio_file, language="es-ES")
|
25 |
if show_messages:
|
|
|
30 |
st.warning("No se pudo reconocer el audio. ¿Intentaste grabar algo?")
|
31 |
audio_text = ""
|
32 |
except sr.RequestError:
|
33 |
+
st.error("Háblame para comenzar!")
|
34 |
audio_text = ""
|
35 |
|
36 |
return audio_text
|
|
|
94 |
|
95 |
with wave.open(temp_audio_file_path, 'w') as wave_file:
|
96 |
wave_file.setnchannels(1)
|
97 |
+
wave_file.setsampwidth(2)
|
98 |
+
wave_file.setframerate(44100)
|
99 |
wave_file.writeframes(audio_bytes)
|
100 |
|
101 |
audio_text = recognize_speech(audio_bytes)
|