window speechsynthesis getvoices returns nothing
speechsynthesis speak new speechsynthesisutterance hey
html5 text to speech
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?
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);
This error means entire document (Website) has no user interaction and Google Chrome update its policy regarding making sound from the website without user interaction.
User interaction means:
click, dblclick, mouseup, pointerup, reset, submit etc.
So, if you want to run
speechSynthesis.speak(); without real user interaction, then you just create temporary user interaction using a method like
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.
Intent to Remove: speechSynthesis.speak without user activation , Deprecated in M70, slated for removal in M71. After deprecation, the plan is to cause speechSynthesis.speak to immediately fire a “not-allowed” error if specific autoplay rules are not satisfied. It's understaffed but the accessibility team is supporting it and hoping to put more resources into it in the future. 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.
I resorted to
swal("Click OK to speak").then(() => speakButton.click()); (with https://sweetalert.js.org) -- https://patarapolw.github.io/tts-api/?q=你好&lang=zh-CN&rate=0.8
if (confirm("Click OK to speak")) speakButton.click() doesn't work.
SpeechSynthesis.speak(), The speak() method of the SpeechSynthesis interface adds an utterance to the When a form containing the text we want to speak is submitted, we Chrome Full support 33, Edge Full support 14, Firefox Full support 49, IE No support No, Opera Full support 21 User must explicitly enable this feature. To overcome a similar problem, I put getAudioContext().resume() as a first line into the touchStarted method, since you need to have a user input first anyways.
A simple hack, without needing a real user activity, is to execute a click event on a hidden button like so.
document.querySelector('button').click(); var msg = new SpeechSynthesisUtterance('Test');
Remove SpeechSynthesis.speak without user activation, This deprecation will cause speechSynthesis.speak to immediately fire an error if the document has not received user activation. This API is being abused by sites since it is one of the only remaining APIs CSS · JS/HTML But I understand Google Chrome prevents auto play of any audio and gives an error [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
- So, we can call this speechSynthesis.speak(message); multiple times for 1 (initial) user interaction?
- UPDATE: I'm using Chromium in Raspbian, seems it no longer comes with pre-installed voices. So I synth the voices elsewhere and sent them as audio files, working fine now even without user interactions.
- I tried
alert(). Yeah, those clicks don't count, apparently.