我如何使用其他语言的语音识别android

Ros*_*pin 4 android speech-recognition voice-recognition recognizer-intent

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

这是我的代码

 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);
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

也许是谷歌现在更新错误

Tom*_*rBu 5

Although I'm late to the party, The following hack works for me:

  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));
Run Code Online (Sandbox Code Playgroud)