Skip to content

Instantly share code, notes, and snippets.

@leonardokl
Last active April 7, 2017 00:49
Show Gist options
  • Save leonardokl/f7129f73941bca14070a50e393cbc9fb to your computer and use it in GitHub Desktop.
Save leonardokl/f7129f73941bca14070a50e393cbc9fb to your computer and use it in GitHub Desktop.
tts.js
/* global SpeechSynthesisUtterance */
const speechSynthesis = window.speechSynthesis
const synthesizeSpeech = (text, { lang = 'pt-BR' } = {}) => {
const utterThis = new SpeechSynthesisUtterance(text)
const voices = speechSynthesis.getVoices()
const selectedVoice = voices.find(i => i.lang === lang)
utterThis.voice = selectedVoice
utterThis.pitch = 1
utterThis.rate = 1
speechSynthesis.speak(utterThis)
}
export default synthesizeSpeech
// synthesizeSpeech('TESTE')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment