If you ever need to add text-to-speech capabilities to your website, you can simply include the HTML code shown below
into your website’s code. You can remove the code for any of the buttons that you do not need. The <textarea>
tag is not absolutely necessary. It is included here simply to provide a source for the text to be converted to speech
which is represented by the “text” variable. Please note that the “soft mute” switch on the side of IOS devices must not
be in the “mute” position, otherwise the text-to-speech capability will be disabled..
Webpage View |
Type some text in the box below and then click the “Listen” button. |
HTML Code View |
<script>
// Copy this script into your HTML function TTS_Speak(text) {speechSynthesis.cancel(); var text; speechSynthesis.speak(new SpeechSynthesisUtterance(text));} function TTS_Pause() {speechSynthesis.pause();} function TTS_Resume() {speechSynthesis.resume();} function TTS_Stop() {speechSynthesis.cancel();} </script>
<!– Code Example : Using the script functions above –>
<textarea id=”msg” rows=”3″ style=”width:95%;”></textarea> <button value=”Listen” onclick=”var text=document.getElementById(‘msg’).value; TTS_Speak(text);”>Listen</button> <button value=”Pause” onclick=”TTS_Pause();”>Pause</button> <button value=”Resume” onclick=”TTS_Resume();”>Resume</button> <button value=”Stop” onclick=”TTS_Stop();”>Stop</button> |
If you need to convert text into speech as an MP3 audio file, then you can use TTSMP3.com.
Related Articles
No user responded in this post