mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-06 09:16:26 +08:00
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:
@@ -5025,10 +5025,24 @@ async function say(text: string) {
|
|||||||
const synth = window.speechSynthesis
|
const synth = window.speechSynthesis
|
||||||
const utterance = new SpeechSynthesisUtterance(speakText)
|
const utterance = new SpeechSynthesisUtterance(speakText)
|
||||||
utterance.rate = normalizedRate
|
utterance.rate = normalizedRate
|
||||||
|
const voices = synth.getVoices()
|
||||||
if (cfg.value.voice) {
|
if (cfg.value.voice) {
|
||||||
const voiceName = cfg.value.voice.toLowerCase()
|
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
|
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 = () => {
|
utterance.onend = () => {
|
||||||
isSpeaking.value = false
|
isSpeaking.value = false
|
||||||
|
|||||||
Reference in New Issue
Block a user