fix: support browser-native TTS in classroom playback#62
fix: support browser-native TTS in classroom playback#62harmony2ww wants to merge 1 commit intoTHU-MAIC:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a browser-native (Web Speech API) TTS fallback path for classroom playback when pre-generated audio isn’t available, and threads speech metadata (text/voice/speed) through the playback/action engines to support pause/resume/stop and active-state checks.
Changes:
- Extend
AudioPlayer.play()to accept a fallback payload and synthesize speech viawindow.speechSynthesiswhen IndexedDB audio is missing. - Pass
text,voice, andspeedintoAudioPlayer.play()from bothPlaybackEngineandActionEngine. - Add speech-synthesis aware implementations of pause/resume/stop/playing-state checks in
AudioPlayer.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/utils/audio-player.ts | Implements Web Speech API fallback and adds speech-synthesis aware pause/resume/active checks. |
| lib/playback/engine.ts | Passes speech metadata into audio playback to enable browser-native fallback. |
| lib/action/engine.ts | Passes speech metadata into audio playback for synchronous speech execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| if (this.audio && !this.audio.paused) { | ||
| this.audio.pause(); | ||
| } | ||
| if (this.utterance && typeof window !== 'undefined' && window.speechSynthesis.speaking) { |
| const voices = window.speechSynthesis.getVoices(); | ||
| const desiredVoice = fallback.voice || ttsVoice; | ||
| const matchedVoice = voices.find( | ||
| (voice) => | ||
| voice.voiceURI === desiredVoice || | ||
| voice.name === desiredVoice || | ||
| voice.lang === desiredVoice, | ||
| ); | ||
| if (matchedVoice) { | ||
| utterance.voice = matchedVoice; | ||
| utterance.lang = matchedVoice.lang || utterance.lang; | ||
| } |
72b1d3b to
645cca8
Compare
645cca8 to
075278a
Compare
|
This was already addressed by #28 (merged Mar 18), which added browser-native TTS playback with text chunking, async voice loading, and language auto-detection. We also shipped #153 on top of that to fix a garbled audio bug and add provider switching in the toolbar. Your approach in AudioPlayer was clean, we just got there through a different path. The PlaybackEngine ended up being a better place for this since it can manage chunk state and pause/resume. Thanks for the contribution! Your #63 is still open and we'll look at that separately. |
Summary
This PR adds browser-native TTS fallback support to the classroom playback flow so that lectures can still be spoken when no pre-generated audio file is available.
Related Issues
Related to browser-native TTS playback behavior in classroom mode.
Changes
lib/utils/audio-player.tstext,voice, andspeedfrom playback/action engines into the audio playerType of Change
Verification
Steps to reproduce / test
browser-native-ttsas the TTS providerWhat you personally verified
Evidence
pnpm check && pnpm lint && npx tsc --noEmit)Checklist