Monday, September 14, 2015

Text to Speech

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text to Speech</title>
</head>
<body>
<input type ="text" name ="text" />
<a href ="#" class ="say">Say it!</a>
<audio src = "" class = "speech" hidden ></audio>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
$('a.say').on('click',function(e){
e.preventDefault();
console.log(text);
var text = $('input[name="text"]').val();
text = encodeURIComponent(text);
var url ="https://translate.google.com/translate_tts?ie=UTF-8&q="+text+"&tl=en";
$('audio').attr('src',url).get(0).play();
});
});
</script>
</body>

</html>
OUTPUT
Text to Speech Say it!

No comments:

Post a Comment