Last active
September 27, 2017 18:06
-
-
Save fwaechter/d5106455b3302b2aca55fe82de01b9ea to your computer and use it in GitHub Desktop.
Simple Text2Speech Snippet in 10 Lines of JavaScript using URLSearchParams (not Supported in Internet Explorer): https://developer.mozilla.org/de/docs/Web/API/URLSearchParams
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
<!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