其他分享
首页 > 其他分享> > 如何将语音识别与其他语言一起使用android

如何将语音识别与其他语言一起使用android

作者:互联网

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

这是我的代码

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

也许是谷歌现在更新错误

解决方法:

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

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

标签:speech-recognition,voice-recognition,android,recognizer-intent
来源: https://codeday.me/bug/20191121/2051064.html