speech_recognition
speech_recognition copied to clipboard
onError handler (android)
Hi, we're seeing
I/flutter ( 7919): _platformCallHandler call speech.onSpeechAvailability false I/flutter ( 7919): _platformCallHandler call speech.onError 7 I/flutter ( 7919): Unknowm method speech.onError
on Android when speech recognition is running and the OS needs to do something (say, a text comes in). I see the onError call in the Java file but I don't see it at the Dart level. Maybe I'm missing something?
Thanks for the great work on this!
Same error for me on the last version, I have log on Android log cat
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at bz.rxla.flutter.speechrecognition.SpeechRecognitionPlugin.getLocale(SpeechRecognitionPlugin.java:86)
at bz.rxla.flutter.speechrecognition.SpeechRecognitionPlugin.onMethodCall(SpeechRecognitionPlugin.java:67)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:191)
at io.flutter.view.FlutterView.handlePlatformMessage(FlutterView.java:643)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:328)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:6361)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
This plugin is very very interesting and a great use case. Congratulations!!!
But same error to me too on Android. Anybody had sucessful?
I/FlutterActivityDelegate(19695): onResume setting current activity to this
I/flutter (19695): _MyAppState.activateSpeechRecognizer...
Syncing files to device SM T330...
D/SpeechRecognitionPlugin(19695): Current Locale : pt_BR
I/flutter (19695): _platformCallHandler call speech.onCurrentLocale pt_BR
D/ViewRootImpl(19695): ViewPostImeInputStage ACTION_DOWN
I/flutter (19695): _MyAppState.start => result true
D/SpeechRecognitionPlugin(19695): onError : 9
I/flutter (19695): _platformCallHandler call speech.onSpeechAvailability false
I/flutter (19695): _platformCallHandler call speech.onError 9
I/flutter (19695): Unknowm method speech.onError
Application finished.
See here https://stackoverflow.com/questions/35248075/android-speech-recognition-insufficient-permission-error-code-9/35784764
Work for me (Error 9)
About error 7 (https://developer.android.com/reference/android/speech/SpeechRecognizer):
public static final int ERROR_NO_MATCH No recognition result matched.
Constant Value: 7
(0x00000007)
So whatever you're saying is not properly recognized. Error 6 means timeout, i've came across that one too.
Trying to figure out error handling right now, i'll update this post if i succeed.
Edit: Seems there is already a Pull request, fixing this problem (https://github.com/rxlabz/speech_recognition/pull/5)
I have faced the same issue. Fixed it by enableing microphone permision from app settings. Also you can do that programatically with this plugin https://pub.dartlang.org/packages/simple_permissions.
Firstly the speech recognition doesn't work on Android Emulator. You can install with USB and then have to provide microphone permissions from app settings or alternatively, as suggested by @gurgenDP you can do the following
import 'package:simple_permissions/simple_permissions.dart';
initState() {
super.initState();
_checkAudioPermission();
activateSpeechRecognizer();
}
void _checkAudioPermission() async {
bool hasPermission =
await SimplePermissions.checkPermission(Permission.RecordAudio);
if (!hasPermission) {
await SimplePermissions.requestPermission(Permission.RecordAudio);
}
}