0

the first except block runs every time i speak into the microphone, please help!

'''

import speech_recognition as sr  

# get audio from the microphone                                                                       
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Speak:")                                                                                   
    audio = r.listen(source)   

try:
    print("You said " + r.recognize_google(audio))
except sr.UnknownValueError:
    print("Could not understand audio")
except sr.RequestError as e:
    print("Could not request results; {0}".format(e))

'''

2 Answers2

0

I think your RequestError is a result of the Google API reaching its limits. Google says:

Audio longer than ~1 minute must use the uri field to reference an audio file in Google Cloud Storage. See here for the documentation

So you need to create an account here and use the API key given. Then upload the audio to the cloud and then use that link as a parameter in your program.

This is the only solution Google gives. Hope it helps :)

Sahith Kurapati
  • 1,617
  • 10
  • 14
0

THIS SHOULD HELP IT

instead of '+' I added ',' in the print statement of try block

    import speech_recognition as sr  

    # get audio from the microphone                                                                       
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Speak:")                                                                                   
        audio = r.listen(source)   

    try:
        print("You said " ,r.recognize_google(audio))
    except sr.UnknownValueError:
        print("Could not understand audio")
    except sr.RequestError as e:
        print("Could not request results; {0}".format(e))