Search code examples
pythonpython-2.7speech-recognitiongoogle-speech-api

Changing Language in Python SpeechRecognition


I am using SpeechRecognition in my Python application. However, it can only recognise English. I want it to recognise other languages too. I know it is possible somehow. Can anyone please help me with the syntax to change the language of speechrecognition in Python2.7 Please help! Thanks in advance. Here is my code so far :

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
    try:
        audio = r.listen(source)
        text = r.recognize_google(audio)
    except:
        pass

Solution

  • Language can be passed as argument to the recognize_google function

    r.recognize_google(audio, language="hi-IN")
    

    A list of supported language tags can be found in this StackOverflow answer http://stackoverflow.com/a/14302134