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

时间:2014-08-23 23:06:21

标签: 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);

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

也许这就是Google现在更新的错误

1 个答案:

答案 0 :(得分:3)

虽然我迟到了, 以下黑客对我有用:

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