'When will SpeechSynthesis.speak work on iOS Safari?
I've been exploring the limits on SpeechSynthesis.speak on iOS Safari. I believe the current rules are more restrictive than there were in the recent past.
Are the rules documented anywhere?
These are the rules that I think apply.
- Speak in direct response to a click on a
<button>
always works. - After the initial speak initiated by a button click additional speaks are allowed on the same page. They may be triggered programmatically by timers or whatever.
- Initial speak on a change/input event does not work.
- Initial speak on a click event on a
<tr>
does not work. - Any change of page, relative or not, puts you back to square one requiring a direct user action.
- When a speak is suppressed you don't get any events nor any error indication.
- You want tell if the speak was suppressed by watching for
SpeechSynthesis.speaking
and timing out if it isn't seen after some delay.
Are these consistent with your recent experience?
I've been testing on BrowserStack watching the events that get fired to determine which cases work.
Solution 1:[1]
I can confirm that you can't use SpeechSynthesisUtterance
programmatically without a user action before. In my case I have in my web app a button to enable/disable audio, if the user enable the audio and later I try to speak something, it doesn't work
To solve it I had to trigger a fake speak (empty text new SpeechSynthesisUtterance('')
) right after the user click on enable audio and then the audio works during all the session.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Simon M. |