Skip to content

Instantly share code, notes, and snippets.

@fwaechter fwaechter/say.html
Last active Sep 27, 2017

Embed
What would you like to do?
Simple Text2Speech Snippet in 10 Lines of JavaScript using URLSearchParams (not Supported in Internet Explorer): https://developer.mozilla.org/de/docs/Web/API/URLSearchParams
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Text2Speech</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<script type="text/javascript">
//<![CDATA[
var searchParams = new URLSearchParams(window.location.search);
var text2peech = searchParams.get("q");
var say = function(text) {
window.speechSynthesis.cancel();
return window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
};
say(text2peech);
document.write(text2peech);
//]]>
</script>
<form action="say.html" role="form" method="get">
<input type="text" name="q" />
<input type="submit" value="Sprich!" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.