From 43ae2bd1fb0730bc190e8c7924a03a9f039c57f9 Mon Sep 17 00:00:00 2001 From: fan Date: Wed, 20 Jul 2022 17:20:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AD=E9=9F=B3=E5=90=88=E6=88=90=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/baidu_tts_cors.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/utils/baidu_tts_cors.js b/src/utils/baidu_tts_cors.js index cc99d90a0..adf268445 100644 --- a/src/utils/baidu_tts_cors.js +++ b/src/utils/baidu_tts_cors.js @@ -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) {