JSFiddle - React, Tailwind, and code Playground
HTML
<button>speak!</button>
JavaScript
const btn = document.querySelector('button');
const speak = (msg) => {
const sp = new SpeechSynthesisUtterance(msg);
[sp.voice] = speechSynthesis.getVoices();
speechSynthesis.speak(sp);
};
btn.addEventListener('click', () => {
speak('My name is Inigo Montoya, you killed my father, prepare to die!');
});