I'm using android SpeechRecognition on an app made with react native. The library used is react-native-voice.
The app keep listening all the time for incoming sentences and sends them through 4 websockets to 4 servers.
I make keep listening calling startSpeech()
every time onEndOfSpeech()
or onError()
are triggered.
The problem is that, only on some devices (for example a cheap android one), when i run the app, after a random amount of time (from 5 minutes to 2 hours of normal working) microphone stops working: the java method onRmsChanged()
keeps returning -2.12( the same value returned when the app stops listening or finishes to recognize something) after a successful restart of speechRecognition with startSpeech()
java method. It seems like the microphone stops listening due a kind of crash or resource unavailable. When it happens i call destroySpeech()
and then startSpeech()
but it still stops working after one or few more recognize attempt. If i close and reopen the app from android UI, it has the same behaviour as above (speechRecognition after from 5 to 20 minutes of normal working, crash, and then it keeps crashing)
I've made a sort of fix that restart the speechRecognition when the onRmsChanged()
returns 20 consecutives times the wrong value above, in order to make it keep it listening as mush as possible, but is not a solution, cause there is no guarantee that onRmsChanged()
will be called during running the app.
I'm using
Android 7.0
Physical device
Android building tools 28.0.3
gradle 3.3.1
react-native 0.59.8
react-native-voice 0.3.0
All the apps in the phone are not allowed to use notifications, draw over other apps and access to microphone, except Google App, Google Play Services and my app.
I would ask: it is possible that another service on background takes the control of the microphone resource in Android system in this way? Or it could be a kind of SpeechRecognition crash?
This is the log of react-native, where 'true' is the value returned by the method isAvailable() (if is available speechRecognition in the system) and 'volume' n is the value return by onRmsChanged():
9-27 11:52:30.425 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:30.431 16130 16424 I ReactNativeJS: true
9-27 11:52:30.495 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:30.499 16130 16424 I ReactNativeJS: true
9-27 11:52:30.545 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:30.547 16130 16424 I ReactNativeJS: true
9-27 11:52:30.557 16130 16424 I ReactNativeJS: speech start
9-27 11:52:35.636 16130 16424 I ReactNativeJS: 'speech error', { error: { message: '6/No speech input' } }
9-27 11:52:35.647 16130 16424 I ReactNativeJS: start listening
9-27 11:52:35.729 16130 16424 I ReactNativeJS: speech start
9-27 11:52:35.799 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:35.806 16130 16424 I ReactNativeJS: true
9-27 11:52:35.918 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:35.921 16130 16424 I ReactNativeJS: true
9-27 11:52:35.967 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:35.969 16130 16424 I ReactNativeJS: true
9-27 11:52:36.019 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.024 16130 16424 I ReactNativeJS: true
9-27 11:52:36.069 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.074 16130 16424 I ReactNativeJS: true
9-27 11:52:36.121 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.128 16130 16424 I ReactNativeJS: true
9-27 11:52:36.180 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.188 16130 16424 I ReactNativeJS: true
9-27 11:52:36.222 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.224 16130 16424 I ReactNativeJS: true
9-27 11:52:36.269 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.272 16130 16424 I ReactNativeJS: true
9-27 11:52:36.323 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.331 16130 16424 I ReactNativeJS: true
9-27 11:52:36.373 16130 16424 I ReactNativeJS: 'volume', -2.119999885559082
9-27 11:52:36.381 16130 16424 I ReactNativeJS: true
Thank you