fix: use browser speechSynthesis for playback when browser-native-tts is selected#28
fix: use browser speechSynthesis for playback when browser-native-tts is selected#28YizukiAme wants to merge 1 commit intoTHU-MAIC:mainfrom
Conversation
Code ReviewClean, focused change with correct edge case handling. Overall LGTM. Two items to consider as follow-up improvements: 1. Chrome long utterance cutoffChrome has a known bug where 2.
|
|
Thanks for the review!!!! I'll address the Chrome 15s cutoff and Firefox pause/resume issues in a follow-up PR by implementing an utterance queue with text chunking. This will elegantly handle both issues while keeping this PR focused on the basic fallback. |
… is selected Previously, selecting browser-native-tts as the TTS provider would produce sound in the settings test but remain silent during classroom playback. This happened because: 1. The scene generator correctly skipped pre-generation for browser TTS (it runs client-side, not via API) 2. The playback engine fell back to a silent reading timer when no pre-generated audio was found, instead of calling speechSynthesis This commit adds Web Speech API integration directly in the PlaybackEngine: - New playBrowserTTS() method speaks text via speechSynthesis - Properly wires onend/onerror to advance to the next action - pause()/resume() now handle speechSynthesis.pause()/resume() - stop() and handleUserInterrupt() cancel browser TTS Fixes THU-MAIC#25, fixes THU-MAIC#12, fixes THU-MAIC#5
49b470f to
496b5d9
Compare
Summary
Fix browser-native TTS producing no sound during classroom playback, while the settings test plays sound correctly.
Fixes #25, fixes #12, fixes #5
Root Cause
When
browser-native-ttsis selected as the TTS provider:use-scene-generator.ts:214,450) correctly skips pre-generating audio — browser TTS runs client-side via Web Speech API, not via server APIengine.ts:436-444) callsaudioPlayer.play()which finds no pre-generated audio in IndexedDB → returnsfalse→ falls back toscheduleReadingTimer()— a silent timer that estimates reading time but never callsspeechSynthesisFix
Add Web Speech API integration directly in
PlaybackEngine(lib/playback/engine.ts):playBrowserTTS()— speaks text viawindow.speechSynthesis, respecting user's voice, speed, volume, and mute settingscancelBrowserTTS()— cancels active browser TTSpause()— callsspeechSynthesis.pause()when browser TTS is activeresume()— callsspeechSynthesis.resume()when browser TTS is pausedstop()/handleUserInterrupt()— callsspeechSynthesis.cancel()to stop browser TTSThe fix is self-contained in one file. When
audioPlayer.play()returnsfalse(no pre-generated audio), the engine now checks ifbrowser-native-ttsis the selected provider and callsspeechSynthesis.speak()instead of falling back to the silent reading timer.Changes
lib/playback/engine.tsTesting