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调用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="" method="post">
<table align="center">
<tr>
<td><input type="text" id='val' placeholder='你要装换的文字'></td>
<td><input type="button" value="提交" onclick="fun()"></td>
</tr>
</table>
</form>
</body>
</html>
<script type="text/javascript">
function fun()
{
var val=document.getElementById("val").value;
var zhText = val;
zhText = encodeURI(zhText);
document.write("<audio autoplay=\"autoplay\">");
document.write("<source src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text="+ zhText +"\" type=\"audio/mpeg\">");
document.write("<embed height=\"0\" width=\"0\" src=\"http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=2&text="+ zhText +"\">");
document.write("</audio>");
}
</script>
本文介绍了如何使用百度的文字转语音(TTS)接口将文本转换为语音,并提供了通过URL直接访问及使用JavaScript进行调用的方法。用户可以调整语言、语速等参数。
4358

被折叠的 条评论
为什么被折叠?



