'Google speech to text: Extra language set to "kn" but not working
I am trying to use Google Speech to Text API for Kannada language and I am setting EXTRA_LANGUAGE to "kn" for the same but it is not working.
Below is the code I am using.
Locale locale = new Locale("kn");
//Locale.setDefault(locale);
Log.e(TAG, "Locale " + locale.getLanguage() + " present: " + isLocalePresent(locale));
if (isLocalePresent(locale)) {
//int randomInt = random.nextInt(allItemsLength);
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, locale.getLanguage());
//intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Try saying \"" + mergedFinalArray.get(randomInt) + "\"");
try {
startActivityForResult(intent, REQ_CODE_K2E_SPEECH_INPUT);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), R.string.missing_in_voc, Toast.LENGTH_SHORT).show();
}
}
Please note that the locale is present in the device. The same is working for other languages like Hindi (hi), Tamil (ta) and Japanese (ja) but not for Telugu (te), Malayalam (ml), Kannada (kn). Am I doing anything wrong?
Solution 1:[1]
After hours of research, I finally found solution.
In the below line of code, I should send "kn_IN" instead of "kn". This made it work.
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "kn_IN");
This method works for all the languages mentioned above. ("te_IN", "ml_IN")
Solution 2:[2]
Have you tried "kan"?
According to this link Locale accepts ISO 639 alpha-2 or alpha-3 and on the following list the code for Kannada language on ISO 639-2 and 3 is "kan".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Varun A M |
Solution 2 | Natan Felipe |