Last active
March 16, 2018 17:50
-
-
Save AutoSponge/74de6860b4243b925f2587e20b67b780 to your computer and use it in GitHub Desktop.
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
async function speak(text) { | |
const msg = new SpeechSynthesisUtterance(); | |
msg.text = text; | |
// msg.volume = 1; // 0 to 1 | |
// msg.rate = 1; // 0.1 to 10 | |
// msg.pitch = 1; //0 to 2 | |
// msg.lang = this.DEST_LANG; | |
msg.voice = await new Promise(resolve => { | |
// Voice are populated, async. | |
speechSynthesis.onvoiceschanged = (e) => { | |
const voices = window.speechSynthesis.getVoices(); | |
// for (const voice of voices) { | |
// console.log(voice.name, voice.localService) | |
// } | |
const name = 'Google UK English Male'; // Note: only works in Google Chrome. | |
resolve(voices.find(voice => voice.name === name)); | |
}; | |
}); | |
msg.onend = e => console.log('SPEECH_DONE'); | |
speechSynthesis.speak(msg); | |
} | |
speak(`yo! what's up?`) | |
// window.speechSynthesis.getVoices() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment