Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Last active February 18, 2016 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StoneCypher/0480f3531e54d9156e00 to your computer and use it in GitHub Desktop.
Save StoneCypher/0480f3531e54d9156e00 to your computer and use it in GitHub Desktop.
How to hear all of Chrome's voices

How to hear all of Chrome's voices

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment