fix: seleccionar voz española explícita en TTS del display_global

This commit is contained in:
Lizandro Guarnizo
2026-06-23 19:55:40 -05:00
parent 56f30f1c6d
commit ee50a47933
+22 -1
View File
@@ -495,6 +495,24 @@ function playBeep() {
} catch (_) {}
}
// Selección de voz española — cargada una vez, reutilizada en cada anuncio
let _vozES = null;
function getVozES() {
if (_vozES) return _vozES;
const voices = window.speechSynthesis.getVoices();
// Preferencia: es-CO → es-419 → es-MX → es-US → es-ES → cualquier es-*
for (const lang of ['es-CO','es-419','es-MX','es-US','es-ES']) {
const v = voices.find(v => v.lang === lang);
if (v) { _vozES = v; return v; }
}
const v = voices.find(v => v.lang.startsWith('es'));
if (v) { _vozES = v; }
return _vozES;
}
if ('speechSynthesis' in window) {
window.speechSynthesis.onvoiceschanged = () => { _vozES = null; getVozES(); };
}
function anunciarTurno(codigo, destino, paciente) {
playBeep();
if ('speechSynthesis' in window) {
@@ -505,7 +523,10 @@ function anunciarTurno(codigo, destino, paciente) {
if (paciente) texto += `, ${paciente}`;
texto += `, pase a ${destino}`;
const utt = new SpeechSynthesisUtterance(texto);
utt.lang = 'es-CO'; utt.rate = 0.85; utt.pitch = 1.05; utt.volume = 1;
utt.lang = 'es-CO';
const voz = getVozES();
if (voz) utt.voice = voz;
utt.rate = 0.85; utt.pitch = 1.05; utt.volume = 1;
window.speechSynthesis.speak(utt);
}, 800);
}