Open vinayakvanarse opened 6 years ago
Hi to solve the problem I had to remove the methodchannel call in onEndOfSpeech() in android/SpeechRecognitionPlugin.java. As per documentation, on Android, RecognitionListener calls onEndOfSpeech every time a user stop talking and onResults when the recognition is completed, so in some case onRecognitionComplete can be called twice. I'm not sure this is the best solution, but hope this helps...
Thanks for this tip @andrezanna. I don't know if there will be other consequences from this change, but it's good enough for the basic test I'm trying to do :)
Hi to solve the problem I had to remove the methodchannel call in onEndOfSpeech() in android/SpeechRecognitionPlugin.java. As per documentation, on Android, RecognitionListener calls onEndOfSpeech every time a user stop talking and onResults when the recognition is completed, so in some case onRecognitionComplete can be called twice. I'm not sure this is the best solution, but hope this helps...
Hi @andrezanna,
where is that SpeechRecognitionPlugin.java file located? i dont have such at my android directory... thanks in advance
It's a lot time i don't use it, but the file i had to modify is this one: https://github.com/rxlabz/speech_recognition/blob/master/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java
It's a lot time i don't use it, but the file i had to modify is this one: https://github.com/rxlabz/speech_recognition/blob/master/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java
@andrezanna, thanks, working perfect!
I am actually getting the same error and i am a newBie what can I do
I am actually getting the same error and i am a newBie what can I do
Hi @ramsham2411
All you need is locate and comment this line: https://github.com/rxlabz/speech_recognition/blob/d527d13d16c2a9cd001bf14a4372ec74c69f72b2/android/src/main/java/bz/rxla/flutter/speechrecognition/SpeechRecognitionPlugin.java#L121 it can be located in SpeechRecognitionPlugin.java file. Locate it by left click with Ctrl on any of plugin classes or methods, then in address bar you can see where is cache of package located. Or just follow the video I made for you:
Hi,
I am facing a strange issue on Android (PIXEL 2) real device and android simulator too. I get void onRecognitionComplete() => setState(() async { called twice.
Here's the dump of the log from Android Studio...
09-06 17:09:31.417 18931-18975/? I/flutter: Your currentLocale is en_AU 09-06 17:09:36.721 18931-18975/? I/flutter: _SpeechBotState.start => result true 09-06 17:09:39.595 18931-18975/? I/flutter: stop() isListening = true 09-06 17:09:39.629 18931-18975/? I/flutter: onRecongintionComplete the transcript is hello inside _api.dioPost() inside getIdToken 09-06 17:09:39.637 18931-18975/? I/flutter: inside getIdTokenFromUser 09-06 17:09:39.639 18931-18975/? I/flutter: params passed to post are = {uid: EJDgM5Kd0EO75R7XW9EPRyD6dZR2, text: hello} 09-06 17:09:39.821 18931-18975/? I/flutter: onRecongintionComplete the transcript is hello 09-06 17:09:39.823 18931-18975/? I/flutter: inside getIdTokenFromUser 09-06 17:09:39.825 18931-18975/? I/flutter: params passed to post are = {uid: EJDgM5Kd0EO75R7XW9EPRyD6dZR2, text: hello} 09-06 17:24:59.118 18931-18975/? I/flutter: {status: success, successFlag: true, data: Greetings!} 09-06 17:24:59.121 18931-18975/? I/flutter: responsePost obtained .... 09-06 17:24:59.122 18931-18975/? I/flutter: {status: success, successFlag: true, data: Hi!} 09-06 17:25:06.597 18931-18975/? I/flutter: _SpeechBotState.start => result true 09-06 17:25:09.309 18931-18975/? I/flutter: onRecongintionComplete the transcript is I have a problem 09-06 17:25:09.318 18931-18975/? I/flutter: inside getIdTokenFromUser 09-06 17:25:09.323 18931-18975/? I/flutter: params passed to post are = 09-06 17:25:09.324 18931-18975/? I/flutter: {uid: EJDgM5Kd0EO75R7XW9EPRyD6dZR2, text: I have a problem} 09-06 17:25:09.528 18931-18975/? I/flutter: onRecongintionComplete the transcript is I have a problem 09-06 17:25:09.545 18931-18975/? I/flutter: inside getIdTokenFromUser 09-06 17:25:09.551 18931-18975/? I/flutter: params passed to post are = {uid: EJDgM5Kd0EO75R7XW9EPRyD6dZR2, text: I have a problem}
Why is it happening twice on Android and on iOS it works fine? Your help will be very much appreciated.
To assess what is going wrong sharing the code below....
@override initState() { super.initState(); initPlatformState(); checkPermission(); }
@override dispose() { stop(); _cancelRecognitionHandler(); super.dispose(); }
new Expanded( child: new Container( alignment: Alignment.bottomCenter, margin: const EdgeInsets.only(bottom: 10.0), child: new FloatingActionButton( backgroundColor: floatBttnColor, child: new Icon(Icons.mic), //navigate: () => navigate(''), onPressed: _speechRecognitionAvailable && !_isListening ? () { if (this.mounted) { setState(() { floatBttnColor = Colors.purple; }); } start(); } : () { stop(); if (this.mounted) { setState(() { floatBttnColor = Colors.green; }); } }, ), ), ),
and out side the build Widget function in the class I have
void start() => _speech .listen(locale: _currentLocale) .then((result) => print('_SpeechBotState.start => result $result'));
void cancel() => _speech.cancel().then((result) => setState(() { _isListening = result; print('_speech.cancel result is $result'); }));
Future stop() => _speech.stop().then((result) => setState(() async {
_isListening = result;
print('stop() isListening = $_isListening');
}));
void onSpeechAvailability(bool result) => setState(() => _speechRecognitionAvailable = result);
void onCurrentLocale(String locale) => setState(() { _currentLocale = locale; print('Your currentLocale is $_currentLocale'); });
void onRecognitionStarted() => setState(() => _isListening = true);
void onRecognitionResult(String text) => setState(() { transcription = text; //print('your intermediate transcription is $transcription'); });
void onRecognitionComplete() => setState(() async { _isListening = false; //await stop(); print('onRecongintionComplete the transcript is $transcription'); //Just for testing... once chatbot integrated with backend TTS will be inserting card in that function ChatCardData card = new ChatCardData( id: id++, hour: '${_date.hour}', meridian: '${_date.minute}', title: transcription, isCustomer: true, source: '${DateName.month[(_date.month) - 1]} ${_date.day}, ${_date.year}', text: true, labelColor: Colors.green); if (this.mounted) { setState(() { _load = true; _list.insert(0, card); }); } //Tts.speak(transcription); dynamic body = {'uid': UserAuth.userModel.uid, 'text': transcription}; //send it to chat engine try { Response responsePost = await _api.dioPost( APIPATH.XXX, APIPATH.YYY, body); print('responsePost obtained ....'); print(responsePost.data); //print(responsePost.headers); //print(responsePost.request); print(responsePost.statusCode); ChatCardData card = new ChatCardData( id: id++, hour: '${_date.hour}', meridian: '${_date.minute}', title: responsePost.data['data'], isCustomer: false, source: '${DateName.month[(_date.month) - 1]} ${_date.day}, ${_date.year}', text: true, labelColor: Colors.green); Tts.speak(responsePost.data['data']); if (this.mounted) { setState(() { _load = false; _list.insert(0, card); }); } } on DioError catch (e) { if (this.mounted) { setState(() { _load = false; }); } // The request was made and the server responded with a status code // that falls out of the range of 2xx and is also not 304. print('post returned error!'); print('Error stack = $e'); if (e.response != null) { print('e.response not null'); print(e.response.data); print('statusCode of error = '); print(e.response.statusCode); //print(e.response.headers); //int statusCode = e.response.statusCode; final ThemeData theme = Theme.of(context); final TextStyle dialogTextStyle = theme.textTheme.subhead .copyWith(color: theme.textTheme.caption.color); await showDialog( barrierDismissible: false, context: this.context, builder: (BuildContext context) => new AlertDialog( title: new Text('Error'), content: new Text(e.response.data['data'], style: dialogTextStyle), actions:[
new FlatButton(
child: const Text('Dismiss'),
onPressed: () {
Navigator.pop(context, true);
})
]));
} else {
// Something happened in setting up or sending the request that triggered an Error
print('e.response is null');
print(e.response);
print(e.message);
}