/SpeechSynthesisUtterance.js Secret
Created
December 20, 2016 13:46
-
-
Save thebeebs/1fcf1416c226aa6d7d92b1ca7f1a4424 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
function speak(textToSpeech) { | |
var synUtterance = new SpeechSynthesisUtterance(textToSpeech); | |
if (voiceSelect.value) { | |
synUtterance.voice = speechSynthesis.getVoices().filter(function (voice) { return voice.name == voiceSelect.value; })[0]; | |
} | |
synUtterance.lang = langSelect.value; | |
synUtterance.volume = parseFloat(volumeRange.value); | |
synUtterance.rate = parseFloat(rateRange.value); | |
synUtterance.pitch = parseFloat(pitchRange.value); | |
const eventList = ["start", "end", "mark", "pause", "resume", "error", "boundary"]; | |
eventList.forEach((event) => { | |
synUtterance.addEventListener(event, (speechSynthesisEvent) => { | |
log(`Fired '${speechSynthesisEvent.type}' event at time '${speechSynthesisEvent.elapsedTime}' and character '${speechSynthesisEvent.charIndex}'.`); | |
}); | |
}); | |
window.speechSynthesis.speak(synUtterance); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment