Google speech to text: Extra language set to “kn”

2019-07-26 17:22发布

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.

Could somebody please help?

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). Please help if I am doing anything wrong here.

2条回答
手持菜刀,她持情操
2楼-- · 2019-07-26 17:44

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".

查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-26 18:04

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")

查看更多
登录 后发表回答