I used speechSynthesis API in this way:
speechSynthesis.speak(new SpeechSynthesisUtterance("hello world"));
But right now I get error after update Google Chrome:
[Deprecation] speechSynthesis.speak() without user activation is no longer allowed since M71, around December 2018. See https://www.chromestatus.com/feature/5687444770914304 for more details speechSynthesisMessage @ application-2c16c437c2795ae01c0a8852e5f8da58dad99d6e17814a31f1eea19922c5ebd2.js:147
How I can fix this issue and ask permission?
JavaScript speechSynthesis.speak() without user activation is no longer allowed since M71 Ask Question Asked3 years ago Active11 months ago Viewed15k times 17 1
This poilicy was extended to speechSynthesis.speak calls. Chrome followed suit and now prints a deprecation warning: speechSynthesis.speak() without user activation is no longer allowed since M71, around December 2018.
The javascript speechSynthesis API is powerful but difficult to use in a production environment supporting multiple platforms and browsers. Lessons Learned Using the javascript speechSynthesis API Make my pictures talk! SpeechSynthesis is a Dou$#@bag
The speak () method of the SpeechSynthesis interface adds an utterance to the utterance queue; it will be spoken when any other utterances queued before it have been spoken. Void. A SpeechSynthesisUtterance object.
This is part of Chrome's new policies regarding making sound from web-pages.
You simply need your user to provide an user-gesture (for which you can find a list here) during the lifetime of the parent document (i.e the event may long be dead, as long as the user ever interacted with the page).
Note that these events can even traverse frames, so for instance, in StackOverflow, the simple fact that you do have to click on the "Run" button will make the inner frame allowed to execute this code:
const ut = new SpeechSynthesisUtterance('No warning should arise');
speechSynthesis.speak(ut);
And in your code, you simply have to provide some kind of an UI that will ensure your users have interacted with the page before you call this method (e.g a button / toggle will do perfectly).
If you set your site address as "trusted" in chrome://settings/content/sound it seems to enable sound and speech synthesis even without user interactions.
I use Chrome in a TV just as a system monitor, using kiosk mode and without any user interactions. It doesn't even have keyboard and mouse. Still, I was able to enable in some versions of Chrome/Chromium, but not in others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With