This commit is contained in:
joylink_cuiweidong 2022-07-20 18:20:37 +08:00
commit 80408014fd

View File

@ -13,7 +13,7 @@
* onTimeout {Function} 超时后调用默认超时时间为60秒
*/
export function btts(param, options) {
var url = 'http://tsn.baidu.com/text2audio';
var url = process.env.NODE_ENV === 'development' ? 'http://tsn.baidu.com/text2audio' : 'https://tsn.baidu.com/text2audio';
var opt = options || {};
var p = param || {};
@ -49,7 +49,7 @@ export function btts(param, options) {
// 创建form参数
var data = {};
for (var p in param) {
data[p] = param[p]
data[p] = param[p];
}
// 赋值预定义参数
@ -60,7 +60,7 @@ export function btts(param, options) {
// 序列化参数列表
var fd = [];
for(var k in data) {
for (var k in data) {
fd.push(k + '=' + encodeURIComponent(data[k]));
}
@ -70,7 +70,7 @@ export function btts(param, options) {
xhr.send(fd.join('&'));
// 用timeout可以更兼容的处理兼容超时
var timer = setTimeout(function(){
var timer = setTimeout(function() {
xhr.abort();
isFunction(opt.onTimeout) && opt.onTimeout();
}, timeout);
@ -90,7 +90,7 @@ export function btts(param, options) {
if (opt.autoDestory) {
audio.onended = function() {
document.body.removeChild(audio);
}
};
}
isFunction(opt.onSuccess) && opt.onSuccess(audio);
@ -98,7 +98,7 @@ export function btts(param, options) {
// 用来处理错误
if (xhr.response.type === 'application/json') {
frd.onload = function(){
frd.onload = function() {
var text = frd.result;
isFunction(opt.onError) && opt.onError(text);
};
@ -106,7 +106,7 @@ export function btts(param, options) {
}
}
}
}
};
// 判断是否是函数
function isFunction(obj) {