I'm experimenting with the Speech Synthesis API. I have the following code:
var message = new SpeechSynthesisUtterance("Hello");
window.speechSynthesis.speak(message);
The code works perfectly fine, however it only works when the user has clicked or interacted with the current page on the browser. I get the following warning on the Chrome console when attempting to run the code without interacting with the page first:
speechSynthesis.speak() without user activation is no longer allowed since M71, around December 2018. See https://www.chromestatus.com/feature/5687444770914304 for more details
I want the code to run as soon as a user loads the page without them having to interact with the page first.
I looked into simulating a page click with javascript/jquery like this:
$('#randomElementOnPage').trigger('click');
And then running the speech code, but it doesn't seem to trick the browser.
Any solutions/advice is appreciated.
Thanks.
EDIT: Since there doesn't seem to be any solutions, are there any browser/audio settings in Chrome, etc I can change for myself to allow this to work for myself only. Someone suggested going to chrome://settings/content/sound
and adding the site to the list of allowed sites for audio. However, this does not seem to work either.