Last active
December 21, 2016 07:02
-
-
Save jhrcek/a1d075d2f112a1db6b06a1b720a1a711 to your computer and use it in GitHub Desktop.
Google chrome Speech synthesis API demo
This file contains 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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Chrome Speech Synthesis API Demo</title> | |
<script> | |
var utterance | |
function readText() { | |
var text = document.getElementById('textInput').value; | |
utterance = new SpeechSynthesisUtterance(text); | |
utterance.lang = getSelectedLanguage(); | |
utterance.rate = 1.0; | |
window.speechSynthesis.speak(utterance); | |
} | |
function stopReading() { | |
window.speechSynthesis.cancel(); | |
} | |
function getSelectedLanguage() { | |
return document.querySelector('input[name="language"]:checked').value; | |
} | |
</script> | |
</head> | |
<body> | |
<textarea id="textInput" rows="10" cols="50"></textarea><br/> | |
<label><input type="radio" name="language" value="de-DE" checked>German</label> | |
<label><input type="radio" name="language" value="en-EN">English</label> | |
<label><input type="radio" name="language" value="fr-FR">French</label> | |
<input type="button" value="Speak" onclick="readText();" /> | |
<input type="button" value="Stop" onclick="stopReading();" /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment