fix: stop() in continuous mode now releases microphone immediately - #260
Open
Akram-Wa wants to merge 2 commits into
Open
fix: stop() in continuous mode now releases microphone immediately#260Akram-Wa wants to merge 2 commits into
Akram-Wa wants to merge 2 commits into
Conversation
Fixes compulim#166 In continuous mode, calling stop() during silence would leave the microphone open indefinitely. stopContinuousRecognitionAsync was only called inside the recognized event handler, which never fires when no speech has been detected. A subsequent start() would then fail. The fix mirrors the existing abort() behavior: call stopContinuousRecognitionAsync immediately when stop is received, without waiting for a recognized event. Also removes the deferred stopContinuousRecognitionAsync call in the recognized handler for the continuous+stopping path, which would have caused a double-call after the fix. Adds a regression test: stop() during silence in continuous mode must fire stopContinuousRecognitionAsync immediately and cleanly fire soundend/audioend/end without a no-speech error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #166
In continuous mode, calling
stop()during silence would leave the microphone open indefinitely.stopContinuousRecognitionAsyncwas only called inside therecognizedevent handler, which never fires when no speech has been detected. A subsequentstart()would then fail silently until the page was refreshed.The fix mirrors the existing
abort()behavior: callstopContinuousRecognitionAsyncimmediately whenstopis received, without waiting for a recognized event.Also removes the deferred
stopContinuousRecognitionAsynccall in therecognizedhandler for the continuous+stopping path, which would have caused a double-call after the fix.Adds a regression test:
stop()during silence in continuous mode must firestopContinuousRecognitionAsyncimmediately and cleanly firesoundend/audioend/endwithout ano-speecherror.SDK Contract
The JS SDK reference confirms:
The SDK runs until
stopContinuousRecognitionAsyncis explicitly called — it does not self-terminate. Any code path that fails to call it leaves the microphone and session permanently open.Why
sessionStoppedandspeechEndDetectedwere never firingTwo existing comments in this codebase hint at a deeper symptom of the same bug:
These events were assumed to be a quirk of
startContinuousRecognitionAsync. In reality they were not firing becausestopContinuousRecognitionAsyncwas never being called promptly — the SDK had no signal that the session should end. With this fix, these events should now fire correctly whenstop()is called.Changelog
Fixed
Specific changes
createSpeechRecognitionPonyfillFromRecognizer.ts: removedabort &&guard sostopContinuousRecognitionAsyncis called immediately for bothabortandstopwhen the stop signal is first receivedcreateSpeechRecognitionPonyfillFromRecognizer.ts: removed deferred stopContinuousRecognitionAsync call in recognized handler for the continuous+stopping path to prevent double-call
createSpeechRecognitionPonyfill.test.js: added regression test —stop()during silence in continuous mode must release the mic immediately and close cleanly without ano-speecherror