diff --git a/src/stores/alert.ts b/src/stores/alert.ts index 55615527d..ad42a4c94 100644 --- a/src/stores/alert.ts +++ b/src/stores/alert.ts @@ -54,13 +54,31 @@ export const useAlertStore = defineStore('alert', () => { // We need to cache these otherwise they get garbage collected... const utterance_cache: SpeechSynthesisUtterance[] = [] + // By default we use the platform language over the default speech text, + // it appears that browsers like chrome fail to have it correctly based on the system. + // The default speech langauge _should_ be the same as platform language. synth.onvoiceschanged = () => { + let default_speech = undefined + let default_speech_by_language = undefined synth.getVoices().forEach((voice) => { availableAlertSpeechVoices.push(voice) - if (selectedAlertSpeechVoiceName.value === undefined && voice.default) { - selectedAlertSpeechVoiceName.value = voice.name + + if (voice.default) { + default_speech = voice + } + + if (voice.lang === navigator.language) { + default_speech_by_language = voice } }) + + if (selectedAlertSpeechVoiceName.value === undefined) { + if (default_speech_by_language !== undefined) { + selectedAlertSpeechVoiceName.value = default_speech_by_language.name + return + } + selectedAlertSpeechVoiceName.value = default_speech.name + } } const availableAlertSpeechVoiceNames = computed(() =>