The Simplest Way to Convert Text to Speech

Sharing is caring!

474 Views

https://responsivevoice.org/
You can instantly voice-enabled your website. Using this you can instantly create any text to speech.
To use Text to Speech, you need to create an account first and then use unique Key.
Include this js library first.

<script src="https://code.responsivevoice.org/responsivevoice.js?key=YOUR_UNIQUE_KEY"></script>

 

speak(String text, [String voice], [Object parameters])

 

Starts speaking the text in a given voice.
Parameters
text: String
The text to be spoken.
voice: String
Defaults to “UK English Female”. Choose from the available ResponsiveVoices.
parameters: Object

Used to add optional pitch (range 0 to 2), rate (range 0 to 1.5), volume (range 0 to 1) and callbacks.

Pitch, rate and volume may not affect audio on some browser combinations, older versions of Chrome on Windows for example.

responsiveVoice.speak("hello world");

responsiveVoice.speak("hello world", "UK English Male");

responsiveVoice.speak("hello world", "UK English Male", {pitch: 2});

responsiveVoice.speak("hello world", "UK English Male", {rate: 1.5});

responsiveVoice.speak("hello world", "UK English Male", {volume: 1});

responsiveVoice.speak("hello world", "UK English Male", {onstart: StartCallback, onend: EndCallback});

 

Speak a specified element on the page:

responsiveVoice.speak(document.getElementById("article-container").textContent);

 

Returns: true/false

cancel()

 

Stops playing the speech.

responsiveVoice.cancel();

voiceSupport()

 

Checks if browser supports native TTS

if(responsiveVoice.voiceSupport()) {
responsiveVoice.speak("hello world");
}

 

Returns: true/false

getVoices()
var voicelist = responsiveVoice.getVoices();

 

Returns: a list of available voices

setDefaultVoice()
responsiveVoice.setDefaultVoice("US English Female");

 

isPlaying()

 

Detects if native TTS or TTS audio element is producing output.

if(responsiveVoice.isPlaying()) {
console.log("I hope you are listening");
}

 

Returns: true/false

pause() and resume()

 

Pauses/Resumes speech

responsiveVoice.pause();

responsiveVoice.resume();

 

Leave a Reply

avatar
  Subscribe  
Notify of