JavaScript SpeechSynthesis API

Published on:

As the web continues to be the medium for all users, standards bodies need to continue to provide new APIs to enrich user experience and accessibility. One underused API for unsighted users is speechSynthesis, an API to programmatically direct the browser to audibly speak any arbitrary string.

The Code

You can direct the browser to utter speech with window.speechSynthesis and SpeechSynthesisUtterance:

window.speechSynthesis.speak(
    new SpeechSynthesisUtterance('Hey Jude!')
)

speechSynthesis.speak will robotically tell the user anything you provide as a SpeechSynthesisUtterance string. Support for this API is available in all modern browsers.

I wouldn’t consider speechSynthesis as a replacement for native accessibility tools, but this API could be used to improve what native tools provide!

Request Metrics real user monitoring
Request Metrics real user monitoring
Request Metrics real user monitoring
  • Conquering Impostor Syndrome

    Conquering Impostor Syndrome

    Two years ago I documented my struggles with Imposter Syndrome and the response was immense.  I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions.  I’ve even caught myself reading the post…

  • JavaScript Promise API

    JavaScript Promise API

    While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why “hold up the show” when you can trigger numerous requests at once and then handle them when each is ready?  Promises are becoming a big part of the JavaScript world…

  • Image Data URIs with PHP

    Image Data URIs with PHP

    If you troll page markup like me, you’ve no doubt seen the use of data URI’s within image src attributes. Instead of providing a traditional address to the image, the image file data is base64-encoded and stuffed within the src attribute. Doing so saves…

  • MooTools Font-Size Scroller with Cookie Save

    MooTools Font-Size Scroller with Cookie Save

    Providing users as many preferences as possible always puts a smile on the user’s face. One of those important preferences is font size. I can see fine but the next guy may have difficulty with the font size I choose. That’s why…


Source link

Related