fix(classroom): force English (US) voice for browser TTS default

When no fixed instructor voice is chosen ("Standard · Ryan US"), the
Web Speech path set no voice and fell back to the OS default (German on
a German system). Now prefers an en-US (then en) voice, matching the
online instructor default.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
itsrubberduck
2026-07-19 19:42:35 +02:00
parent 3cd07e4331
commit 6dbd9c3ef4

View File

@@ -5025,10 +5025,24 @@ async function say(text: string) {
const synth = window.speechSynthesis
const utterance = new SpeechSynthesisUtterance(speakText)
utterance.rate = normalizedRate
const voices = synth.getVoices()
if (cfg.value.voice) {
const voiceName = cfg.value.voice.toLowerCase()
const voice = synth.getVoices().find(item => item.name.toLowerCase().includes(voiceName))
const voice = voices.find(item => item.name.toLowerCase().includes(voiceName))
if (voice) utterance.voice = voice
} else {
// No fixed voice picked ("Standard · Ryan US"). The default OS voice is
// locale-dependent (German on a German machine), so force an English —
// ideally US — voice to match the online instructor default.
const enVoice =
voices.find(item => /^en[-_]us/i.test(item.lang)) ||
voices.find(item => /^en/i.test(item.lang))
if (enVoice) {
utterance.voice = enVoice
utterance.lang = enVoice.lang
} else {
utterance.lang = 'en-US'
}
}
utterance.onend = () => {
isSpeaking.value = false