谷歌从变量翻译文本到语音

时间:2013-05-12 10:46:48

标签: javascript text-to-speech

该场景是我从用户那里获得输入并需要为该文本提供音频。来自用户的输入存储在变量中。如何将变量的值提供给Google tts

    <html>
<head>
<script src="jquery.js"></script>
<script>
function myfunction()
{
$("#div_style").html($("#text_area_id").val());
if(typeof(Storage)!=="undefined")
  {
  localStorage.lase=$("#text_area_id").val();
  document.getElementById("div_style").innerHTML=" " + localStorage.lase;

var audio = new Audio();
audio.src ='http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=localStorage.lase;
audio.play();
 }
}
</script>
</head>
<body>
<form name="myform"> 
<textarea name="text_area" id="text_area_id" rows="2" cols="16"></textarea>
</form> 

<input type="button" onclick="myfunction()" value="save" />
<div style="color:red" id="div_style">
</div>is certified.
</body>
</html>

1 个答案:

答案 0 :(得分:0)

尝试附加变量:

audio.src ='http://translate.google.com/translate_tts?ie=utf-8&tl=en&q=' + localStorage.lase;

如果它适用于字符串,它应该可以工作。