Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Synthesize a dialog via Chrome's built-in speech synthesis.
// Synthesize a dialog via Chrome's built-in speech synthesis.
// Hardcoded to British Male / US Female, slightly slowed down,
// with random pauses between lines.
// Copy&paste this into Chrome's Console.
// You might have to copy the first 2 lines individually / with delay / twice;
// getVoices() takes a while? (Chrome 57)
var msg = new SpeechSynthesisUtterance();
var voices = speechSynthesis.getVoices();
// check here if voices is populated and not []
// if so, repeat last line & check again
console.log(voices);
if (! voices[0]) console.error('no voice');
var v = [
voices[1],
voices[3]
];
console.log(v);
var s = [
'Hello, What\'s Up!',
'Nice to meet you.',
'I will ask you questions. Are you ready?',
'I was born ready.'
];
var i = 0;
msg.onend = function (e) {
if (i < s.length) {
window.setTimeout(function () {
next();
}, Math.random() * 3000);
}
}
function next () {
var vno = i % 2;
msg.voice = v[vno];
//msg.voiceURI = 'native';
msg.text = s[i];
msg.rate = (vno === 0) ? .7 : .85;
console.log(v, vno, msg.voice, msg.rate, msg.text);
speechSynthesis.speak(msg);
i++;
}
next();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment