speech_recognition
speech_recognition copied to clipboard
onRecognitionComplete triggered twice
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();
}
},
I'd also like to get a same solution to this issues =)
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>
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.
How do I do this?
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
thanks I'll do this