fix(tts): instant pause via cancel+re-speak and resume-from-position via onboundary#254
Open
YizukiAme wants to merge 2 commits intoTHU-MAIC:mainfrom
Open
fix(tts): instant pause via cancel+re-speak and resume-from-position via onboundary#254YizukiAme wants to merge 2 commits intoTHU-MAIC:mainfrom
YizukiAme wants to merge 2 commits intoTHU-MAIC:mainfrom
Conversation
- Add currentProviderRef to track active TTS provider - Destructure pause/resume from useBrowserTTS - Delegate pause() to browserPause or audioRef.pause() based on provider - Delegate resume() to browserResume, audioRef.play(), or processQueue - Guard processQueue and onEnd against queue advancement while paused - Reset currentProviderRef in cleanup() Closes THU-MAIC#245
…via onboundary useBrowserTTS (discussion mode, THU-MAIC#249): - Replace speechSynthesis.pause() with cancel() for instant silence - Track word positions via utterance.onboundary events (charIndex + charLength) - Resume re-speaks text.slice(lastBoundaryIndex) with same voice - cancellingForPauseRef stays true during pause, reset in speakInternal() PlaybackEngine (lecture mode, THU-MAIC#250): - Add browserTTSBoundaryIndex field tracking onboundary charIndex - On pause, slice current chunk from boundary position (end of last word) - Save resolved language to prevent voice switching at language boundaries - Resume plays remaining text from pause point, not chunk start Closes THU-MAIC#249, closes THU-MAIC#250
255de0c to
6e78b47
Compare
Contributor
|
Thanks for the PR! I tested this locally and the cancel+re-speak approach does eliminate the ~300ms pause delay, but I ran into a couple of issues:
The root cause is that Web Speech API doesn't expose precise audio position, so cancel+re-speak is inherently approximate. The original These are limitations of the Web Speech API itself, so no easy fix — let's leave this for now and revisit later. Appreciate the contribution! |
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.
Summary
Fixes #249 — Browser TTS pause has ~300ms delay due to
speechSynthesis.pause()buffering.Fixes #250 — Lecture mode TTS resume restarts from sentence beginning instead of continuing from pause point.
Note
This PR depends on PR #253 (
fix/discussion-tts-pause) which adds browser TTS pause/resume delegation inuseDiscussionTTS. Merge #253 first.Approach:
cancel()+onboundaryWord Position TrackingBoth issues stem from Web Speech API limitations. The unified fix:
speechSynthesis.cancel()instead of.pause()— cancel is immediate, no buffering delay.utterance.onboundaryevents (charIndex + charLength). On resume,text.slice(lastBoundaryIndex)re-speaks from where the user paused.Changes
lib/hooks/use-browser-tts.ts(discussion mode, #249)speakInternal()— shared byspeak()andresume(), attachesonboundaryhandlerpause()— setscancellingForPauseRef = true, callscancel(), keeps flag true during entire pause period (Chrome firesonEndasynchronously)resume()— slices text from last boundary, re-speaks with same voice viaspeakInternal()cancellingForPauseRefreset moved tospeakInternal()to prevent race condition with asynconEndlib/playback/engine.ts(lecture mode, #250)browserTTSBoundaryIndex— trackscharIndex + charLengthwithin current chunk viaonboundarypause()— slices current chunk from boundary position (not chunk[0])browserTTSCurrentLang— saves resolved language to prevent voice switching at language boundaries on resumeTesting