Created
February 23, 2018 18:10
-
-
Save bikubi/c2e2a3eb04d78c35815700ddf93dd0bd to your computer and use it in GitHub Desktop.
Synthesize a dialog via Chrome's built-in speech synthesis.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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