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

后端 未结 6 1079
失恋的感觉
失恋的感觉 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:30

    Although I haven't found any way to ask permission, the user can enable permission in Google Chrome:

    1. Click on the icon on the left of the URL bar, and open Site settings

    2. Change the Sound setting from "Automatic (default)" to "Allow"

    After doing that, the site will be able to make sounds without any user interaction, including speech.

    Unfortunately, I haven't found a way in code to know whether this is working or not. (Perhaps we could try one of the other audio APIs and see if it responds with an error message.)

提交回复
热议问题