0

Can someone tell me the "best" way to detect Safari and then its version number?

Look, I don't want to do it but I can't find a way to pin down a WORKING version of speechSynthesis on Safari

See below for an example that works on iOS 7.1.2 IF you don't add the onEnd listener. Apart from that everything is peachy.

In my real world full blown example it talks but still won't deliver the at end event.

On iOS 8 there is no issue.

Please offer a best-of-breed agent/version sniffer or a better working-feature-detector.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function fini()
{
    alert("end");
}
function talk()
{
    if (!('speechSynthesis' in window)) {
        alert("Unsupported browser");
        return;
    }

    alert("Getting ready.");
    var utterance = "Hello World";
    var chat = new SpeechSynthesisUtterance(utterance);

    chat.addEventListener('end', fini, false);

    speechSynthesis.speak(chat);

}
</script>
</head>
<body>

<p>On Safari this example won't fire any known events<br />
onend, onerror, even onended: -</p>

<input type="button" value="Talk" onclick="talk()" />
<br /><br />
No probs on Chrome or Opera. Spewin!
</body>
</html>
Richard Maher
  • 41
  • 1
  • 9

2 Answers2

0

For the record, the addEventListener was throwing an exception on 7.2.1 that could be trapped to signify unsupported speech synthesis.

Richard Maher
  • 41
  • 1
  • 9
0

Opera mobile has laryngitis

Different problem same topic: -

You (and I) may question the correctness of this behaviour in Opera but it appears to be as simple as there are no known/registered/available voices for Opera Mobile on my Android phone :-(

"Sing for me Christine! Sing my angel, SING!" Sorry couldn't help it.

So are there any files I have to download?

FYI on Safari, apparently, the speechSynthesis.getVoices method is synchronous which makes life easy. Elsewhere it is asynchronous and will return an array of length 0 on first call.

We need to register an event such as: -

    speechSynthesis.onvoiceschanged = function() {
    voices = window.speechSynthesis.getVoices();
    alert("Voices " + voices.length);
    if (!done) theWork();
    };

This never fires on Opera Mobile. Curious!

Why don't I get a error from the synthesis specification like "language-unavailable" or "voice-unavailable"?

Because I didn't explicitly specify a language and a voice?

And why does Chrome deliver onvoiceschanged 3 times?

Richard Maher
  • 41
  • 1
  • 9