In case you'd like to know what they all sound like (there's a bunch of funny ones)
var pack_msg = (v, i) => { return { voice: v, text: `hi there from the voice named ${v.name}` }; },
msgs = speechSynthesis.getVoices().map(pack_msg),
speaker = new SpeechSynthesisUtterance(),
halt = false;
function speakOne(i, overrideMessage) {
if (halt) { halt = false; speaker.onend = undefined; return; }
speaker.voice = msgs[i].voice;
speaker.text = overrideMessage || msgs[i].text;
speechSynthesis.speak(speaker);
console.log(`Saying #${i} "${speaker.voice.name}"`);
}
function speakAll() {
var cursor = 0;
speaker.onend = () => (++cursor) >= msgs.length? true : speakOne(cursor); // chain each end
speakOne(cursor); // start the series
}
Call speakOne(i)
to listen to any specific voice by index, or speakAll()
to listen to them all.
To bail, set halt
to true in the console. speechSynthesis.cancel()
will only cancel the currently speaking voice.