SpeechRecognizer throws onError on the first listening

后端 未结 5 943
[愿得一人]
[愿得一人] 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:18

    Done one workaround.

    This is a regular flow

    onReadyForSpeech -->onBeginningOfSpeech-->onEndOfSpeech -->onResults

    But weired flow

    onError(no match) -->onReadyForSpeech -->onBeginningOfSpeech-->onEndOfSpeech -->onResults

    So set a boolean on the end of speech to true. and check onError to make sure that it has thrown an error after an end of speech!

    speech.startListening(recognizerIntent);
    isEndOfSpeech = false;
    
     @Override
        public void onError(int error) {
            if (!isEndOfSpeech)
                return;
    }
    
    
     @Override
        public void onEndOfSpeech() { 
            isEndOfSpeech = true; 
        }
    

提交回复
热议问题