Skip to content

Instantly share code, notes, and snippets.

@ganmahmud
Last active October 21, 2021 05:49
Show Gist options
  • Save ganmahmud/8770a5c213d551655d0355f8162b3c19 to your computer and use it in GitHub Desktop.
Save ganmahmud/8770a5c213d551655d0355f8162b3c19 to your computer and use it in GitHub Desktop.
Text to Speech with JavaScript
const textToSpeech = (text) => {
const speech = new SpeechSynthesisUtterance(text);
[speech.voice] = speechSynthesis.getVoices();
// sp.rate = ?; //speed of the voice. Default value is 1. lowest = 0.1 and highest = 10
// sp.pitch = ?; //pitch of the voice. Default value is 1. lowest = 0 and highest = 2
speechSynthesis.speak(speech);
};
textToSpeech('Hello TalkJS!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment