I am using the speech recognition library to detect speech. I am using streamlit for the interface. A button triggers the speech recognition process. The first time it works fine.The audio is recognized and transcribed.
When I press the button a second time, it keeps running/listening
At this point I don’t know if the problem is with streamlit or with the speech_recognition part.
This is the function doing the SR:
import speech_recognition as sr
r= sr.Recognizer()
def get_audio():
with sr.Microphone() as source:
r.pause_threshold=0.5
audio=r.listen(source)
said=""
try:
print("inside Try")
said=r.recognize_google(audio, language="fr-FR")
print(said)
except sr.UnknownValueError:
print("Exception: Google speech recogniton could not understand audio")
except sr.RequestError as e:
print(f"Could not request results from Google Speech Recognition service: {e}")
return said
The second time it’s not even entering the Try block
This is an excerpt from the call to get_audio():
if st.button("Click-me to speak"):
text= get_audio()
query = st.text_input("Input your prompt here: ", text, key="transcription")
if query:
submit = True