JavaScript speechSynthesis.speak() without user activation is no longer allowed since M71

后端 未结 6 1081
失恋的感觉
失恋的感觉 2021-01-11 11:15

I used speechSynthesis API in this way:

speechSynthesis.speak(new SpeechSynthesisUtterance(\"hello world\"));

But right now I get error aft

6条回答
  •  一向
    一向 (楼主)
    2021-01-11 11:49

    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');
    

提交回复
热议问题