Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import base64
|
|
3 |
import io
|
4 |
from huggingface_hub import InferenceClient
|
5 |
from gtts import gTTS
|
|
|
|
|
6 |
from audiorecorder import audiorecorder
|
7 |
import speech_recognition as sr
|
8 |
|
@@ -22,6 +24,9 @@ def recognize_speech(audio_data):
|
|
22 |
|
23 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|
24 |
|
|
|
|
|
|
|
25 |
def format_prompt(message, history):
|
26 |
prompt = "<s>"
|
27 |
|
@@ -63,10 +68,13 @@ def text_to_speech(text, speed=1.3):
|
|
63 |
audio_fp = io.BytesIO()
|
64 |
tts.write_to_fp(audio_fp)
|
65 |
audio_fp.seek(0)
|
66 |
-
|
|
|
|
|
|
|
67 |
|
68 |
def main():
|
69 |
-
audio_data = audiorecorder("Habla para
|
70 |
|
71 |
if "history" not in st.session_state:
|
72 |
st.session_state.history = []
|
@@ -75,12 +83,10 @@ def main():
|
|
75 |
st.audio(audio_data.export().read(), format="audio/wav")
|
76 |
audio_data.export("audio.wav", format="wav")
|
77 |
st.write(f"Frame rate: {audio_data.frame_rate}, Frame width: {audio_data.frame_width}, Duration: {audio_data.duration_seconds} seconds")
|
78 |
-
|
79 |
audio_text = recognize_speech("audio.wav")
|
80 |
|
81 |
if audio_text:
|
82 |
-
output, audio_file = generate(audio_text, history=st.session_state.history)
|
83 |
-
st.text_area("Respuesta", height=100, value=output, key="output_text", disabled=True)
|
84 |
|
85 |
if audio_file is not None:
|
86 |
st.markdown(
|
|
|
3 |
import io
|
4 |
from huggingface_hub import InferenceClient
|
5 |
from gtts import gTTS
|
6 |
+
from pydub import AudioSegment
|
7 |
+
from pydub.playback import play
|
8 |
from audiorecorder import audiorecorder
|
9 |
import speech_recognition as sr
|
10 |
|
|
|
24 |
|
25 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|
26 |
|
27 |
+
st.success("Reconocimiento de voz completado.")
|
28 |
+
return audio_text
|
29 |
+
|
30 |
def format_prompt(message, history):
|
31 |
prompt = "<s>"
|
32 |
|
|
|
68 |
audio_fp = io.BytesIO()
|
69 |
tts.write_to_fp(audio_fp)
|
70 |
audio_fp.seek(0)
|
71 |
+
audio = AudioSegment.from_mp3(audio_fp)
|
72 |
+
audio = audio.speedup(playback_speed=speed)
|
73 |
+
|
74 |
+
return audio.export(format="mp3", codec="mp3")
|
75 |
|
76 |
def main():
|
77 |
+
audio_data = audiorecorder("Habla para iniciar", "Procesando...")
|
78 |
|
79 |
if "history" not in st.session_state:
|
80 |
st.session_state.history = []
|
|
|
83 |
st.audio(audio_data.export().read(), format="audio/wav")
|
84 |
audio_data.export("audio.wav", format="wav")
|
85 |
st.write(f"Frame rate: {audio_data.frame_rate}, Frame width: {audio_data.frame_width}, Duration: {audio_data.duration_seconds} seconds")
|
|
|
86 |
audio_text = recognize_speech("audio.wav")
|
87 |
|
88 |
if audio_text:
|
89 |
+
output, audio_file = generate(audio_text, history=st.session_state.history)
|
|
|
90 |
|
91 |
if audio_file is not None:
|
92 |
st.markdown(
|