我对 Android SpeechRecognizer 有疑问。它在具有英语 (en-GB) 和德语 (de-DE) 的 Android 版本 2.3.5 上完美运行,但在版本 4.0.3 上,尽管指定的语言是德语,但它始终可以识别英语语音。
这是我传递给 SpeechRecognizer 的意图。
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
mContext.getPackageName());
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
mRecognizer.startListening(intent);
我确信这个变量总是好的(当我想要德语等时 de-DE)。
我还尝试添加:
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, language);
但它也不起作用。
我也确信 SpeechRecognizer 支持德语。我正在使用此 BroadcastReceiver 来获取可用语言的列表。
public class AndroidAvailableLanguagesChecker extends BroadcastReceiver {
private List<String> supportedLanguages;
public AndroidAvailableLanguagesChecker() {
supportedLanguages = new ArrayList<String>();
}
@Override
public void onReceive(Context context, Intent intent) {
Bundle results = getResultExtras(true);
if (results.containsKey(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES)) {
supportedLanguages = results
.getStringArrayList(RecognizerIntent.EXTRA_SUPPORTED_LANGUAGES);
}
}
public List<String> getSupportedLanguages() {
return supportedLanguages;
}
}
// using broadcast receiver
Intent detailsIntent = new Intent(
RecognizerIntent.ACTION_GET_LANGUAGE_DETAILS);
mChecker = new AndroidAvailableLanguagesChecker();
context.sendOrderedBroadcast(detailsIntent, null, mChecker, null,
Activity.RESULT_OK, null, null);
有谁知道为什么这不起作用?
提前致谢!