1

In my application I'm using SpeechRecognizer, in order to detect what the user said. My device's language is set to English and it works perfect when I say something in English, but when I say something in other languages, for example - Hebrew, it doesn't work all the time as it works for English, until I set the device's language to Hebrew and then it works OK. I'm trying to avoid from setting the device's language and want it to automatically detect the user language. I've noticed that "OK Google" works and detect the correct words in Hebrew even when the device's language is set to English.

For the meantime, what I tried to do is when the user enter for the first time to my application, I'm asking him to enter his country. Then when I have his country -> I'm getting the country code and then I create a Locale using the country code. This locale is then sent as the language to the speech recognizer. But it didn't help..

// example of how to get the locale using the country code
Locale myLocale = null;
String toSearch = "IL";

toSearch = toSearch.trim().toLowerCase();

for (Locale locale : Locale.getAvailableLocales())
{
    if(locale.getCountry().trim().toLowerCase().contains(toSearch))
    {
        myLocale = locale;
        break;
    }
}

// example of how I'm sending the locale
Intent recIntent= new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recIntent.putExtra(RecognizerIntent.ExtraLanguage,myLocale);
Elior
  • 3,178
  • 6
  • 37
  • 67

0 Answers0