arekuzu
Pendej@
- Registrado
- 2007/07/14
- Mensajes
- 219
Tengo un script sencillo:
al hacer clic en el botón funciona perfecto, pero como lo llamo desde la etiqueta <body>, para que hable al cargar la pagina?
HTML:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var voices = [];
$(document).ready(function() {
voices = window.speechSynthesis.getVoices();
console.log('Get voices ' + voices.length.toString());
for(var i = 0; i < voices.length; i++ ) {
console.log("Voice " + i.toString() + ' ' + voices[i].name);
}
$("#demo_1").on('click', function(e) {
// e.preventDefault();
var u1 = new SpeechSynthesisUtterance('Has llegado a tu destino');
u1.lang = 'es-ES';
u1.pitch = 1;
u1.rate = 1;
u1.voice = voices[10];
u1.voiceURI = 'native';
u1.volume = 1;
speechSynthesis.speak(u1);
console.log("Voice " + u1.voice.name);
});
});
</script>
</head>
<body>
<input type="button" id="demo_1" value="Speak">
</body></html>