salomonsky commited on
Commit
686ef78
verified
1 Parent(s): f2c3ba6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -15,27 +15,26 @@ microphone = sr.Microphone()
15
 
16
  # reconociendo voz
17
  def recognize_speech_with_vad(audio_data, show_messages=True):
18
- with microphone as source:
19
- try:
20
- st.info("Escuchando...")
21
- audio_data.record(source, vad_enabled=True)
22
  st.success("Fin de la grabaci贸n. Procesando audio...")
23
- audio_text = recognizer.recognize_google(audio_data, language="es-ES")
24
 
25
- if show_messages:
26
- st.subheader("Texto Reconocido:")
27
- st.write(audio_text)
28
 
29
- except sr.UnknownValueError:
30
- st.warning("No se pudo reconocer el audio. 驴Intentaste grabar algo?")
31
- audio_text = ""
32
- except sr.RequestError:
33
- st.error("Hablame para comenzar!")
34
- audio_text = ""
35
-
36
- return audio_text
37
 
 
 
 
 
 
 
38
 
 
 
39
  # preparando entrada para el modelo de lenguaje
40
  def format_prompt(message, history):
41
  prompt = "<s>"
@@ -98,17 +97,16 @@ def audio_player_markup(audio_file):
98
  # interfaz de usuario
99
  def main():
100
  st.title("Chatbot de Voz a Voz")
101
- st.info("Habla para grabar...")
102
- audio_data = audiorecorder("Escuchando...", "Deteniendo la grabaci贸n...")
103
 
104
  if not audio_data.empty():
105
  st.audio(audio_data.export().read(), format="audio/wav")
106
  audio_data.export("audio.wav", format="wav")
107
- audio_text = recognize_speech("audio.wav")
108
 
109
  if audio_text:
110
  st.success("Frase detectada. Procesando audio...")
111
- output, audio_file = generate(audio_text, history=st.session_state.history)
112
 
113
  if audio_file is not None:
114
  st.markdown(audio_player_markup(audio_file), unsafe_allow_html=True)
 
15
 
16
  # reconociendo voz
17
  def recognize_speech_with_vad(audio_data, show_messages=True):
18
+ try:
19
+ with sr.AudioFile(audio_data) as source:
20
+ audio_data = recognizer.record(source, vad_enabled=True)
 
21
  st.success("Fin de la grabaci贸n. Procesando audio...")
 
22
 
23
+ audio_text = recognizer.recognize_google(audio_data, language="es-ES")
 
 
24
 
25
+ if show_messages:
26
+ st.subheader("Texto Reconocido:")
27
+ st.write(audio_text)
 
 
 
 
 
28
 
29
+ except sr.UnknownValueError:
30
+ st.warning("No se pudo reconocer el audio. 驴Intentaste grabar algo?")
31
+ audio_text = ""
32
+ except sr.RequestError:
33
+ st.error("Hablame para comenzar!")
34
+ audio_text = ""
35
 
36
+ return audio_text
37
+
38
  # preparando entrada para el modelo de lenguaje
39
  def format_prompt(message, history):
40
  prompt = "<s>"
 
97
  # interfaz de usuario
98
  def main():
99
  st.title("Chatbot de Voz a Voz")
100
+ audio_data = audiorecorder("Deteniendo la grabaci贸n...", vad_enabled=True)
 
101
 
102
  if not audio_data.empty():
103
  st.audio(audio_data.export().read(), format="audio/wav")
104
  audio_data.export("audio.wav", format="wav")
105
+ audio_text = recognize_speech_with_vad("audio.wav")
106
 
107
  if audio_text:
108
  st.success("Frase detectada. Procesando audio...")
109
+ output, audio_file = generate(audio_text, history=st.session_state.history)
110
 
111
  if audio_file is not None:
112
  st.markdown(audio_player_markup(audio_file), unsafe_allow_html=True)