SpeechRecognizer始终以英语识别(在4.0.3版本上)

时间:2012-09-17 12:39:45

标签: android

Android SpeechRecognizer存在问题。它在Android版本2.3.5上完全适用于英语(en-GB)和德语(de-DE),但在版本4.0.3中它始终用英语识别语音,尽管指定的语言是德语。

这是我传递给SpeechRecognizer的Intent。

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);

有人知道为什么这不起作用吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

这只是一个假设,而不是现在的测试,但也许语言必须是“de_DE”而不是“de-DE”,请试试....