This example shows how to create a text to speech widget allowing the visitor to enter their own text, choose a voice and click Play to listen.
This is example code to add anywhere in a page where you want the Text to Speech Widget to appear.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<script src="https://code.responsivevoice.org/responsivevoice.js"></script> <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <textarea id="text" cols="45" rows="3">Hello world</textarea> <select id="voiceselection"></select> <input onclick="responsiveVoice.speak($('#text').val(),$('#voiceselection').val());" type="button" value="Play" /> <script> //Populate voice selection dropdown var voicelist = responsiveVoice.getVoices(); var vselect = $("#voiceselection"); $.each(voicelist, function() { vselect.append($("<option />").val(this.name).text(this.name)); }); </script> |
Keywords: text to speech widget, interactive text to speech