Search code examples
pythonspeech-recognition

Python multilingual SpeechRecognition


I have a speech recognition in Python project. So, I need it to recognize 5 languages.

My code:

import speech_recognition as sr
r = sr.Recognizer() 
with sr.Microphone() as source:
    audio = r.listen(source)
    print(r.recognize_google(audio, language="ru-RU en-US de-DE fr-FR es-ES"))

It recognizes only english and russian speech. Please help.


Solution

  • The problem here is that the Google Speech Recognition API, which you are calling in the call to recognize_google() works on single-language models. That is, it will only accent the first language code that you pass to it. It is expecting audio to be in a single language.

    What you're describing, with speech in five different languages, is called code-switching, and the speech recognition model needs to be build specifically for code switching. AFAIK, none of the cloud speech recognition providers currently offers code switching models, and if they did, five different languages would be ... unlikely.

    Can you split the audio so that you're sending one language at a time?