top of page

Testing with Web Speech API

The latest installment in a series of posts related to finding an immersive test solution, this should work under chrome on desktop and android.

Code in place:

<!DOCTYPE html>
    <title>Web Speech API to Listen a Blog Post - By</title>

  .highlight {
    background-color: yellow;

    <button onclick="read()">Listen to Post</button>
    <button onclick="pause()">Pause</button>
<button onclick="resume()">Resume</button>

<div id="text-to-read">
  This is the text that will be highlighted as it is read.


    function speak(message, language='en-us'){
        const msg = new SpeechSynthesisUtterance(message);
        msg.lang = language;


    function read() {
      // Get the text to be spoken
      var text = document.querySelector("#text-to-read").innerText;

      // Speak the text

    function pause() {

function resume() {

function highlightWord(index) {
  // Get all the words in the text
  var words = document.querySelectorAll("#text-to-read span");

  // Remove the highlight from all the words
  for (var i = 0; i < words.length; i++) {

  // Highlight the current word

// Add a boundary event listener to the speech synthesis object
window.speechSynthesis.addEventListener("boundary", function(event) {
  // Get the index of the word boundary
  var index = event.charIndex;

  // Highlight the word at the boundary


Highlight functionality doesnt seem to be working, but I will take what I can get. It seems the text to speech is working well. however this does not work well on ios/chromer

I asked Chat GPT about this and it pointed me to espeak as a posisble alternative.


Thank You for Visiting Everything Neurodiversity!

Hello, Thank you for visiting Everything Neurodiversity. This site is a passion project of mine. The hosting costs are minimal and I try to dedicate time to it whenever I can. I intend to keep this site as educational and ad free. 

I have learned a great deal from working on this site and the social platforms that go along with it. So much that I have started another site dedicated to building a more sustainable and easier fashion shopping expiereince. It has recently been selected for sponsorship in the Microsoft Founders Hub Program and I'm excited for the new developments this will enable. The first 10,000 users who make a purchase through the site will get lifetime Premier Status enabling rewards up to 17%! Check it out here: RunwayRewards.Shop or browse the integrated page below: 

popular posts




HR Resources