JavaScript调用百度语音朗读信息

  

<title>JavaScript利用百度语音服务朗读文字示例</title>
名字:<input type="text" id="txtName" /><br>
其他:<input type="text" id="txtOther" /><input type="button" onclick="setSrc()" value="朗读"/>
<div id="dvAudio"></div>
<script type="text/javascript">
    function setSrc() {
        var t = (document.getElementById('txtName').value + ' ' + document.getElementById('txtOther').value).replace(/^\s+|\s+$/g, '');
        if (t == '') { alert('请输入内容!'); return; }
        t = encodeURI(t);
        var s = "<audio autoplay=\"autoplay\">"
        + "<source type=\"audio/mpeg\" src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text=" + t + "\">"
        + "<embed  height=\"0\" width=\"0\" src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text=" + t + "\" >"
        + "</audio>";
        document.getElementById('dvAudio').innerHTML = s;
    }
</script> 

 


原创文章,转载请注明出处:JavaScript调用百度语音朗读信息

评论(1)Web开发网
阅读(264)喜欢(0)不喜欢(0)JavaScript/Ajax开发技巧