竹磬网-邵珠庆の日记 生命只有一次,你可以用它来做些更多伟大的事情–Make the world a little better and easier

205月/170

百度文字转语音免费接口使用实例

1、接口

http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text=你要转换的文字

上述接口的url,在浏览器上直接打开,即可听到文字转换后的语音

 

lan=zh:语言是中文,如果改为lan=en,则语言是英文。

ie=UTF-8文字格式。

spd=2:语速,可以是1-9的数字,数字越大,语速越快。

text=**:这个就是你要转换的文字

2、js调用

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6. </head>
  7. <body>
  8.     <form action="" method="post">
  9.         <table align="center">
  10.             <tr>
  11.                 <td><input type="text" id='val' placeholder='你要装换的文字'></td>
  12.                 <td><input type="button" value="提交" onclick="fun()"></td>
  13.             </tr>
  14.         </table>
  15.     </form>
  16. </body>
  17. </html>
  18. <script type="text/javascript">
  19. function fun()
  20. {
  21.     var val=document.getElementById("val").value;
  22.     var zhText = val;
  23.     zhText = encodeURI(zhText);
  24.     document.write("<audio autoplay=\"autoplay\">");
  25.     document.write("<source src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text="+ zhText +"\" type=\"audio/mpeg\">");
  26.     document.write("<embed height=\"0\" width=\"0\" src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text="+ zhText +"\">");
  27.     document.write("</audio>");
  28. }
  29. </script>

 

邵珠庆推荐文章

博文加载中...

喜欢这个文章吗?

考虑订阅我们的RSS Feed吧!

发布在 邵珠庆

评论 (0) 引用 (0)

还没有评论.


Leave a comment

*

引用被禁用.