🎙️ Prueba de voces alemanas
Guten Tag, wie geht es dir heute, ich hoffe, du fühlst dich gut
(function () {
const textoPrueba = "Guten Tag, wie geht es dir heute, ich hoffe, du fühlst dich gut";
const selector = document.getElementById("selectorVozPrueba");
const boton = document.getElementById("botonProbarVoz");
const informacion = document.getElementById("informacionVoz");
let vocesAlemanas = [];
function cargarVoces() {
const todasLasVoces = window.speechSynthesis.getVoices();
vocesAlemanas = todasLasVoces.filter(function (voz) {
return voz.lang && voz.lang.toLowerCase().startsWith("de");
});
selector.innerHTML = "";
if (vocesAlemanas.length === 0) {
const opcion = document.createElement("option");
opcion.textContent = "Esperando voces alemanas...";
selector.appendChild(opcion);
informacion.textContent = "El navegador todavía está cargando las voces.";
return; }
vocesAlemanas.forEach(function (voz, indice) {
const opcion = document.createElement("option");
opcion.value = indice;
opcion.textContent = voz.name + " — " + voz.lang + (voz.default ? " — predeterminada" : "");
selector.appendChild(opcion);
});
informacion.textContent = "Encontradas " + vocesAlemanas.length + " voces alemanas.";
}
cargarVoces();
if ("onvoiceschanged" in window.speechSynthesis) {
window.speechSynthesis.addEventListener( "voiceschanged", cargarVoces );
}
boton.addEventListener("click", function () {
if (vocesAlemanas.length === 0) {
cargarVoces();
return;
}
const indice = parseInt(selector.value, 10);
const vozSeleccionada = vocesAlemanas[indice];
const voz = new SpeechSynthesisUtterance(textoPrueba);
voz.voice = vozSeleccionada;
voz.lang = vozSeleccionada.lang;
voz.rate = 0.9;
voz.pitch = 1;
voz.volume = 1;
window.speechSynthesis.cancel();
window.speechSynthesis.speak(voz);
informacion.textContent = "Escuchando: " + vozSeleccionada.name + " — " + vozSeleccionada.lang;
});
})();