Android Marshmallow 6.0.1打破了我的连续语音识别

时间:2016-03-20 15:55:38

标签: java android speech-recognition android-6.0-marshmallow

我正在创建一个我正在使用连续语音识别的应用程序。直到有一天我将手机更新到Android 6.0.1时,它工作得很好,所以我假设这是破坏代码的原因。现在,语音识别器几乎立即抛出一个ERROR_NO_MATCH错误,并且在重新启动之前只监听输入不到一秒钟,它应该监听5秒钟。它导致很难对应用程序说出命令。这是我的代码:

private void displaySpeechRecognizer() {
    if(sr != null) {
        sr.destroy();
    }
    sr = SpeechRecognizer.createSpeechRecognizer(this);
    sr.setRecognitionListener(this);
    intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

    // Start the activity, the intent will be populated with the speech text
    sr.startListening(intent);
}

@Override
public void onReadyForSpeech(Bundle params) {
}

@Override
public void onBeginningOfSpeech() {
}

@Override
public void onRmsChanged(float rmsdB) {
}

@Override
public void onBufferReceived(byte[] buffer) {
}

@Override
public void onEndOfSpeech() {
}

@Override
public void onError(int error) {
    displaySpeechRecognizer();
}

1 个答案:

答案 0 :(得分:0)

我刚遇到同样的问题。似乎这个问题可能与"总是在"行为改变为" Ok,Google"特征。 SpeechRecognizer throws onError on the first listening