window.speechSynthesis.getVoices().length returns 0
Opera never triggers onvoiceschanged yet (on windows desktop) the call to speechSynthesis.speak(chat) works and after the voice invocation getVoices() now returns an array of length one. On Android I get no audio and no errors and absolutely no events
Please help.
Cheers Richard Maher
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var voices;
var done = false;
function fini()
{
alert("end");
}function errorLog()
{
alert("error");
}
function talk()
{
if (!('speechSynthesis' in window)) {
alert("Unsupported browser");
return;
}
alert("Count is "+speechSynthesis.getVoices().length);
try {
speechSynthesis.onvoiceschanged = function() {
voices = window.speechSynthesis.getVoices();
alert("Voices " + voices.length);
if (!done) theWork();
};
voices = speechSynthesis.getVoices();
if (voices.length != 0) theWork();
} catch (err) {alert("0");alert(err.description||err.message);}
alert("Hello");
}
function theWork()
{
done = true;
alert("Getting ready." + speechSynthesis.speaking + voices.length);
var utterance = "Hello World";
var chat;
try {
chat = new SpeechSynthesisUtterance(utterance);
} catch (err) {alert("1");alert("new error "+ err.description||err.message);}
alert("a");
try {
chat.addEventListener('end', fini, false);
} catch (err) {alert("2");alert("AddEvent "+ err.description||err.message);}
alert("b");
try {
chat.addEventListener('error', errorLog, false);
} catch (err) {alert("3");alert("AddEvent "+ err.description||err.message);}
alert("c");
try {
chat.addEventListener('abort', errorLog, false);
} catch (err) {alert("4");alert("AddEvent "+ err.description||err.message);}
alert("d");
try {
speechSynthesis.speak(chat);
} catch (err) {alert("5");alert("Speak "+ err.description||err.message);}
alert("e");
}
</script>
</head>
<body>
On Safari this example won't fire any known events
onend, onerror, even onended: -
<input type="button" value="Talk" onclick="talk()" />
No probs on Chrome or Opera. Spewin!
</body>
</html>