SpeechRecognizer throws onError on the first listening

后端 未结 5 942
[愿得一人]
[愿得一人] 2020-12-11 07:09

In the Android 5 I faced with strange problem. The first call to the startListening of SpeechRecognizer results to the onError with error code 7 (ERROR_

5条回答
  •  天命终不由人
    2020-12-11 07:12

    I had the same problem on several devices. It seems onError(7) is always called before onReadyForSpeech(), so if to avoid using ugly times, you can do something like:

    public void start(){
        performingSpeechSetup = true;
        speechRecognizer.startListening(intent);
    }
    

    and in the RecognitionListener:

    public void onReadyForSpeech(Bundle bundle) {
        performingSpeechSetup = false;
    }
    
    @Override
    public void onError(int error) {
        if (performingSpeechSetup && error == SpeechRecognizer.ERROR_NO_MATCH) return;
        // else handle error
    }
    

提交回复
热议问题