rxlabz / speech_recognition

A Flutter plugin to use speech recognition on iOS & Android (Swift/Java)
https://pub.dartlang.org/packages/speech_recognition
Other
336 stars 197 forks source link

onRecognitionComplete triggered twice #73

Open toshiossada opened 4 years ago

toshiossada commented 4 years ago

When I speak some sentence with speech_recognition the "onRecognitionComplete" are triggered twice, for example, I said "Hello how are you", it triggered "Hello how are" and "Hello how are you"... it's anyway to fix this and trigger just once??

Following logs bellow

I/flutter (15202): true I/flutter (15202): _platformCallHandler call speech.onSpeechAvailability true I/flutter (15202): _platformCallHandler call speech.onRecognitionStarted null I/flutter (15202): _platformCallHandler call speech.onSpeech I/flutter (15202): _platformCallHandler call speech.onSpeech Hello I/flutter (15202): _platformCallHandler call speech.onSpeech Hello I/flutter (15202): _platformCallHandler call speech.onSpeech Hello I/flutter (15202): _platformCallHandler call speech.onSpeech Hello how I/flutter (15202): _platformCallHandler call speech.onSpeech Hello how are I/flutter (15202): _platformCallHandler call speech.onRecognitionComplete Hello how are I/flutter (15202): _platformCallHandler call speech.onSpeech Hello how are you I/flutter (15202): _platformCallHandler call speech.onRecognitionComplete Hello how are you

I'm using this way

void initSpeechRecognizer() {
    speechRecognition = SpeechRecognition();

    speechRecognition.setAvailabilityHandler(
      (bool result) => isAvailable = result,
    );

    speechRecognition.setRecognitionResultHandler((String speech) {
      if (speech.length > 0) {
        resultText = speech;
      }
    });

    speechRecognition.setRecognitionCompleteHandler(() {
      isListening = false;
      if (resultText.length > 0) _chatController.senMsg(resultText);
      resultText = '';
    });

    speechRecognition.activate().then(
          (result) => isAvailable = result,
        );
  }

.

            onTap: () {
              if (!microfoneController.isListening) {
                microfoneController.isListening = true;
                microfoneController.speechRecognition
                    .listen(locale: "pt_BR")
                    .then((result) => print('$result'));
              } else {
                cancelRecording();
              }
            },
naiadelali commented 4 years ago

I'd also like to get a same solution to this issues =)

Edwin-Luijten commented 4 years ago

Encountering the same issue.

D/SpeechRecognitionPlugin(19739): onRmsChanged : -2.0  
D/SpeechRecognitionPlugin(19739): onRmsChanged : -2.0  
D/SpeechRecognitionPlugin(19739): onRmsChanged : -2.0  
D/SpeechRecognitionPlugin(19739): onEndOfSpeech  
I/flutter (19739): _platformCallHandler call speech.onRecognitionComplete bloody bloody bloody ... 
<snip>  
D/SpeechRecognitionPlugin(19739): onRmsChanged : -2.0  
D/SpeechRecognitionPlugin(19739): onRmsChanged : -2.0  
D/SpeechRecognitionPlugin(19739): onRmsChanged : -2.0  
D/SpeechRecognitionPlugin(19739): onResults...  
D/SpeechRecognitionPlugin(19739): onResults -> bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody bloody  
I/flutter (19739): _platformCallHandler call speech.onRecognitionComplete bloody bloody bloody ...<snip> 
tan-yaka commented 4 years ago

I had to comment out speechChannel.invokeMethod("speech.onRecognitionComplete", transcription); at line 121 of android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java to stop it being called twice.

Also commented out Log.d(LOG_TAG, "onRmsChanged : " + rmsdB); to cut down on log output.

This project doesn't appear to be being maintained anymore.

toshiossada commented 4 years ago

How do I do this? image

tan-yaka commented 4 years ago

Fork the repo and make the changes in your own copy.

You can reference your version in pubspec.yaml with:

  speech_recognition:
    git:
      url: git://github.com/{your_github_username}/speech_recognition.git
      ref: master
toshiossada commented 4 years ago

thanks I'll do this