问题描述
我一直工作在语音识别API在Android和发现,语音配发结果有所不同,当语言设置被更改,有没有办法来编程设置呢?或者是有意向午餐演讲语言设置屏幕?还是什么别的?注意:我试图用这个意图额外的:
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");
但它是无效的。
but it was ineffective
推荐答案
由于pargat说,这将做到这一点:
As pargat says, this will do it:
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
另外,你的应用程序可以通过发送 RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS
有序广播,像这样查询所支持的语言列表:
Also, your app can query for the list of supported languages by sending a RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS
ordered broadcast like so:
Intent detailsIntent = new Intent(RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
sendOrderedBroadcast(
detailsIntent, null, new LanguageDetailsChecker(), null, Activity.RESULT_OK, null, null);
在这里LanguageDetailsChecker是这样的:
where LanguageDetailsChecker is something like this:
public class LanguageDetailsChecker extends BroadcastReceiver
{
private List<String> supportedLanguages;
private String languagePreference;
@Override
public void onReceive(Context context, Intent intent)
{
Bundle results = getResultExtras(true);
if (results.containsKey(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE))
{
languagePreference =
results.getString(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE);
}
if (results.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES))
{
supportedLanguages =
results.getStringArrayList(
RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
}
}
}
有关完整的code看看这个github上的项目: https://github.com/gast-lib
For the complete code check out this github project:https://github.com/gast-lib
这篇关于如何设置在Android的语音识别的语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!