Skip to content

Instantly share code, notes, and snippets.

@jhrcek
Last active December 21, 2016 07:02
Show Gist options
  • Save jhrcek/a1d075d2f112a1db6b06a1b720a1a711 to your computer and use it in GitHub Desktop.
Save jhrcek/a1d075d2f112a1db6b06a1b720a1a711 to your computer and use it in GitHub Desktop.
Google chrome Speech synthesis API demo
<!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