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

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

最佳答案

我刚遇到同样的问题。似乎该问题可能与“Ok,Google”功能的“始终在线”行为更改有关。 SpeechRecognizer throws onError on the first listening

关于java - Android Marshmallow 6.0.1 打破了我的连续语音识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36115987/

相关文章:

java - SwingWorker 得到一个结果

java - 如何在GAE java中为自定义用户数据库创建cookie?

android使用WIFI检测位置

android - 是否可以使用 OkHttp 设置占位符路径参数

安卓语音识别情绪检测器

android - 谷歌语音转文本 : Extra language set to "kn" but not working

java - Spring Boot 中的 DispatcherServlet 和 web.xml

java - Liferay kaleo 工作流程不工作

android - 为什么 LiveLiteralsKt 会导致运行时问题?

java - 如何对其他类中 SpeechRecognizer 的结束使用react?额外类中的识别器