Text to Speech Demo

by SHELDON PASCIAK

HTML

<p>
    <label>Message
        <input type="text" id="text" value="Uræus"></input>
    </label>
</p>
<p>
    <label>Volume
        <input type="number" id="volume" value="1"></input>
    </label>
</p>
<p>
    <label>Rate
        <input type="number" id="rate" value="1"></input>
    </label>
</p>
<p>
    <label>Pitch
        <input type="number" id="pitch" value="1"></input>
    </label>
</p>
<p>
    <label>Voice
        <select id="voice"></select>
    </label>
</p>
<p>
    <button type="button">Speak!</button>
</p>

JavaScript

var message = new SpeechSynthesisUtterance("this is smart sign");
var voices = speechSynthesis.getVoices();

// Hack around voices bug
var interval = setInterval(function () {
    voices = speechSynthesis.getVoices();
    if (voices.length) clearInterval(interval); else return;

    for (var i = 0; i < voices.length; i++) {
        $("select").append("<option value=\"" + i + "\">" + voices[i].name + "</option>");
    }
}, 10);

 speechSynthesis.speak(message);