HTML speech not working on Safari mac "TypeError"

HTML5 speech does not work on Safari on mac 10.0.1,

I get an error,

TypeError: argument 1 ('statement') on SpeechSynthesis.speak must be an instance of SpeechSynthesisUtterance

It works on Chrome and Firefox, and I'm sure it worked on Safari ...

var u = new SpeechSynthesisUtterance(); u.text = "hello world"; u.lang = "en"; window.speechSynthesis.speak(u); 
+5
source share
1 answer

Ok, finally figured it out.

I had a compatibility code to support html5 speechless browser,

 if (SpeechSynthesisUtterance == undefined) { function SpeechSynthesisUtterance(text) { this.text = text; } } 

This works in Chrome and Firefox, but in Safari it seems that any function in any script is evaluated when the script is analyzed, so the function is declared even though SpeechSynthesisUtterance already exists.

I think I will need to do it differently ...

+2
source

Source: https://habr.com/ru/post/1260235/


All Articles