百度API在线发音的小Demo
尝试了一下百度的API 在线发音,代码如下:
<body>
<div id="wordDiv">
<audio src="http://tts.baidu.com/text2audio?lan=en&ie=UTF-8&text=hello" id="word">hi</audio>
<button id="fanyi">点我发音</button>
<!-- <audio src="http://tts.baidu.com/text2audio?lan=en&ie=UTF-8&text=hello">点我发声</audio> -->
</div>
<script>
// voiceText("王炸");
var word = document.getElementById('word');
var fanyi = document.getElementById('fanyi');
var wd=word.textContent;
fanyi.onmousedown=function(){
word.src = "http://tts.baidu.com/text2audio?lan=en&ie=UTF-8&text="+wd;
word.autoplay='autoplay';
}
</script>
</body>
---------------------------作者:HelloBytes
关于作者: JavaEE小新人,请多多赐教!
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。

浙公网安备 33010602011771号