-
Notifications
You must be signed in to change notification settings - Fork 34
fix: resumeInfinity/onresume interaction #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
Test Results: ✅ PASSEDRun at: 2025-11-26T16:01:42.800Z Summary: |
michielvandergeest
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! A few minor syntax related comments
Test Results: ✅ PASSEDRun at: 2025-12-02T10:28:25.494Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-03T12:17:48.082Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-03T12:20:32.097Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-03T14:38:24.613Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-03T15:06:07.990Z Summary: |
…meInfinity function
Test Results: ✅ PASSEDRun at: 2025-12-04T09:07:59.870Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-04T09:46:56.875Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-05T10:56:39.578Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-08T13:39:40.543Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-08T16:10:34.947Z Summary: |
Test Results: ✅ PASSEDRun at: 2025-12-23T20:37:14.088Z Summary: |
| }) | ||
| debounce = null | ||
| }, 200) | ||
| }, 300) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was there a specific reason for increasing the timeout from 200 to 300?
| // Cancel any active speech synthesis | ||
| speechSynthesis.cancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does clearing the queue also mean that we want to cancel the current message being spoken out? I'm not sure that it should always be so ..
| if (!state) { | ||
| return | ||
| } | ||
| if (state?.timer !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer not to use optional chaining (as it doesn't transpile to very optimal es5 code)
| const { utterance } = state | ||
|
|
||
| // utterance check: utterance instance is invalid | ||
| if (!(utterance instanceof SpeechSynthesisUtterance)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this instanceof check? would there ever be a case where it's not an instance of SpeechSynthesisUtterance? instanceof is a relatively expensive operation
| } | ||
|
|
||
| // Clear existing timer for this specific utterance | ||
| if (state?.timer !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the optional chaining syntax
| const initialize = () => { | ||
| // syn api check: syn might not have getVoices method | ||
| if (!syn || typeof syn.getVoices !== 'function') { | ||
| initialized = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct? if syn is falsy, do we want to set initialized to true?
| const isReady = !syn.speaking && !syn.pending | ||
|
|
||
| if (isReady) { | ||
| Log.warn(`SpeechSynthesis - ready after ${elapsed}ms`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably be Log.debug statements and not Log.warn?
|
|
||
| const startTime = Date.now() | ||
|
|
||
| const intervalId = window.setInterval(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use window.setInterval instead of setInterval?
|
|
||
| if (isReady) { | ||
| Log.warn(`SpeechSynthesis - ready after ${elapsed}ms`) | ||
| window.clearInterval(intervalId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why use window.clearInterval instead of clearInterval?
|
|
||
| utterance.onerror = (e) => { | ||
| clear() | ||
| utterances.delete(id) // Cleanup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this not necessary anymore?
Change resumeInfinity to reset the existing timeout instead of calling clear() when a timer is present
Introduce resumeFromKeepAlive guard so keep-alive resume() calls don’t recursively trigger resumeInfinity
Key changes for consumers:
1) Added enableUtteranceKeepAlive parameter
Previously, the startKeepAlive() logic (resume/pause) was enabled only for non-Android user agents via:
However, on Comcast XI devices, triggering SpeechSynthesisUtterance resume/pause events can cause the announce to get stuck (the Promise never resolves). Also, for Comcast XI we don’t need to run the startKeepAlive() (resume/pause) logic.
With the new enableUtteranceKeepAlive option, consumers can explicitly enable/disable the keep-alive behavior from the app side:
Note: The default value is based on defaultUtteranceKeepAlive, so consumers can override it if needed. This is not a breaking change.
const defaultUtteranceKeepAlive = !isAndroid
2) Added cancelPrevious parameter
While working with Vishnu, I noticed they were cancelling the previous utterance during navigation by calling three APIs:
To simplify this requirement, I added cancelPrevious, which cancels any in-progress/queued utterance before speaking the new one:
This reduces multiple calls into a single, safer API call.
3) Improved clearing of utterances
I improved how we clear utterances by removing them based on the utterance ID, ensuring references are cleaned up more reliably and avoiding stale entries in the map.