how to pass language in speech recognition on android apps?

旧时模样 提交于 2019-12-22 13:59:34

问题


I've been working on speech Recognition API in android and found out that the speech results vary allot when the language settings are changed , is there a way to set it programmatically ? or is there an intent to lunch the speech language settings screen ? or what else ? note: I tried to use this intent extra:

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en-US");

and

Intent detailsIntent =  new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
sendOrderedBroadcast(detailsIntent, null, new LanguageDetailsChecker(), null, Activity.RESULT_OK, null, null);

回答1:


Yes hanifs, that method didn't work for me also.

My default device language is English US, but I needed Italian for SR. Only applying all these three extras I succeded forcing Google Engine (used as default speech engine from my device) to use Italian.

String myLanguage = "it"; //or, Locale.Italian.toString()
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, myLanguage);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, myLanguage); 
intent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, myLanguage);

Try this way customizing your "myLanguage" variable, it should be ok!




回答2:


The only thing you can do for now is

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, Locale.getDefault());  

It may not work if the recognizer engine does not support this language.



来源:https://stackoverflow.com/questions/16296947/how-to-pass-language-in-speech-recognition-on-android-apps

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