A Pen by Tomek Główka on CodePen.
Created
August 7, 2018 18:42
-
-
Save glowka/77c8be61ab3bea479c723a555a60a3ac to your computer and use it in GitHub Desktop.
PByZvw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 | |
| <script src="http://code.responsivevoice.org/responsivevoice.js"></script> | |
| <textarea id="text-to-speak"></textarea> | |
| <input type="text" id="text-to-speak-pos"> | |
| <button onclick="start()"> | |
| start | |
| </button> | |
| <button onclick="pause()"> | |
| pause | |
| </button> | |
| <button onclick="resume()"> | |
| resume | |
| </button> | |
| <font id="current-pos"></font> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var step = 10; | |
| function speak(txt) { | |
| var pos = document.getElementById('text-to-speak-pos').value; | |
| var splitTxt = txt.split('\n'); | |
| var currentPos = pos ? parseInt(pos) : 0; | |
| function speakPart() { | |
| if(currentPos > splitTxt.length) { | |
| return; | |
| } | |
| var txtPart = splitTxt.slice(currentPos, currentPos + step).join('\n'); | |
| responsiveVoice.speak(txtPart,"US English Male", {rate: 0.95, onend: speakPart}); | |
| document.getElementById('current-pos').innerHTML = currentPos; | |
| currentPos += step; | |
| } | |
| speakPart(); | |
| } | |
| function start() { | |
| var txt = document.getElementById('text-to-speak').value; | |
| var cleanedTxt = txt.replace(/\n\n\n+/, '\n\n\n'); | |
| speak(cleanedTxt); | |
| } | |
| function pause() { | |
| responsiveVoice.pause(); | |
| } | |
| function resume() { | |
| responsiveVoice.resume(); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| textarea { | |
| width: 100%; | |
| height: 200px; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment