Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ from gtts import gTTS
|
|
6 |
from audiorecorder import audiorecorder
|
7 |
import speech_recognition as sr
|
8 |
from pydub import AudioSegment
|
|
|
9 |
|
10 |
if "history" not in st.session_state:
|
11 |
st.session_state.history = []
|
@@ -13,8 +14,16 @@ if "history" not in st.session_state:
|
|
13 |
def recognize_speech(audio_data, show_messages=True):
|
14 |
recognizer = sr.Recognizer()
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
try:
|
20 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|
|
|
6 |
from audiorecorder import audiorecorder
|
7 |
import speech_recognition as sr
|
8 |
from pydub import AudioSegment
|
9 |
+
import Microphone, Recognizer from speech_recognition
|
10 |
|
11 |
if "history" not in st.session_state:
|
12 |
st.session_state.history = []
|
|
|
14 |
def recognize_speech(audio_data, show_messages=True):
|
15 |
recognizer = sr.Recognizer()
|
16 |
|
17 |
+
microphone_list = sr.Microphone.list_working_microphones()
|
18 |
+
|
19 |
+
if not microphone_list:
|
20 |
+
raise ValueError("No se encontraron micr贸fonos funcionando.")
|
21 |
+
|
22 |
+
selected_microphone_index = microphone_list[0]
|
23 |
+
|
24 |
+
with sr.Microphone(device_index=selected_microphone_index) as source:
|
25 |
+
recognizer.adjust_for_ambient_noise(source, duration=5)
|
26 |
+
audio = recognizer.listen(source, timeout=5)
|
27 |
|
28 |
try:
|
29 |
audio_text = recognizer.recognize_google(audio, language="es-ES")
|