2

I want to use the HTML5 Speech API to synthesize speech by calling window.speechSynthesis.speak(...), which works in nearly all browsers as expected, but I have some trouble with iOS Safari:

Calling speechSynthesis.speak(...) is only possible in iOS Safari if the user has actually triggered the function call himself by clicking somewhere. If this is the case, everything works as expected. The problem I have is that I need to call speechSynthesis.speak(...) in a callback function that is called when a http request returns. As this callback function is no longer directly triggered by the user, the speech synthesizer doesn't work.

Is there any way to work around this restriction? I know that the behavior is supposed to protect the user from misuse of the API, but in my scenario the synthesis is triggered by a user action, but there's the remote request in between.

SebastianR
  • 1,683
  • 2
  • 17
  • 33
  • http://stackoverflow.com/a/33748459/226844 I don't know if what this guy suggests work or not, will try it when I get my hand on an iPhone. Maybe u can try it and let me know – Sarsaparilla Feb 13 '17 at 08:05
  • https://responsivevoice.org/faq/#thb-section-0-row-0-column-0-block-5 also according to this, user action is only needed the first time – Sarsaparilla Feb 13 '17 at 08:09
  • 1
    You're right, you only need to trigger it from a user action once. So, what I've done is that I call speechSynthesis.speak(" ") when the user does something. Later calls of speak(...) work then, regardless of what triggered them! – SebastianR Feb 13 '17 at 16:47
  • Fantastic! I'm going to do the same for my site http://readaloud.news – Sarsaparilla Feb 13 '17 at 18:26

0 Answers0