JS朗读文本
;(function(w){
var DEFIND_SRC = "http://tts.baidu.com/text2audio?";
var speech = function (options){
return new speech.fn.init(options);
}
speech.fn = speech.prototype = {
init : function(options){
if(options){
if(typeof options == "string") this.txt = options;
this.speek(true);
}
return this;
},
resrc : function(objs){
objs = objs || {};
var options = {
"lan" : objs.lan || "zh",
"ie" : objs.ie || "UTF-8",
"spd" : objs.spd || "4",
"text" : encodeURI(this.txt)
}
var src = DEFIND_SRC;
for(var name in options) src += name + "=" + options[name]+"&";
return src.substr(0 , src.length - 1);
},
speek : function(isspeek){
if(!this.txt) return this;
var aud = this.audioer = this.audioer || document.createElement("audio");
aud.duration
aud.src = this["resrc"]();
isspeek && aud.play();
return this;
}
}
speech.fn.init.prototype = speech.fn;
window.speech = speech;
}(window));