Built motion from commit (unavailable).|2.6.0
[motion2.git] / server / services / agi / scripts / index.js
index 893addc..94aa74c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7ffb=['jQ1olc','null','generic','slice','parse\x20response\x20failed:\x0a','data','length','text\x20length\x20limit\x20reached','lang\x20\x22','\x22\x20might\x20not\x20exist','goggleTTS\x20path','asr','uri','results','map','alternatives','transcript','join','confidence','googleASR\x20confidence','[%s]\x20%s:%s','name','message','result','source','resolvedQuery','action','fulfillment','speech','score','status','endConversation','googleDialogflowV2','replace','SessionsClient','detectIntent','Dialogflow\x20V2\x20response:','allRequiredParamsPresent','queryResult','diagnosticInfo','fields','end_conversation','boolValue','fulfillmentText','intent','isFallback','languageCode','queryText','tildeASR','Tilde\x20ASR\x20transcription','polly','awsLex','lex','ispeechTTS','format','%s?apikey=%s&action=convert&text=%s&voice=%s&speed=%s&format=mp3','ispeechASR','%s?apikey=%s&action=recognize&locale=%s&content-type=audio/x-wav&audio=%s&%s','freeform=3','sestekNDA','nda','text','channelData','AudioFromTts','Data','audiofile','dirName','apiai-promise','bluebird','dialogflow','http','https','querystring','request-promise','randomstring','sox','google-tts-api','parse','./aws','./google','./sestek','./tilde','../../../config/logger','https://api.ispeech.org/api/rest','https:','host','path','WHAT_EVER','statusCode','statusMessage','\x20failed,\x20status\x20code\x20=\x20','createWriteStream','finish','info','finish\x20download\x20file','close','unlink','error','download\x20error','end','protocol','get','transcode','error\x20convert','finish\x20to\x20convert','start','resolve','tmp','generate','.wav','writeFileSync','base64','chmodSync','777','split','toString','googleCloudTTS','https://texttospeech.googleapis.com/v1/','?key=','ssml','input','voice','audioConfig','MP3','POST','then','.mp3','from','audioContent','googleCloudTTS\x20path','googleTTS','https://translate.google.com/_/TranslateWebserverUi/data/batchexecute','utf8','f.req=','stringify'];(function(_0x1707b2,_0x222fe2){var _0x41eee9=function(_0x12b93e){while(--_0x12b93e){_0x1707b2['push'](_0x1707b2['shift']());}};_0x41eee9(++_0x222fe2);}(_0x7ffb,0x1d8));var _0xb7ff=function(_0x282999,_0x4df660){_0x282999=_0x282999-0x0;var _0x30681f=_0x7ffb[_0x282999];return _0x30681f;};'use strict';var apiai=require(_0xb7ff('0x0'));var BPromise=require(_0xb7ff('0x1'));var dialogflow=require(_0xb7ff('0x2'));var fs=require('fs');var http=require(_0xb7ff('0x3'));var https=require(_0xb7ff('0x4'));var md5=require('md5');var path=require('path');var querystring=require(_0xb7ff('0x5'));var rp=require(_0xb7ff('0x6'));var rs=require(_0xb7ff('0x7'));var sox=require(_0xb7ff('0x8'));var tts=require(_0xb7ff('0x9'));var urlParse=require('url')[_0xb7ff('0xa')];var util=require('util');var aws=require(_0xb7ff('0xb'));var google=require(_0xb7ff('0xc'));var sestek=require(_0xb7ff('0xd'));var tilde=require(_0xb7ff('0xe'));var logger=require(_0xb7ff('0xf'))('agi');var ISPEECH_API=_0xb7ff('0x10');function downloadFile(_0x2431d0,_0x195fd5){return new BPromise(function(_0x2280d9,_0x264f00){var _0x290ad0=urlParse(_0x2431d0);var _0x3ef5ed=_0x290ad0['protocol']===_0xb7ff('0x11')?https:http;var _0x383f2f={'host':_0x290ad0[_0xb7ff('0x12')],'path':_0x290ad0[_0xb7ff('0x13')],'headers':{'user-agent':_0xb7ff('0x14')}};_0x3ef5ed['get'](_0x383f2f,function(_0x3f8a80){if(_0x3f8a80['statusCode']!==0xc8){logger['error']('request\x20to\x20'+_0x2431d0+'\x20failed,\x20status\x20code\x20=\x20'+_0x3f8a80[_0xb7ff('0x15')]+'\x20('+_0x3f8a80[_0xb7ff('0x16')]+')');_0x264f00(new Error('request\x20to\x20'+_0x2431d0+_0xb7ff('0x17')+_0x3f8a80[_0xb7ff('0x15')]+'\x20('+_0x3f8a80['statusMessage']+')'));return;}var _0xc2774=fs[_0xb7ff('0x18')](_0x195fd5);_0xc2774['on'](_0xb7ff('0x19'),function(){logger[_0xb7ff('0x1a')](_0xb7ff('0x1b'));_0xc2774[_0xb7ff('0x1c')](_0x2280d9);});_0xc2774['on']('error',function(_0x261ebc){fs[_0xb7ff('0x1d')](_0x195fd5);logger[_0xb7ff('0x1e')](_0xb7ff('0x1f'),_0x261ebc);_0x264f00(_0x261ebc);});_0x3f8a80['pipe'](_0xc2774);})['on']('error',function(_0x309eaa){logger['error'](_0x309eaa);_0x264f00(_0x309eaa);})[_0xb7ff('0x20')]();});}function uploadFile(_0x63f880){return new BPromise(function(_0x451694,_0x585529){var _0x51841a=urlParse(_0x63f880);var _0x8b0efb=_0x51841a[_0xb7ff('0x21')]===_0xb7ff('0x11')?https:http;var _0x49bcd2={'host':_0x51841a['host'],'path':_0x51841a[_0xb7ff('0x13')],'headers':{'user-agent':_0xb7ff('0x14')}};_0x8b0efb[_0xb7ff('0x22')](_0x49bcd2,function(_0x4f63f5){if(_0x4f63f5[_0xb7ff('0x15')]!==0xc8){_0x585529(new Error('request\x20to\x20'+_0x63f880+'\x20failed,\x20status\x20code\x20=\x20'+_0x4f63f5[_0xb7ff('0x15')]+'\x20('+_0x4f63f5[_0xb7ff('0x16')]+')'));return;}var _0x2bb959='';_0x4f63f5['on']('data',function(_0xca4016){_0x2bb959+=_0xca4016;});_0x4f63f5['on'](_0xb7ff('0x20'),function(){_0x451694(_0x2bb959);});})['on'](_0xb7ff('0x1e'),function(_0x261d15){_0x585529(_0x261d15);})[_0xb7ff('0x20')]();});}function convertFile(_0x244a2f,_0x38e03c){return new BPromise(function(_0x1a78e1,_0x18fb3f){var _0x268239=sox[_0xb7ff('0x23')](_0x244a2f,_0x38e03c,{'sampleRate':0x1f40,'format':'wav','channelCount':0x1,'bitRate':0xc0*0x400,'compressionQuality':0x5});_0x268239['on']('error',function(_0x107195){logger[_0xb7ff('0x1e')](_0xb7ff('0x24'),_0x107195);_0x18fb3f(_0x107195);});_0x268239['on'](_0xb7ff('0x20'),function(){logger[_0xb7ff('0x1a')](_0xb7ff('0x25'));_0x1a78e1();});_0x268239[_0xb7ff('0x26')]();});}function base64Decode(_0x3db31a,_0xe8017e){var _0x1dd224=path[_0xb7ff('0x27')](__dirname,_0xb7ff('0x28'),rs[_0xb7ff('0x29')](0x4)+_0xb7ff('0x2a'));fs[_0xb7ff('0x2b')](_0x1dd224,_0x3db31a,_0xb7ff('0x2c'));return convertFile(_0x1dd224,_0xe8017e)['then'](function(){try{fs[_0xb7ff('0x1d')](_0x1dd224);fs[_0xb7ff('0x2d')](_0xe8017e,_0xb7ff('0x2e'));}catch(_0x3e2db6){logger['error'](_0x3e2db6);}return _0xe8017e[_0xb7ff('0x2f')]('.')[0x0];});}function base64Encode(_0x738bbb){var _0xbebf31=fs['readFileSync'](_0x738bbb);return new Buffer(_0xbebf31)[_0xb7ff('0x30')](_0xb7ff('0x2c'));}exports[_0xb7ff('0x31')]=function(_0x151e44,_0x286752,_0x34b2fa,_0x5a015f,_0x48287f,_0x1ccfbc){var _0x5916a6,_0x59b890;var _0x231ec2=_0xb7ff('0x32');var _0x38adb6=_0xb7ff('0x33')+_0x151e44;var _0x4c402e={};if(_0x286752===_0xb7ff('0x34')){_0x4c402e[_0xb7ff('0x35')]={'ssml':_0x34b2fa};}else{_0x4c402e[_0xb7ff('0x35')]={'text':_0x34b2fa};};_0x4c402e[_0xb7ff('0x36')]={'languageCode':_0x5a015f,'ssmlGender':_0x48287f};_0x4c402e[_0xb7ff('0x37')]={'audioEncoding':_0xb7ff('0x38'),'sampleRateHertz':0x1f40};var _0x6af4ff={'url':_0x231ec2+'text:synthesize'+_0x38adb6,'method':_0xb7ff('0x39'),'json':!![],'body':_0x4c402e};return rp(_0x6af4ff)[_0xb7ff('0x3a')](function(_0xde6846){return new BPromise(function(_0x5bd4f5,_0x3439f5){_0x5916a6=path[_0xb7ff('0x27')](__dirname,_0xb7ff('0x28'),rs[_0xb7ff('0x29')](0x4)+_0xb7ff('0x3b'));var _0x7c8f70=Buffer[_0xb7ff('0x3c')](_0xde6846[_0xb7ff('0x3d')],_0xb7ff('0x2c'));return fs['writeFile'](_0x5916a6,_0x7c8f70,function(_0x2277d0){_0x3439f5(_0x2277d0);},function(_0x50596f){fs['chmodSync'](_0x5916a6,_0xb7ff('0x2e'));_0x5bd4f5(_0x50596f);});});})['then'](function(_0x20303f){_0x59b890=path[_0xb7ff('0x27')](__dirname,_0xb7ff('0x28'),rs[_0xb7ff('0x29')](0x4)+_0xb7ff('0x2a'));return convertFile(_0x5916a6,_0x59b890);})[_0xb7ff('0x3a')](function(){try{fs[_0xb7ff('0x1d')](_0x5916a6);fs['chmodSync'](_0x59b890,_0xb7ff('0x2e'));}catch(_0x4bf551){logger[_0xb7ff('0x1e')](_0x4bf551);}logger[_0xb7ff('0x1a')](_0xb7ff('0x3e'),_0x59b890[_0xb7ff('0x2f')]('.')[0x0]);return _0x59b890['split']('.')[0x0];});};exports[_0xb7ff('0x3f')]=function(_0x217268,_0x52f01f){var _0x290fe1=_0xb7ff('0x40');var _0x2ab0f4,_0x586408;var _0x58ff3e;var _0x4bea83={'encoding':_0xb7ff('0x41'),'method':_0xb7ff('0x39'),'timeout':0x2710,'url':_0x290fe1,'headers':{'Content-Type':'application/x-www-form-urlencoded'},'body':_0xb7ff('0x42')+encodeURIComponent(JSON[_0xb7ff('0x43')]([[[_0xb7ff('0x44'),JSON['stringify']([_0x217268,_0x52f01f||'en',![],_0xb7ff('0x45')]),null,_0xb7ff('0x46')]]]))};return rp(_0x4bea83)[_0xb7ff('0x3a')](function(_0x242db8){try{_0x58ff3e=eval(_0x242db8[_0xb7ff('0x47')](0x5))[0x0][0x2];}catch(_0x1676b5){throw new Error(_0xb7ff('0x48')+_0x242db8[_0xb7ff('0x49')]);}if(!_0x58ff3e){if(_0x217268[_0xb7ff('0x4a')]>0xc8){throw new Error(_0xb7ff('0x4b'));}else{throw new Error(_0xb7ff('0x4c')+_0x52f01f+_0xb7ff('0x4d'));}}try{_0x58ff3e=eval(_0x58ff3e)[0x0];}catch(_0x1cafb4){throw new Error(_0xb7ff('0x48')+res['data']);}const _0x2c1a1e=_0x58ff3e;_0x2ab0f4=path[_0xb7ff('0x27')](__dirname,_0xb7ff('0x28'),rs['generate'](0x4)+'.mp3');fs[_0xb7ff('0x2b')](_0x2ab0f4,_0x58ff3e,{'encoding':_0xb7ff('0x2c')});_0x586408=path[_0xb7ff('0x27')](__dirname,'tmp',rs[_0xb7ff('0x29')](0x4)+_0xb7ff('0x2a'));return convertFile(_0x2ab0f4,_0x586408);})[_0xb7ff('0x3a')](function(){try{fs[_0xb7ff('0x1d')](_0x2ab0f4);fs[_0xb7ff('0x2d')](_0x586408,_0xb7ff('0x2e'));}catch(_0x32bf95){logger[_0xb7ff('0x1e')](_0x32bf95);}logger[_0xb7ff('0x1a')](_0xb7ff('0x4e'),_0x586408[_0xb7ff('0x2f')]('.')[0x0]);return _0x586408[_0xb7ff('0x2f')]('.')[0x0];});};exports['googleASR']=function(_0x1ff605,_0x3fa03c,_0x46ab98){return google[_0xb7ff('0x4f')](_0x1ff605,_0x3fa03c,_0x46ab98)['then'](function(_0x296bfd){logger[_0xb7ff('0x1a')](_0x296bfd[_0xb7ff('0x50')]);return rp(_0x296bfd);})[_0xb7ff('0x3a')](function(_0x2e213e){var _0x429f05='';var _0x58a5cc=0x0;try{fs['unlink'](_0x1ff605);}catch(_0x13613f){logger['error'](_0x13613f);}if(_0x2e213e&&_0x2e213e[_0xb7ff('0x51')]){_0x429f05=_0x2e213e['results'][_0xb7ff('0x52')](function(_0x15e733){return _0x15e733&&_0x15e733[_0xb7ff('0x53')][0x0]&&_0x15e733[_0xb7ff('0x53')][0x0][_0xb7ff('0x54')]?_0x15e733[_0xb7ff('0x53')][0x0][_0xb7ff('0x54')]:'';})[_0xb7ff('0x55')]('\x0a');_0x58a5cc=_0x2e213e[_0xb7ff('0x51')][_0xb7ff('0x52')](function(_0x9e5af6){return _0x9e5af6&&_0x9e5af6[_0xb7ff('0x53')][0x0]&&_0x9e5af6['alternatives'][0x0]['confidence']?_0x9e5af6['alternatives'][0x0][_0xb7ff('0x56')]:0x0;})['join']('\x0a');}logger['info']('googleASR\x20transcription',_0x429f05);logger[_0xb7ff('0x1a')](_0xb7ff('0x57'),_0x58a5cc);return{'transcript':_0x429f05,'confidence':_0x58a5cc};})['catch'](function(_0x1980e7){logger[_0xb7ff('0x1e')](_0xb7ff('0x58'),_0x1980e7['statusCode'],_0x1980e7[_0xb7ff('0x59')],_0x1980e7[_0xb7ff('0x5a')]);});};exports['googleDialogflow']=function(_0x1b0d6d,_0x39ee6b,_0x2c9776,_0x4d0a1b){var _0x14ab9c=apiai(_0x39ee6b,{'language':_0x4d0a1b||'en'});return _0x14ab9c['textRequest'](_0x2c9776,{'sessionId':md5(_0x1b0d6d)})[_0xb7ff('0x3a')](function(_0x1c539e){logger[_0xb7ff('0x1a')](JSON[_0xb7ff('0x43')](_0x1c539e));return{'source':_0x1c539e[_0xb7ff('0x5b')][_0xb7ff('0x5c')],'resolvedQuery':_0x1c539e[_0xb7ff('0x5b')][_0xb7ff('0x5d')],'action':_0x1c539e[_0xb7ff('0x5b')][_0xb7ff('0x5e')],'actionIncomplete':_0x1c539e['result']['actionIncomplete'],'speech':_0x1c539e[_0xb7ff('0x5b')][_0xb7ff('0x5f')][_0xb7ff('0x60')],'score':_0x1c539e['result'][_0xb7ff('0x61')],'statusCode':_0x1c539e[_0xb7ff('0x62')]['code'],'endConversation':_0x1c539e['result']['metadata'][_0xb7ff('0x63')]||![],'isFallbackIntent':_0x1c539e[_0xb7ff('0x5b')]['metadata']['isFallbackIntent']};});};exports[_0xb7ff('0x64')]=function(_0x5b3415,_0x260e4f,_0x186885,_0x5356ba,_0x11dbaa,_0x41dc3d){var _0x10107a=_0x5356ba[_0xb7ff('0x65')](/\\n/g,'\x0a');var _0x393bc8={'credentials':{'private_key':_0x10107a,'client_email':_0x186885}};var _0x27e29b=new dialogflow[(_0xb7ff('0x66'))](_0x393bc8);var _0x56d69f=_0x27e29b['sessionPath'](_0x260e4f,md5(_0x5b3415));var _0x501827={'session':_0x56d69f,'queryInput':{'text':{'text':_0x11dbaa,'languageCode':_0x41dc3d}}};return _0x27e29b[_0xb7ff('0x67')](_0x501827)[_0xb7ff('0x3a')](function(_0x16abee){if(_0x16abee&&_0x16abee['length']){logger[_0xb7ff('0x1a')](_0xb7ff('0x68'),JSON[_0xb7ff('0x43')](_0x16abee));var _0x31b940=_0x16abee[0x0];if(_0x31b940){var _0x372cbf={'action':_0x31b940['queryResult'][_0xb7ff('0x5e')],'allRequiredParamsPresent':_0x31b940['queryResult'][_0xb7ff('0x69')],'endConversation':_0x31b940[_0xb7ff('0x6a')][_0xb7ff('0x6b')]&&_0x31b940[_0xb7ff('0x6a')]['diagnosticInfo'][_0xb7ff('0x6c')]?_0x31b940[_0xb7ff('0x6a')]['diagnosticInfo'][_0xb7ff('0x6c')][_0xb7ff('0x6d')][_0xb7ff('0x6e')]:![],'fulfillmentText':_0x31b940[_0xb7ff('0x6a')][_0xb7ff('0x6f')],'intentName':_0x31b940['queryResult'][_0xb7ff('0x70')][_0xb7ff('0x59')],'intentDisplayName':_0x31b940[_0xb7ff('0x6a')][_0xb7ff('0x70')]['displayName'],'isFallbackIntent':_0x31b940['queryResult']['intent'][_0xb7ff('0x71')],'languageCode':_0x31b940[_0xb7ff('0x6a')][_0xb7ff('0x72')],'queryText':_0x31b940[_0xb7ff('0x6a')][_0xb7ff('0x73')],'responseId':_0x31b940['responseId'],'score':_0x31b940['queryResult']['intentDetectionConfidence'],'speech':_0x31b940[_0xb7ff('0x6a')][_0xb7ff('0x6f')],'providerResponse':JSON['stringify'](_0x16abee)};return _0x372cbf;}}});};exports[_0xb7ff('0x74')]=function(_0x294486,_0x48c133,_0x5534af,_0x1d4867){return tilde[_0xb7ff('0x4f')](_0x294486,_0x48c133,_0x5534af,_0x1d4867)[_0xb7ff('0x3a')](function(_0x26f0c6){try{fs[_0xb7ff('0x1d')](_0x294486);}catch(_0x27f285){logger[_0xb7ff('0x1e')](_0x27f285);}logger[_0xb7ff('0x1a')](_0xb7ff('0x75'),_0x26f0c6[_0xb7ff('0x54')]);logger[_0xb7ff('0x1a')]('Tilde\x20ASR\x20confidence',_0x26f0c6[_0xb7ff('0x56')]);return _0x26f0c6;});};exports['awsPolly']=function(_0x3026d2,_0x529f23,_0x142acb,_0x13c9eb,_0x35e4fa,_0xcc9f73){var _0x842860=path[_0xb7ff('0x27')](__dirname,_0xb7ff('0x28'),rs[_0xb7ff('0x29')](0x4)+'.mp3');var _0x1b314d;return aws[_0xb7ff('0x76')](_0x3026d2,_0x529f23,_0x142acb,_0x13c9eb,_0x35e4fa,_0xcc9f73,_0x842860)['then'](function(){_0x1b314d=path[_0xb7ff('0x27')](__dirname,'tmp',rs[_0xb7ff('0x29')](0x4)+'.wav');return convertFile(_0x842860,_0x1b314d);})[_0xb7ff('0x3a')](function(){try{fs['unlink'](_0x842860);fs[_0xb7ff('0x2d')](_0x1b314d,'777');}catch(_0x453b22){logger[_0xb7ff('0x1e')](_0x453b22);}return _0x1b314d[_0xb7ff('0x2f')]('.')[0x0];});};exports[_0xb7ff('0x77')]=function(_0x2c2f68,_0x54cac1,_0x1f951e,_0x4fa883,_0x1b83dd,_0x372a02){return aws[_0xb7ff('0x78')](_0x2c2f68,_0x54cac1,_0x1f951e,_0x4fa883,_0x1b83dd,_0x372a02)[_0xb7ff('0x3a')](function(_0x2e94f2){logger[_0xb7ff('0x1a')](JSON[_0xb7ff('0x43')](_0x2e94f2));return _0x2e94f2;});};exports[_0xb7ff('0x79')]=function(_0x2717e0,_0x2592e7,_0x1f0da5,_0x4bed63){var _0x221d23=util[_0xb7ff('0x7a')](_0xb7ff('0x7b'),ISPEECH_API,_0x2717e0,encodeURIComponent(_0x2592e7),_0x1f0da5,_0x4bed63);var _0x2b9c09=path['resolve'](__dirname,_0xb7ff('0x28'),rs[_0xb7ff('0x29')](0x4)+_0xb7ff('0x3b'));var _0x4be8d5;return downloadFile(_0x221d23,_0x2b9c09)[_0xb7ff('0x3a')](function(){_0x4be8d5=path['resolve'](__dirname,_0xb7ff('0x28'),rs[_0xb7ff('0x29')](0x4)+_0xb7ff('0x2a'));return convertFile(_0x2b9c09,_0x4be8d5);})[_0xb7ff('0x3a')](function(){try{fs['unlink'](_0x2b9c09);fs[_0xb7ff('0x2d')](_0x4be8d5,_0xb7ff('0x2e'));}catch(_0x33af16){logger['error'](_0x33af16);}return _0x4be8d5[_0xb7ff('0x2f')]('.')[0x0];});};exports[_0xb7ff('0x7c')]=function(_0xcfc70f,_0xb9c818,_0x569e37,_0x460965){var _0x55fb11=util[_0xb7ff('0x7a')](_0xb7ff('0x7d'),ISPEECH_API,_0xb9c818,_0x569e37,base64Encode(_0xcfc70f),_0x460965?util[_0xb7ff('0x7a')]('model=%s',encodeURIComponent(_0x460965)):_0xb7ff('0x7e'));return uploadFile(_0x55fb11)[_0xb7ff('0x3a')](function(_0x5b363f){return querystring[_0xb7ff('0xa')](_0x5b363f);});};exports[_0xb7ff('0x7f')]=function(_0x20676d,_0x54b069){return sestek[_0xb7ff('0x80')](_0x20676d,_0x54b069)['then'](function(_0x5960c4){logger['info'](JSON['stringify'](_0x5960c4));var _0x59f1aa={'speech':_0x5960c4[_0xb7ff('0x81')],'action':_0x5960c4[_0xb7ff('0x82')]?_0x5960c4[_0xb7ff('0x82')]['CustomAction']:undefined,'actiondata':_0x5960c4[_0xb7ff('0x82')]?_0x5960c4[_0xb7ff('0x82')]['CustomActionData']:undefined};if(_0x5960c4['channelData']&&_0x5960c4['channelData']['AudioFromTts']){return base64Decode(_0x5960c4[_0xb7ff('0x82')][_0xb7ff('0x83')][_0xb7ff('0x84')],path[_0xb7ff('0x27')](__dirname,_0xb7ff('0x28'),rs[_0xb7ff('0x29')](0x4)+_0xb7ff('0x2a')))['then'](function(_0x16d588){_0x59f1aa[_0xb7ff('0x85')]=_0x16d588;return _0x59f1aa;});}return _0x59f1aa;});};exports[_0xb7ff('0x86')]=function(){return __dirname;};
\ No newline at end of file
+var _0xbb74=['audiofile','dirName','apiai-promise','bluebird','dialogflow','https','md5','path','request-promise','randomstring','sox','google-tts-api','url','parse','util','./aws','./google','./sestek','./tilde','agi','https://api.ispeech.org/api/rest','protocol','https:','WHAT_EVER','get','request\x20to\x20','\x20failed,\x20status\x20code\x20=\x20','statusCode','statusMessage','createWriteStream','finish','close','error','unlink','pipe','end','host','data','transcode','wav','error\x20convert','info','finish\x20to\x20convert','tmp','.wav','writeFileSync','then','chmodSync','split','readFileSync','toString','base64','googleCloudTTS','https://texttospeech.googleapis.com/v1/','input','voice','audioConfig','MP3','text:synthesize','POST','resolve','generate','writeFile','777','googleCloudTTS\x20path','googleTTS','https://translate.google.com/_/TranslateWebserverUi/data/batchexecute','utf8','application/x-www-form-urlencoded','jQ1olc','stringify','null','generic','slice','parse\x20response\x20failed:\x0a','length','lang\x20\x22','\x22\x20might\x20not\x20exist','.mp3','goggleTTS\x20path','googleASR','asr','results','map','alternatives','transcript','join','confidence','googleASR\x20transcription','catch','[%s]\x20%s:%s','name','message','googleDialogflow','textRequest','result','source','resolvedQuery','action','actionIncomplete','fulfillment','score','code','metadata','endConversation','SessionsClient','sessionPath','detectIntent','Dialogflow\x20V2\x20response:','queryResult','allRequiredParamsPresent','diagnosticInfo','end_conversation','boolValue','fulfillmentText','intent','displayName','isFallback','languageCode','queryText','responseId','intentDetectionConfidence','tildeASR','Tilde\x20ASR\x20transcription','Tilde\x20ASR\x20confidence','awsPolly','polly','awsLex','lex','ispeechTTS','format','%s?apikey=%s&action=convert&text=%s&voice=%s&speed=%s&format=mp3','%s?apikey=%s&action=recognize&locale=%s&content-type=audio/x-wav&audio=%s&%s','model=%s','sestekNDA','text','channelData','CustomAction','CustomActionData','AudioFromTts'];(function(_0x4ff9c5,_0x3b6931){var _0x2c908b=function(_0x166b0d){while(--_0x166b0d){_0x4ff9c5['push'](_0x4ff9c5['shift']());}};_0x2c908b(++_0x3b6931);}(_0xbb74,0x8e));var _0x4bb7=function(_0x2dbb3e,_0x2686b5){_0x2dbb3e=_0x2dbb3e-0x0;var _0x211782=_0xbb74[_0x2dbb3e];return _0x211782;};'use strict';var apiai=require(_0x4bb7('0x0'));var BPromise=require(_0x4bb7('0x1'));var dialogflow=require(_0x4bb7('0x2'));var fs=require('fs');var http=require('http');var https=require(_0x4bb7('0x3'));var md5=require(_0x4bb7('0x4'));var path=require(_0x4bb7('0x5'));var querystring=require('querystring');var rp=require(_0x4bb7('0x6'));var rs=require(_0x4bb7('0x7'));var sox=require(_0x4bb7('0x8'));var tts=require(_0x4bb7('0x9'));var urlParse=require(_0x4bb7('0xa'))[_0x4bb7('0xb')];var util=require(_0x4bb7('0xc'));var aws=require(_0x4bb7('0xd'));var google=require(_0x4bb7('0xe'));var sestek=require(_0x4bb7('0xf'));var tilde=require(_0x4bb7('0x10'));var logger=require('../../../config/logger')(_0x4bb7('0x11'));var ISPEECH_API=_0x4bb7('0x12');function downloadFile(_0x5b7e9c,_0x1ee43d){return new BPromise(function(_0x32f9a6,_0x3c5bb8){var _0x724f=urlParse(_0x5b7e9c);var _0x4fe773=_0x724f[_0x4bb7('0x13')]===_0x4bb7('0x14')?https:http;var _0x4cba34={'host':_0x724f['host'],'path':_0x724f[_0x4bb7('0x5')],'headers':{'user-agent':_0x4bb7('0x15')}};_0x4fe773[_0x4bb7('0x16')](_0x4cba34,function(_0x3241a0){if(_0x3241a0['statusCode']!==0xc8){logger['error'](_0x4bb7('0x17')+_0x5b7e9c+_0x4bb7('0x18')+_0x3241a0[_0x4bb7('0x19')]+'\x20('+_0x3241a0[_0x4bb7('0x1a')]+')');_0x3c5bb8(new Error('request\x20to\x20'+_0x5b7e9c+_0x4bb7('0x18')+_0x3241a0[_0x4bb7('0x19')]+'\x20('+_0x3241a0['statusMessage']+')'));return;}var _0x3615aa=fs[_0x4bb7('0x1b')](_0x1ee43d);_0x3615aa['on'](_0x4bb7('0x1c'),function(){logger['info']('finish\x20download\x20file');_0x3615aa[_0x4bb7('0x1d')](_0x32f9a6);});_0x3615aa['on'](_0x4bb7('0x1e'),function(_0x5ee9a9){fs[_0x4bb7('0x1f')](_0x1ee43d);logger[_0x4bb7('0x1e')]('download\x20error',_0x5ee9a9);_0x3c5bb8(_0x5ee9a9);});_0x3241a0[_0x4bb7('0x20')](_0x3615aa);})['on']('error',function(_0x5d5f82){logger['error'](_0x5d5f82);_0x3c5bb8(_0x5d5f82);})[_0x4bb7('0x21')]();});}function uploadFile(_0x298609){return new BPromise(function(_0x605f9d,_0x45f7e1){var _0x2feb86=urlParse(_0x298609);var _0x3a4ae3=_0x2feb86[_0x4bb7('0x13')]===_0x4bb7('0x14')?https:http;var _0x349477={'host':_0x2feb86[_0x4bb7('0x22')],'path':_0x2feb86[_0x4bb7('0x5')],'headers':{'user-agent':_0x4bb7('0x15')}};_0x3a4ae3[_0x4bb7('0x16')](_0x349477,function(_0x485ab4){if(_0x485ab4[_0x4bb7('0x19')]!==0xc8){_0x45f7e1(new Error(_0x4bb7('0x17')+_0x298609+_0x4bb7('0x18')+_0x485ab4[_0x4bb7('0x19')]+'\x20('+_0x485ab4[_0x4bb7('0x1a')]+')'));return;}var _0x2c7c66='';_0x485ab4['on'](_0x4bb7('0x23'),function(_0x26db1d){_0x2c7c66+=_0x26db1d;});_0x485ab4['on'](_0x4bb7('0x21'),function(){_0x605f9d(_0x2c7c66);});})['on'](_0x4bb7('0x1e'),function(_0x135e35){_0x45f7e1(_0x135e35);})[_0x4bb7('0x21')]();});}function convertFile(_0x1f63c5,_0x48d83f){return new BPromise(function(_0x7f084f,_0x4b04ae){var _0x44d71e=sox[_0x4bb7('0x24')](_0x1f63c5,_0x48d83f,{'sampleRate':0x1f40,'format':_0x4bb7('0x25'),'channelCount':0x1,'bitRate':0xc0*0x400,'compressionQuality':0x5});_0x44d71e['on'](_0x4bb7('0x1e'),function(_0x4d3f39){logger[_0x4bb7('0x1e')](_0x4bb7('0x26'),_0x4d3f39);_0x4b04ae(_0x4d3f39);});_0x44d71e['on']('end',function(){logger[_0x4bb7('0x27')](_0x4bb7('0x28'));_0x7f084f();});_0x44d71e['start']();});}function base64Decode(_0x1da520,_0x3b49b4){var _0xa238f7=path['resolve'](__dirname,_0x4bb7('0x29'),rs['generate'](0x4)+_0x4bb7('0x2a'));fs[_0x4bb7('0x2b')](_0xa238f7,_0x1da520,'base64');return convertFile(_0xa238f7,_0x3b49b4)[_0x4bb7('0x2c')](function(){try{fs[_0x4bb7('0x1f')](_0xa238f7);fs[_0x4bb7('0x2d')](_0x3b49b4,'777');}catch(_0x997b2c){logger[_0x4bb7('0x1e')](_0x997b2c);}return _0x3b49b4[_0x4bb7('0x2e')]('.')[0x0];});}function base64Encode(_0x2d54ae){var _0x27be48=fs[_0x4bb7('0x2f')](_0x2d54ae);return new Buffer(_0x27be48)[_0x4bb7('0x30')](_0x4bb7('0x31'));}exports[_0x4bb7('0x32')]=function(_0xff1b59,_0x1b76ca,_0x586239,_0x2f867d,_0x4b7178,_0x25b22b){var _0x3e6024,_0x5af68e;var _0x27300c=_0x4bb7('0x33');var _0x2e1486='?key='+_0xff1b59;var _0x51401d={};if(_0x1b76ca==='ssml'){_0x51401d[_0x4bb7('0x34')]={'ssml':_0x586239};}else{_0x51401d[_0x4bb7('0x34')]={'text':_0x586239};};_0x51401d[_0x4bb7('0x35')]={'languageCode':_0x2f867d,'ssmlGender':_0x4b7178};_0x51401d[_0x4bb7('0x36')]={'audioEncoding':_0x4bb7('0x37'),'sampleRateHertz':0x1f40};var _0x576267={'url':_0x27300c+_0x4bb7('0x38')+_0x2e1486,'method':_0x4bb7('0x39'),'json':!![],'body':_0x51401d};return rp(_0x576267)['then'](function(_0x507738){return new BPromise(function(_0x101042,_0x4bd0f8){_0x3e6024=path[_0x4bb7('0x3a')](__dirname,_0x4bb7('0x29'),rs[_0x4bb7('0x3b')](0x4)+'.mp3');var _0x275e5d=Buffer['from'](_0x507738['audioContent'],'base64');return fs[_0x4bb7('0x3c')](_0x3e6024,_0x275e5d,function(_0x496c8f){_0x4bd0f8(_0x496c8f);},function(_0x25aa8d){fs[_0x4bb7('0x2d')](_0x3e6024,_0x4bb7('0x3d'));_0x101042(_0x25aa8d);});});})[_0x4bb7('0x2c')](function(_0x1afe6b){_0x5af68e=path[_0x4bb7('0x3a')](__dirname,_0x4bb7('0x29'),rs[_0x4bb7('0x3b')](0x4)+_0x4bb7('0x2a'));return convertFile(_0x3e6024,_0x5af68e);})[_0x4bb7('0x2c')](function(){try{fs['unlink'](_0x3e6024);fs[_0x4bb7('0x2d')](_0x5af68e,_0x4bb7('0x3d'));}catch(_0x4e56c4){logger[_0x4bb7('0x1e')](_0x4e56c4);}logger[_0x4bb7('0x27')](_0x4bb7('0x3e'),_0x5af68e[_0x4bb7('0x2e')]('.')[0x0]);return _0x5af68e[_0x4bb7('0x2e')]('.')[0x0];});};exports[_0x4bb7('0x3f')]=function(_0x246f8,_0x48fa2c){var _0xb00e9b=_0x4bb7('0x40');var _0x22963f,_0x4e49db;var _0x35594d;var _0x169e25={'encoding':_0x4bb7('0x41'),'method':_0x4bb7('0x39'),'timeout':0x2710,'url':_0xb00e9b,'headers':{'Content-Type':_0x4bb7('0x42')},'body':'f.req='+encodeURIComponent(JSON['stringify']([[[_0x4bb7('0x43'),JSON[_0x4bb7('0x44')]([_0x246f8,_0x48fa2c||'en',![],_0x4bb7('0x45')]),null,_0x4bb7('0x46')]]]))};return rp(_0x169e25)[_0x4bb7('0x2c')](function(_0x54c2cc){try{_0x35594d=eval(_0x54c2cc[_0x4bb7('0x47')](0x5))[0x0][0x2];}catch(_0x54b30d){throw new Error(_0x4bb7('0x48')+_0x54c2cc[_0x4bb7('0x23')]);}if(!_0x35594d){if(_0x246f8[_0x4bb7('0x49')]>0xc8){throw new Error('text\x20length\x20limit\x20reached');}else{throw new Error(_0x4bb7('0x4a')+_0x48fa2c+_0x4bb7('0x4b'));}}try{_0x35594d=eval(_0x35594d)[0x0];}catch(_0x402991){throw new Error(_0x4bb7('0x48')+res[_0x4bb7('0x23')]);}const _0x46ba02=_0x35594d;_0x22963f=path[_0x4bb7('0x3a')](__dirname,_0x4bb7('0x29'),rs['generate'](0x4)+_0x4bb7('0x4c'));fs[_0x4bb7('0x2b')](_0x22963f,_0x35594d,{'encoding':'base64'});_0x4e49db=path[_0x4bb7('0x3a')](__dirname,_0x4bb7('0x29'),rs[_0x4bb7('0x3b')](0x4)+_0x4bb7('0x2a'));return convertFile(_0x22963f,_0x4e49db);})[_0x4bb7('0x2c')](function(){try{fs['unlink'](_0x22963f);fs['chmodSync'](_0x4e49db,'777');}catch(_0xc7598a){logger[_0x4bb7('0x1e')](_0xc7598a);}logger['info'](_0x4bb7('0x4d'),_0x4e49db['split']('.')[0x0]);return _0x4e49db[_0x4bb7('0x2e')]('.')[0x0];});};exports[_0x4bb7('0x4e')]=function(_0x480d10,_0x554f46,_0x3bdf89){return google[_0x4bb7('0x4f')](_0x480d10,_0x554f46,_0x3bdf89)[_0x4bb7('0x2c')](function(_0x57d0ed){logger['info'](_0x57d0ed['uri']);return rp(_0x57d0ed);})[_0x4bb7('0x2c')](function(_0x2e7149){var _0x14403c='';var _0x5a95ac=0x0;try{fs[_0x4bb7('0x1f')](_0x480d10);}catch(_0x1742e3){logger[_0x4bb7('0x1e')](_0x1742e3);}if(_0x2e7149&&_0x2e7149[_0x4bb7('0x50')]){_0x14403c=_0x2e7149[_0x4bb7('0x50')][_0x4bb7('0x51')](function(_0x1f3816){return _0x1f3816&&_0x1f3816[_0x4bb7('0x52')][0x0]&&_0x1f3816[_0x4bb7('0x52')][0x0][_0x4bb7('0x53')]?_0x1f3816['alternatives'][0x0][_0x4bb7('0x53')]:'';})[_0x4bb7('0x54')]('\x0a');_0x5a95ac=_0x2e7149[_0x4bb7('0x50')]['map'](function(_0x503a10){return _0x503a10&&_0x503a10[_0x4bb7('0x52')][0x0]&&_0x503a10[_0x4bb7('0x52')][0x0][_0x4bb7('0x55')]?_0x503a10[_0x4bb7('0x52')][0x0]['confidence']:0x0;})[_0x4bb7('0x54')]('\x0a');}logger[_0x4bb7('0x27')](_0x4bb7('0x56'),_0x14403c);logger['info']('googleASR\x20confidence',_0x5a95ac);return{'transcript':_0x14403c,'confidence':_0x5a95ac};})[_0x4bb7('0x57')](function(_0x5c61a4){logger[_0x4bb7('0x1e')](_0x4bb7('0x58'),_0x5c61a4[_0x4bb7('0x19')],_0x5c61a4[_0x4bb7('0x59')],_0x5c61a4[_0x4bb7('0x5a')]);});};exports[_0x4bb7('0x5b')]=function(_0x34bea5,_0x306516,_0x429f95,_0x138be2){var _0x5d3991=apiai(_0x306516,{'language':_0x138be2||'en'});return _0x5d3991[_0x4bb7('0x5c')](_0x429f95,{'sessionId':md5(_0x34bea5)})['then'](function(_0x4129df){logger['info'](JSON[_0x4bb7('0x44')](_0x4129df));return{'source':_0x4129df[_0x4bb7('0x5d')][_0x4bb7('0x5e')],'resolvedQuery':_0x4129df[_0x4bb7('0x5d')][_0x4bb7('0x5f')],'action':_0x4129df['result'][_0x4bb7('0x60')],'actionIncomplete':_0x4129df[_0x4bb7('0x5d')][_0x4bb7('0x61')],'speech':_0x4129df['result'][_0x4bb7('0x62')]['speech'],'score':_0x4129df[_0x4bb7('0x5d')][_0x4bb7('0x63')],'statusCode':_0x4129df['status'][_0x4bb7('0x64')],'endConversation':_0x4129df[_0x4bb7('0x5d')][_0x4bb7('0x65')][_0x4bb7('0x66')]||![],'isFallbackIntent':_0x4129df['result'][_0x4bb7('0x65')]['isFallbackIntent']};});};exports['googleDialogflowV2']=function(_0x4317de,_0x280e86,_0x4fda73,_0x4572f3,_0x4b3e1c,_0x40df02){var _0x121100=_0x4572f3['replace'](/\\n/g,'\x0a');var _0x4789a9={'credentials':{'private_key':_0x121100,'client_email':_0x4fda73}};var _0x1355dd=new dialogflow[(_0x4bb7('0x67'))](_0x4789a9);var _0x370ca3=_0x1355dd[_0x4bb7('0x68')](_0x280e86,md5(_0x4317de));var _0x267aef={'session':_0x370ca3,'queryInput':{'text':{'text':_0x4b3e1c,'languageCode':_0x40df02}}};return _0x1355dd[_0x4bb7('0x69')](_0x267aef)[_0x4bb7('0x2c')](function(_0x5eb7d6){if(_0x5eb7d6&&_0x5eb7d6['length']){logger[_0x4bb7('0x27')](_0x4bb7('0x6a'),JSON[_0x4bb7('0x44')](_0x5eb7d6));var _0x31fcc8=_0x5eb7d6[0x0];if(_0x31fcc8){var _0x2576a3={'action':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x60')],'allRequiredParamsPresent':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x6c')],'endConversation':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x6d')]&&_0x31fcc8['queryResult'][_0x4bb7('0x6d')]['fields']?_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x6d')]['fields'][_0x4bb7('0x6e')][_0x4bb7('0x6f')]:![],'fulfillmentText':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x70')],'intentName':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x71')][_0x4bb7('0x59')],'intentDisplayName':_0x31fcc8[_0x4bb7('0x6b')]['intent'][_0x4bb7('0x72')],'isFallbackIntent':_0x31fcc8['queryResult']['intent'][_0x4bb7('0x73')],'languageCode':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x74')],'queryText':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x75')],'responseId':_0x31fcc8[_0x4bb7('0x76')],'score':_0x31fcc8[_0x4bb7('0x6b')][_0x4bb7('0x77')],'speech':_0x31fcc8[_0x4bb7('0x6b')]['fulfillmentText'],'providerResponse':JSON['stringify'](_0x5eb7d6)};return _0x2576a3;}}});};exports[_0x4bb7('0x78')]=function(_0x498b6d,_0x352619,_0x2f6d67,_0x22e0df){return tilde[_0x4bb7('0x4f')](_0x498b6d,_0x352619,_0x2f6d67,_0x22e0df)[_0x4bb7('0x2c')](function(_0xad210e){try{fs[_0x4bb7('0x1f')](_0x498b6d);}catch(_0x4317f3){logger[_0x4bb7('0x1e')](_0x4317f3);}logger[_0x4bb7('0x27')](_0x4bb7('0x79'),_0xad210e[_0x4bb7('0x53')]);logger[_0x4bb7('0x27')](_0x4bb7('0x7a'),_0xad210e[_0x4bb7('0x55')]);return _0xad210e;});};exports[_0x4bb7('0x7b')]=function(_0x470952,_0x2b49a2,_0x5a09e3,_0x143d9e,_0xaf3c9c,_0x513b52){var _0x383999=path['resolve'](__dirname,_0x4bb7('0x29'),rs['generate'](0x4)+_0x4bb7('0x4c'));var _0x5a1845;return aws[_0x4bb7('0x7c')](_0x470952,_0x2b49a2,_0x5a09e3,_0x143d9e,_0xaf3c9c,_0x513b52,_0x383999)[_0x4bb7('0x2c')](function(){_0x5a1845=path[_0x4bb7('0x3a')](__dirname,'tmp',rs[_0x4bb7('0x3b')](0x4)+_0x4bb7('0x2a'));return convertFile(_0x383999,_0x5a1845);})['then'](function(){try{fs[_0x4bb7('0x1f')](_0x383999);fs[_0x4bb7('0x2d')](_0x5a1845,'777');}catch(_0x4e1bf0){logger[_0x4bb7('0x1e')](_0x4e1bf0);}return _0x5a1845[_0x4bb7('0x2e')]('.')[0x0];});};exports[_0x4bb7('0x7d')]=function(_0x38b833,_0x4dc413,_0x5d64f8,_0x408958,_0x1dd90d,_0x27f0d1){return aws[_0x4bb7('0x7e')](_0x38b833,_0x4dc413,_0x5d64f8,_0x408958,_0x1dd90d,_0x27f0d1)[_0x4bb7('0x2c')](function(_0x17626d){logger[_0x4bb7('0x27')](JSON[_0x4bb7('0x44')](_0x17626d));return _0x17626d;});};exports[_0x4bb7('0x7f')]=function(_0x21bec2,_0x40313d,_0x5c9251,_0x14f02a){var _0x273d60=util[_0x4bb7('0x80')](_0x4bb7('0x81'),ISPEECH_API,_0x21bec2,encodeURIComponent(_0x40313d),_0x5c9251,_0x14f02a);var _0x519105=path['resolve'](__dirname,'tmp',rs[_0x4bb7('0x3b')](0x4)+_0x4bb7('0x4c'));var _0x3e3bf0;return downloadFile(_0x273d60,_0x519105)[_0x4bb7('0x2c')](function(){_0x3e3bf0=path[_0x4bb7('0x3a')](__dirname,'tmp',rs[_0x4bb7('0x3b')](0x4)+_0x4bb7('0x2a'));return convertFile(_0x519105,_0x3e3bf0);})[_0x4bb7('0x2c')](function(){try{fs[_0x4bb7('0x1f')](_0x519105);fs[_0x4bb7('0x2d')](_0x3e3bf0,'777');}catch(_0x342fb6){logger[_0x4bb7('0x1e')](_0x342fb6);}return _0x3e3bf0[_0x4bb7('0x2e')]('.')[0x0];});};exports['ispeechASR']=function(_0x59e1ac,_0x3c66f0,_0x3e33df,_0x23106b){var _0x40a532=util['format'](_0x4bb7('0x82'),ISPEECH_API,_0x3c66f0,_0x3e33df,base64Encode(_0x59e1ac),_0x23106b?util[_0x4bb7('0x80')](_0x4bb7('0x83'),encodeURIComponent(_0x23106b)):'freeform=3');return uploadFile(_0x40a532)[_0x4bb7('0x2c')](function(_0x446455){return querystring[_0x4bb7('0xb')](_0x446455);});};exports[_0x4bb7('0x84')]=function(_0x35fa4c,_0x324cab){return sestek['nda'](_0x35fa4c,_0x324cab)[_0x4bb7('0x2c')](function(_0x96cb31){logger[_0x4bb7('0x27')](JSON[_0x4bb7('0x44')](_0x96cb31));var _0x295f10={'speech':_0x96cb31[_0x4bb7('0x85')],'action':_0x96cb31['channelData']?_0x96cb31[_0x4bb7('0x86')][_0x4bb7('0x87')]:undefined,'actiondata':_0x96cb31[_0x4bb7('0x86')]?_0x96cb31['channelData'][_0x4bb7('0x88')]:undefined};if(_0x96cb31[_0x4bb7('0x86')]&&_0x96cb31[_0x4bb7('0x86')][_0x4bb7('0x89')]){return base64Decode(_0x96cb31[_0x4bb7('0x86')][_0x4bb7('0x89')]['Data'],path[_0x4bb7('0x3a')](__dirname,'tmp',rs[_0x4bb7('0x3b')](0x4)+_0x4bb7('0x2a')))[_0x4bb7('0x2c')](function(_0x32a906){_0x295f10[_0x4bb7('0x8a')]=_0x32a906;return _0x295f10;});}return _0x295f10;});};exports[_0x4bb7('0x8b')]=function(){return __dirname;};
\ No newline at end of file