How to use JS class SpeechSynthesis in an OpenFl build to html5?

In the console for a browser I can enter the following and it speaks that string:

speechSynthesis.speak(new SpeechSynthesisUtterance(“Currently it is 3 in the afternoon.”))

I’m trying to figure out how to add code to my OpenFl project that will do the same thing.

speechSynthesis is obviously an instance of js.html.SpeechSynthesis that exists somewhere. I don’t know how to access it. I’ve tried to create an instance of SpeechSynthesis but that produces a run-time error of “Can’t find variable: SpeechSynthesis”

Any ideas? Please give exact code lines to use. Thanks.

var speechSynthesis = cast(, js.html.Window).speechSynthesis;
1 Like

Thanks. I was able to come up with these lines which also work:

var speechSynthesis:SpeechSynthesis = Browser.window.speechSynthesis;
var utter:SpeechSynthesisUtterance = new SpeechSynthesisUtterance(text);