-2

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.

Tahmid
  • 185
  • 1
  • 4
  • 20
  • 1
    How would you like it if any random web page could start speaking to you? This feature is blocked for very good reasons. – JK. Feb 12 '20 at 03:35
  • @JK, As much as everyone thinks this is for malicious reasons. I'm creating a web app that helps people with dementia remember things by playing back the reminder aloud. I only posted to see if there was a workaround as I don't really see any other solution. If there isn't then so be it. – Tahmid Feb 12 '20 at 03:42
  • @Tahmid given your use case, could you maybe have a user interact with a button etc once, and have that interaction trigger something like `setInterval` to check for memos? Not an ideal solution of course, but it works. – NoSock Feb 19 '20 at 13:25
  • Who is loading the page? Or the browser? And why, while being able to do so, this someone is unable to interact with the page? Could you please tell the full user story behind you code – x00 Feb 21 '20 at 14:30

1 Answers1

-1

If, as it's said in your EDIT, you want to use your code on your own computer (computers in some way controlled by you), you may instead use some automation tool (and it will press buttons/interact with the page on your behalf).
I don't know what is trending now. Puppeteer or Intern or something like that, probably, will be an overkill (and puppeteer is headless, as far as I know). A long time ago, I personally, used AutoIt.

x00
  • 13,643
  • 3
  • 16
  • 40