Michael Haufe (\"TNO\")
4/2/2015 1:00:00 AM
On Wednesday, April 1, 2015 at 3:49:28 AM UTC-5, Richard Maher wrote:
> 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. (I'm assuming here Safari versions are tied
> to the OS?)
>
> Please offer a best-of-breed agent 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>
On Safari is the button failing silently onclick? Is it not throwing an exception when it sees: "new SpeechSynthesisUtterance"? If it at least throw an error you could wrap with try..catch