Skip to content

Instantly share code, notes, and snippets.

Forked from kypflug/SpeechSynthesisUtterance.js
Created December 20, 2016 13:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
function speak(textToSpeech) {
var synUtterance = new SpeechSynthesisUtterance(textToSpeech);
if (voiceSelect.value) {
synUtterance.voice = speechSynthesis.getVoices().filter(function (voice) { return == 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}'.`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment