Skip to content

Instantly share code, notes, and snippets.

@wesbos
Last active July 20, 2022 18:13
Show Gist options
  • Save wesbos/cd16b8b1815825f111a2 to your computer and use it in GitHub Desktop.
Save wesbos/cd16b8b1815825f111a2 to your computer and use it in GitHub Desktop.
// paste in your console
speechSynthesis.onvoiceschanged = function() {
var msg = new SpeechSynthesisUtterance();
msg.voice = this.getVoices().filter(v => v.name == 'Cellos')[0];
msg.text = Object.keys(window).join(' ');
this.speak(msg);
};
@msikma
Copy link

msikma commented Feb 18, 2016

I've got Japanese too. Is this standard in all Chrome installs?

var msg = new SpeechSynthesisUtterance();
msg.voice = speechSynthesis.getVoices().filter(v => v.name == 'Google 日本語')[0];
msg.text = 'こんにちは皆さん!';
speechSynthesis.speak(msg);

@ToreJuloe
Copy link

@akenn The reason it's wrapped in the voiceschanged eventlistener, is that the voices are loaded asynchronously and this way you can make sure that they actually exist before you start using them.

It's no problem when you just run the snippet in the dev console, but if it's embedded on a page and set to run immediately, you'll get an error.

Here's a pretty cool Pen to play around with the different voices.

@L1fescape
Copy link

@ToreJuloe oh good to know - thanks!

@mathiasbynens
Copy link

Why not use Array#find? .filter(v => v.name == 'Cellos')[0].find(v => v.name == 'Cellos')

@msikma Not in my Opera/Chrome.

@riston
Copy link

riston commented Feb 19, 2016

Its not working in Linux window.speechSynthesis.getVoices() returns empty array no "voices" :(

@incleaf
Copy link

incleaf commented Mar 14, 2016

Wow 👍

@imtaehyun
Copy link

Love it!

@pokono
Copy link

pokono commented Mar 24, 2016

Awesome!!

@heytulsiprasad
Copy link

I really hope I wasn't the last one to find out this! Amazing 🎉

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