javascript Deferred和递归次数限制实例
来源: 阅读:906 次 日期:2014-11-03 14:51:10
温馨提示: 小编为您整理了“javascript Deferred和递归次数限制实例”,方便广大网友查阅!

你知道Deferred和递归次数限制吗?下面有个不错的实例,大家可以看看

function runAsyncTTS(text,speecher,audiopath) {

var def = jQuery.Deferred();

var args = {"SynthText": text, "VoiceSpeecher": speecher, "WordSpeed": "3", "UseCSSML": "0", "AudioPath": audiopath};

tts.asyncTTS(JSON.stringify(args),function(err,result) {

def.resolve(result);

});

return def.promise();

}

function textToSpeechBat(metaJson, speecher, audioPath) {

var def = $.Deferred();

var result = {originalWords:"", resultJsonArr:[]};

var jsons="";

for(var index=0;index < metaJson.words.length;index++) {

var audioName = metaJson.words[index]['audio'];

audioName = audioName.replace('.mp3','');

var audioFile = audioPath +"/" + audioName + '.wav';

var args = '{"SynthText": "'+metaJson.words[index]['word']+'", "VoiceSpeecher": "'+speecher+'", "WordSpeed": "3", "UseCSSML": "0", "AudioPath": "'+audioFile+'"}';

jsons += args + "|";

}

jsons = jsons.substr(0,jsons.length-1);

tts.asyncTTSBat(jsons,function(err,ret) {

result['resultJsonArr'] = ret.split('|');

def.resolve(result);

});

return def.promise();

}

function textToSpeechWithTryTimes(metaJson, speecher, audioPath,times) {

var def = $.Deferred();

var ttsRet = null;

var ttsCallBack = function(index) {

if(index < times) {

textToSpeechBat(metaJson,speecher,audioPath).done(function (ret) {

console.log("textToSpeechWithTryTimes:"+JSON.stringify(ret));

ttsRet = ret;

var resultJsonArr = ret.resultJsonArr;

var audioFlag = true;

for(var i=0;i<resultJsonArr.length;i++) {

if(resultJsonArr[i] == "") {

audioFlag = false;

break;

}

var retObj = JSON.parse(resultJsonArr[i]);

console.log(retObj['audioFlag']);

if(retObj['audioFlag'] == 'false' || retObj['result']=="") {

audioFlag = false;

break;

}

}

console.log(audioFlag);

if(audioFlag == false) {

console.log("textToSpeechWithTryTimes Fail, try again!");

ttsCallBack(++index);

}else {

console.log("textToSpeechWithTryTimes succeed,return");

def.resolve(ret);

}

});

}

if(index == times) {

console.log("textToSpeechWithTryTimes timesover,return");

def.resolve(ttsRet);

}

};

ttsCallBack(0);

return def.promise();

}

更多信息请查看IT技术专栏

更多信息请查看脚本栏目
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!

2025国考·省考课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map