Skip to content

Instantly share code, notes, and snippets.

@schollz
Last active January 19, 2016 19:49
Show Gist options
  • Save schollz/224c331810f44ce743a4 to your computer and use it in GitHub Desktop.
Save schollz/224c331810f44ce743a4 to your computer and use it in GitHub Desktop.
var msg = new SpeechSynthesisUtterance();
var voices = window.speechSynthesis.getVoices();
msg.voice = voices[2]; // Note: some voices don't support altering params
msg.voiceURI = 'native';
msg.volume = 1; // 0 to 1
msg.rate = 0.75; // 0.1 to 10
msg.pitch = 0; //0 to 2
msg.lang = 'en-US';
messages = ["A light inherits.","Blushes.","And it does not return.","The enchanting color of this crystal planetarium.","Like how the somber brick of","communities that water the domestic forests","Are trusted.","I get the feeling.","They must have lots to imbue to each other","Since the value imposes necessity.","And necessity equates love."];
var messageNumber = 0;
msg.text = messages[messageNumber];
msg.onend = function(e) {
console.log('Finished in ' + event.elapsedTime + ' seconds.');
messageNumber = messageNumber + 1;
msg.text = messages[messageNumber];
if (msg.text=="pause") {
msg.volume = 0;
} else {
msg.volume = 1;
}
if (messageNumber < messages.length) {
speechSynthesis.speak(msg);
}
};
speechSynthesis.speak(msg);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment