62 lines
1.9 KiB
HTML
62 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Prueba de SpeechSynthesis</title>
|
|
</head>
|
|
<body>
|
|
<button onclick="hablar()">Hacer hablar</button>
|
|
|
|
<script>
|
|
|
|
function iterar_voces(text, voices, i){
|
|
if(i >= voices.length)
|
|
return;
|
|
|
|
const utterance = new SpeechSynthesisUtterance(text);
|
|
|
|
utterance.voice = voices[i];
|
|
utterance.onend = () => iterar_voces(text, voices, i + 1);
|
|
console.log([voices[i], i]);
|
|
|
|
speechSynthesis.speak(utterance);
|
|
|
|
};
|
|
|
|
function hablar(){
|
|
// speechSynthesis.cancel();
|
|
|
|
const voices = speechSynthesis.getVoices().filter(voice => voice.lang == "es");
|
|
|
|
console.log(voices);
|
|
iterar_voces('¡Hola, mundo! Esto es una prueba. ¿Qué tal funciona?', voices, 0);
|
|
// voices.forEach((voice, i) => {
|
|
|
|
// iterar_voces('¡Hola, mundo! Esto es una prueba. ¿Qué tal funciona?');
|
|
|
|
// speechSynthesis.speak(utterance);
|
|
|
|
// });
|
|
// utterance.voice = voices[4];
|
|
// speechSynthesis.speak(utterance);
|
|
// speechSynthesis.
|
|
// window.speechSynthesis.onvoiceschanged = () => {
|
|
// const voices = window.speechSynthesis.getVoices();
|
|
|
|
// // Verifica si se han cargado voces
|
|
// if (voices.length === 0) {
|
|
// console.error('No se encontraron voces.');
|
|
// return;
|
|
// }
|
|
|
|
// // Selecciona la primera voz disponible (puedes personalizar esto)
|
|
// const selectedVoice = voices[0];
|
|
|
|
// const utterance = new SpeechSynthesisUtterance('Hola, mundo!');
|
|
// utterance.voice = selectedVoice;
|
|
|
|
// window.speechSynthesis.speak(utterance);
|
|
// };
|
|
};
|
|
</script>
|
|
</body>
|
|
</html> |