Skip to content

Instantly share code, notes, and snippets.

@mizanmahi
Created October 13, 2021 16:27
Show Gist options
  • Save mizanmahi/ccf14bc6ef4de7f224e7fb2b64fab463 to your computer and use it in GitHub Desktop.
Save mizanmahi/ccf14bc6ef4de7f224e7fb2b64fab463 to your computer and use it in GitHub Desktop.
Js text to speech api
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