EddyVerbruggen / nativescript-speech-recognition

:speech_balloon: Speech to text, using the awesome engines readily available on the device.
Other
91 stars 23 forks source link

Plugin breaks when resuming app #7

Closed GrEg00z closed 7 years ago

GrEg00z commented 7 years ago

On android, when leaving and resuming the app, the SpeechRecognizer stops to work (method startListening of plugin) and throw error "7".

I have add a console.log to onError listener in speech-recognition.android.js to see this error.

Also if after resuming app, I make a mute record (without speaking), onError listener throw error "6", and after that, the plugin restart to work !

(From official doc) : Error 7 : ERROR_NO_MATCH Error 6 : ERROR_SPEECH_TIMEOUT

EddyVerbruggen commented 7 years ago

Interesting find.. so I guess adding an onPause listener to the plugin that stops listening would fix it.

Did you try to invoke stopListening from a pause event to prevent the problem?

GrEg00z commented 7 years ago

Yes I tried to call stopListening inside the 'suspend' event listener of my nativescript app :

application.on(application.suspendEvent, (args: application.ApplicationEventData) => {
      if(this.isStarted)
           this.speechRecognition.stopListening();
});

but it doesnt fix it, and I also get an Error 5 : ERROR_CLIENT (from onError listener).

Also I must have 'isStarted' flag to prevent application crash, because if startListening event has not been already called, the app crash with error : Cannot read property 'stopListening' of undefined

I have also tried to call stopListening directly in speech-recognition plugin code, inside 'onEndOfSpeech' event callback. No error are throw but nothing changes too

Last thing is if I do not invoke startListening before suspend app, then when I resume the app the plugin works. But the next suspend event will provoke the same error as explain in my first post

EddyVerbruggen commented 7 years ago

Thanks for those great pointers!