JSFiddle - React, Tailwind, and code Playground

by Jake

HTML

<button>
Listen
</button>

JavaScript

// @ref https://youtu.be/QFZ-pwErSl4?t=1024
const phrases = [
	"The wheels on the bus go round and round, round and round, round and round",
  "Dibidi ba did dou dou, di ba did dou, didi dididididididi houdi dey dou",
  "hee haw hee haw... hee haw"
];

function getRandomArrayElement (arr) {
	var len = arr.length;
  var rand = Math.floor( Math.random() * Math.floor(len) );
  return arr[rand];
}

function speak( phrase ) {
	if( phrase == null )
  	phrase = getRandomArrayElement( phrases );
    window.speechSynthesis.speak( new window.SpeechSynthesisUtterance(phrase) );
}

document.querySelector('button').addEventListener('click', () => speak() );