salomonsky commited on
Commit
5a44809
·
verified ·
1 Parent(s): 10d0552

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -4,7 +4,7 @@ import io
4
  from huggingface_hub import InferenceClient
5
  from gtts import gTTS
6
  from audiorecorder import audiorecorder
7
- import speechrecognizer as sr
8
  import librosa
9
 
10
  def record_audio(filename="audio.wav", duration=5):
@@ -19,6 +19,28 @@ def record_audio(filename="audio.wav", duration=5):
19
  with open(filename, "wb") as f:
20
  f.write(audio_data.get_wav_data())
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  def format_prompt(message, history):
23
  prompt = "<s>"
24
 
 
4
  from huggingface_hub import InferenceClient
5
  from gtts import gTTS
6
  from audiorecorder import audiorecorder
7
+ import speechrecognition as sr
8
  import librosa
9
 
10
  def record_audio(filename="audio.wav", duration=5):
 
19
  with open(filename, "wb") as f:
20
  f.write(audio_data.get_wav_data())
21
 
22
+ def recognize_speech(audio_data, show_messages=True):
23
+ recognizer = sr.Recognizer()
24
+ audio_recording = sr.AudioFile(audio_data)
25
+
26
+ with audio_recording as source:
27
+ audio = recognizer.record(source)
28
+
29
+ try:
30
+ audio_text = recognizer.recognize_google(audio, language="es-ES")
31
+ if show_messages:
32
+ st.subheader("Texto Reconocido:")
33
+ st.write(audio_text)
34
+ st.success("Reconocimiento de voz completado.")
35
+ except sr.UnknownValueError:
36
+ st.warning("No se pudo reconocer el audio. ¿Intentaste grabar algo?")
37
+ audio_text = ""
38
+ except sr.RequestError:
39
+ st.error("No he recibido ningun audio. Por favor, inténtalo de nuevo.")
40
+ audio_text = ""
41
+
42
+ return audio_text
43
+
44
  def format_prompt(message, history):
45
  prompt = "<s>"
46