js实现语音播报功能
想让页面能说话?很简单的哟~
定义语音播报的函数
function speckText(str){
//var request= new URLRequest();
var url = "http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + encodeURI(str); // baidu
//url = "http://translate.google.cn/translate_tts?ie=UTF-8&tl=zh-CN&total=1&idx=0&textlen=19&prev=input&q=" + encodeURI(str); // google
//request.url = encodeURI(url);
// request.contentType = "audio/mp3"; // for baidu
//request.contentType = "audio/mpeg"; // for google
var n = new Audio(url);
n.src = url;
n.play();
// $("...").play();
// var sound = new Sound(request);
// sound.play();
}
OK ,str为你传入的参数,即你要播报的内容
下面哪里需要哪里调用就好了~