<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>语音test</title> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script> function sound(str){ var obj=document.createElement("embed"); obj.style.width=0; obj.style.height=0; obj.src="http://tsn.baidu.com/text2audio?lan=zh&cuid=80-9B-20-57-81-D4&ctp=1&vol=9&tok=24.c76ae180d333a2697d3d7b6ea74ddc1f.2592000.1494832440.282335-5861601&tex="+str; obj.loop=0; document.body.appendChild(obj); } $(function(){ sound("语音测试!"); $("#btn").click(function(){ sound($("#tt").val()); }); }); </script> </head> <body> <h1>语音测试</h1> <input id="tt" value="这是测试的内容"/> <button id="btn">播放文本内容</button> </body> </html>