问题描述
我正在尝试将Google Speech to Text api用于卡纳达语,并且我将EXTRA_LANGUAGE设置为"kn",但仍无法正常工作.
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();
}
}
请注意,语言环境存在于设备中.其他语言(如印地语(hi),泰米尔语(ta)和日语(ja))也适用,但不适用于泰卢固语(te),马拉雅拉姆语(ml),卡纳达语(kn).如果我在这里做错了任何事情,请帮忙.
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.
推荐答案
经过数小时的研究,我终于找到了解决方法.
After hours of research, I finally found solution.
在下面的代码行中,我应该发送"kn_IN"而不是"kn".这样就可以了.
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");
此方法适用于上述所有语言. ("te_IN","ml_IN")
This method works for all the languages mentioned above. ("te_IN", "ml_IN")
这篇关于Google语音转文字:将其他语言设置为"kn",但不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!