4

我有一个曾经可以工作的代码,但由于某种原因它突然停止工作,我正在尝试在希伯来语中使用语音识别,但似乎从几天前开始它才开始用英语进行语音识别。

这是我的代码

 sr = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
            test_voice_recognitiona listener = new test_voice_recognitiona();
            sr.setRecognitionListener(listener);
            Intent fl = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            fl.putExtra("android.speech.extra.LANGUAGE", "he");
            fl.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "he");
            fl.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                    this.getPackageName());
            sr.startListening(fl);

test_voice_recognitiona 是我的 RecognitionListener 类名的名称。

代码运行良好,但由于某种原因,它一直在听英语。

我究竟做错了什么?

顺便说一句,我用谷歌对话框尝试了更简单的代码,它正在工作。

  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "he");
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Talk to Me " + user_name);
        startActivityForResult(intent,REQUEST_CODE);

也许是谷歌现在更新故障

4

1 回答 1

5

虽然我迟到了,但以下技巧对我有用:

  Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "he");
    intent.putExtra("android.speech.extra.EXTRA_ADDITIONAL_LANGUAGES", new String[]{"he"});

    intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
            getString(R.string.speech_prompt));
于 2015-03-04T12:00:13.380 回答