How to change the language of Google speech recognition
Asked Answered
O

2

6

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?

Otolith answered 9/4, 2018 at 12:3 Comment(0)
S
15

here's the relevant line of documentataion.

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

Sellingplater answered 9/4, 2018 at 17:12 Comment(1)
You can find all the possible language codes here : cloud.google.com/speech-to-text/docs/languagesPotentiate
S
0
try:
    voise = r.recognize_google(audio, language="fr-FR")
except sr.UnknownValueError:
    speak('understand')
return voise
Stoss answered 21/4, 2020 at 12:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.