Race condition between stopListening() and command handling on Chrome Mobile
korneliuszw opened this issue · 1 comments
korneliuszw commented
Hello,
I am using this library to create voice navigation for my app (v3.10.0 from npm). So far it is great.
However, I encountered a race condition when using stopListening() with continuous mode on Chrome Android.
I have a command called "stop" which stops voice recognition using SpeechRecognition.stopListening() (abortListening doesn't help). During this stopListening() call, an onend is called from SpeechRecognition API (because of chrome limitations) and resets listening. In result, despite calling stopListening(), the recognition is still working.
Reproduction (say stop right after start):
https://codesandbox.io/s/upbeat-lucy-sxjlx6?file=/src/App.js
korneliuszw commented
Workaround for this issue
const recognition = SpeechRecognition.getRecognition()
if (recognition) recognition.continuous = false
SpeechRecognition.stopListening()