JavaScript deferred and recursive number limits

Source: Internet
Author: User

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,aud                    Iopath). 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 (); }

JavaScript deferred and recursive number limits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.