0

Code:

def get_audio() -> str:
    r = sr.Recognizer()
    with sr.Microphone() as microphone:
        print("Listening ...")
        audio = r.listen(microphone)  # stuck at this line
        print("Sopped Listening")
        said = ""

        try:
            said = r.recognize_google(audio)
        except Exception as e:
            return str(e)
    return said

So when I run the function, it prints "Listening...", goes to the next line and nothing happens. It never gets to "Stopped listening" line. It is guaranteed that there is a connected microphone used by the OS. So might be the problem?

Zozo
  • 81
  • 2
  • 8
  • 1
    You can add a time limit: https://stackoverflow.com/questions/41359535/python-speechrecognition-attributeerror-exit-with-sr-microphone – piertoni Apr 09 '21 at 10:59
  • Does this answer your question? [How do i control when to stop the audio input?](https://stackoverflow.com/questions/43720729/how-do-i-control-when-to-stop-the-audio-input) – jbflow Apr 09 '21 at 11:00
  • 1
    because of noise it can create problem so use this to avoid noise r.adjust_for_ambient_noise(microphone) just below with statement – Bhavya Parikh Apr 09 '21 at 12:00

0 Answers0