Skip to content

Instantly share code, notes, and snippets.

@jojijacobk
Last active August 9, 2019 17:38
Show Gist options
  • Save jojijacobk/588eb95d771f323dfee163c326b1c003 to your computer and use it in GitHub Desktop.
Save jojijacobk/588eb95d771f323dfee163c326b1c003 to your computer and use it in GitHub Desktop.
To simulate speech from browser using all the voices installed in your computer
// To simulate speech from browser using all the voices installed in your computer
Array.from(window.speechSynthesis.getVoices()).forEach(voice => {
console.log(voice);
const msg = new SpeechSynthesisUtterance();
msg.voice = voice; // Note: some voices don't support altering params
msg.voiceURI = 'native';
msg.volume = 1; // 0 to 1
msg.rate = 1; // 0.1 to 10
msg.pitch = 2; // 0 to 2
msg.text = 'Hello World';
msg.lang = 'en-US';
msg.onend = function onend(event) {
console.log(`Finished in ${event.elapsedTime} seconds.`);
};
window.speechSynthesis.speak(msg);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment