Google speech to text: Extra language set to “kn” but not working

社会主义新天地 提交于 2019-12-24 10:48:04

问题


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.


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




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



来源:https://stackoverflow.com/questions/51048466/google-speech-to-text-extra-language-set-to-kn-but-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!