<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>语音合成提示语音</title>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<button id="target">点我试试</button>
<script>
function mPlay(str) {
    var url = "http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + encodeURI(str);
    var n = new Audio(url);
    console.log(url);
    n.src = url;
    n.play();
}
$("#target").click(function() {
    mPlay("大家好,我是老王,最近学习的怎么样!谢谢!大家关注我的博客:有什么要求,建议 大家可以留言");
})
</script>
<hr>
注意:
TTS简介
TTS是Text To Speech的缩写,即“从文本到语音”
在audio的子标签source中设置src,具体内容为:src="http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=8&text="+content (content是要朗读的内容)
参数:{
lan:语言,
ie:编码,
spd:语速(1-9),
text:要朗读的内容
}
</body>
</html>

与御风痕博客园,程序员博客园地的首选!
御风痕博客园 » 将文本转成语音播报

发表评论