Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ from huggingface_hub import InferenceClient
|
|
5 |
from gtts import gTTS
|
6 |
from audiorecorder import audiorecorder
|
7 |
import speech_recognition as sr
|
8 |
-
import os
|
9 |
|
10 |
def recognize_speech(audio_data):
|
11 |
recognizer = sr.Recognizer()
|
@@ -73,25 +72,21 @@ def main():
|
|
73 |
if not audio_data.empty():
|
74 |
st.audio(audio_data.export().read(), format="audio/wav")
|
75 |
audio_data.export("audio.wav", format="wav")
|
76 |
-
|
77 |
-
if os.path.exists("audio.wav"):
|
78 |
-
audio_text = recognize_speech("audio.wav")
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
else:
|
94 |
-
st.error("Error: aún no se encontro un audio.")
|
95 |
|
96 |
if __name__ == "__main__":
|
97 |
main()
|
|
|
5 |
from gtts import gTTS
|
6 |
from audiorecorder import audiorecorder
|
7 |
import speech_recognition as sr
|
|
|
8 |
|
9 |
def recognize_speech(audio_data):
|
10 |
recognizer = sr.Recognizer()
|
|
|
72 |
if not audio_data.empty():
|
73 |
st.audio(audio_data.export().read(), format="audio/wav")
|
74 |
audio_data.export("audio.wav", format="wav")
|
75 |
+
audio_text = recognize_speech("audio.wav")
|
|
|
|
|
76 |
|
77 |
+
if audio_text:
|
78 |
+
output, audio_file = generate(audio_text, history=st.session_state.history)
|
79 |
+
|
80 |
+
if audio_text:
|
81 |
+
st.session_state.history.append((audio_text, output))
|
82 |
+
|
83 |
+
if audio_file is not None:
|
84 |
+
st.markdown(
|
85 |
+
f"""
|
86 |
+
<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_file.read()).decode()}" type="audio/mp3" id="audio_player"></audio>
|
87 |
+
""",
|
88 |
+
unsafe_allow_html=True
|
89 |
+
)
|
|
|
|
|
90 |
|
91 |
if __name__ == "__main__":
|
92 |
main()
|