百度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>
posted @ 2020-06-08 23:29  HelloBytes  阅读(591)  评论(1)    收藏  举报