How to change the language of Google speech recognition

Sudar picture Sudar · Apr 9, 2018 · Viewed 19.2k times · Source

My code:

with sr.Microphone() as source:
    audio = r.listen(source)
    try:
        print("You said: " + r.recognize_google(audio) + "in french")
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service")

I would like to change the listening language to french. How should i do that?

Answer

e.s. picture e.s. · Apr 9, 2018

here's the relevant line of documentataion.

try r.recognize_google(audio, language="fr-FR")