SpeechSynthesis has no voices or errors Opera 28 Android 4.4.2
-
maherrj last edited by
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> -
maherrj last edited by
Here's the best strategy I can come up with as Opera is small beer and I have to get on to speech Recognition: -
The first getVoices() tells Opera to swing into action.
Opera needs you to release the thread so it can get the voices info
Opera will not honour/deliver the onvoiceschanged event.
I stick a setTimout(myvoicesHandler,0) in there.
If the handler gets voices it updates the selections else it stays at zero
the feature detection has to move way down into the codeBut why are there no voices on Opera 28 Android 4.4.2?