Android SpeechRecognizer在第二次收听时失败

时间:2015-07-07 16:26:10

标签: android speech-recognition text-to-speech speech

我遇到一个问题,其中SpeechRecognizer会正确收听,当我下次听到识别器时,它会转到SpeechRecognizer.ERROR_NO_MATCH,然后立即转到SpeechRecognizer.ERROR_NO_MATCH。我第三次听,会再次奏效。有任何想法吗?代码如下:此外,当错误代码为SpeechRecognizer.ERROR_SPEECH_TIMEOUT时,可以正常工作,第二次正确收听。

@Override
    public void onError(int error) {
        switch (error) {
            case SpeechRecognizer.ERROR_AUDIO:
                showLog("ERROR_AUDIO");
                endTimer();
                break;
            case SpeechRecognizer.ERROR_CLIENT:
                showLog("ERROR_CLIENT");
                endTimer();
                break;
            case SpeechRecognizer.ERROR_RECOGNIZER_BUSY:
                showLog("ERROR_RECOGNIZER_BUSY");
                endTimer();
                break;
            case SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS:
                showLog("ERROR_INSUFFICIENT_PERMISSIONS");
                endTimer();
                break;
            case SpeechRecognizer.ERROR_NETWORK_TIMEOUT:
                showLog("ERROR_NETWORK_TIMEOUT");
                endTimer();
                break;
            case SpeechRecognizer.ERROR_NETWORK:
                sr.destroy();
                showLog("ERROR_NETWORK");
                endTimer();
                break;
            case SpeechRecognizer.ERROR_SERVER:
                showLog("ERROR_SERVER");
                endTimer();
                break;
            case SpeechRecognizer.ERROR_NO_MATCH:
                showLog("ERROR_NO_MATCH");
                break;
            case SpeechRecognizer.ERROR_SPEECH_TIMEOUT:
                showLog("ERROR_SPEECH_TIMEOUT");
                break;
            default:
                assert false;
                return;
        }
    }

2 个答案:

答案 0 :(得分:0)

这是“Google App”中的一个错误,卸载Google应用的更新,它将清除问题或执行此答案 SpeechRecognizer throws onError on the first listening

答案 1 :(得分:-1)

尝试先取消导致错误的识别器,然后再次开始侦听。

public void onError(int error) {
    // put this where the bug occurs
    recognizer.cancel();
    recognizer.startListening(yourIntent);
}

我发现它有助于解决由错误引起的大量错误。