Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / services / agi / scripts / index.js
index 22e02ef..d2fd740 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x566d=['freeform=3','sestekNDA','nda','text','channelData','CustomAction','CustomActionData','AudioFromTts','Data','audiofile','apiai-promise','dialogflow','http','https','md5','querystring','randomstring','sox','url','parse','./aws','./tilde','../../../config/logger','agi','https://api.ispeech.org/api/rest','protocol','https:','host','path','WHAT_EVER','get','statusCode','error','\x20failed,\x20status\x20code\x20=\x20','statusMessage','request\x20to\x20','createWriteStream','finish','finish\x20download\x20file','unlink','download\x20error','pipe','end','transcode','error\x20convert','info','finish\x20to\x20convert','start','resolve','tmp','generate','.wav','writeFileSync','base64','chmodSync','777','toString','https://texttospeech.googleapis.com/v1/','ssml','input','voice','audioConfig','MP3','text:synthesize','POST','.mp3','from','audioContent','then','split','googleTTS','goggleTTS\x20path','results','map','alternatives','transcript','join','confidence','googleASR\x20transcription','googleASR\x20confidence','[%s]\x20%s:%s','textRequest','stringify','result','source','resolvedQuery','action','actionIncomplete','fulfillment','speech','status','metadata','endConversation','isFallbackIntent','replace','SessionsClient','sessionPath','detectIntent','length','Dialogflow\x20V2\x20response:','queryResult','allRequiredParamsPresent','diagnosticInfo','fields','intent','displayName','isFallback','languageCode','queryText','responseId','intentDetectionConfidence','fulfillmentText','tildeASR','asr','Tilde\x20ASR\x20confidence','awsPolly','polly','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'];(function(_0x5525bf,_0x165203){var _0xcf3ce8=function(_0x26cc97){while(--_0x26cc97){_0x5525bf['push'](_0x5525bf['shift']());}};_0xcf3ce8(++_0x165203);}(_0x566d,0x85));var _0xd566=function(_0x58194c,_0x51eca2){_0x58194c=_0x58194c-0x0;var _0x3c16b3=_0x566d[_0x58194c];return _0x3c16b3;};'use strict';var apiai=require(_0xd566('0x0'));var BPromise=require('bluebird');var dialogflow=require(_0xd566('0x1'));var fs=require('fs');var http=require(_0xd566('0x2'));var https=require(_0xd566('0x3'));var md5=require(_0xd566('0x4'));var path=require('path');var querystring=require(_0xd566('0x5'));var rp=require('request-promise');var rs=require(_0xd566('0x6'));var sox=require(_0xd566('0x7'));var tts=require('google-tts-api');var urlParse=require(_0xd566('0x8'))[_0xd566('0x9')];var util=require('util');var aws=require(_0xd566('0xa'));var google=require('./google');var sestek=require('./sestek');var tilde=require(_0xd566('0xb'));var logger=require(_0xd566('0xc'))(_0xd566('0xd'));var ISPEECH_API=_0xd566('0xe');function downloadFile(_0x3dc638,_0x442eaa){return new BPromise(function(_0x51ea98,_0x28c3b1){var _0x29be67=urlParse(_0x3dc638);var _0x2f32ac=_0x29be67[_0xd566('0xf')]===_0xd566('0x10')?https:http;var _0x47c8a4={'host':_0x29be67[_0xd566('0x11')],'path':_0x29be67[_0xd566('0x12')],'headers':{'user-agent':_0xd566('0x13')}};_0x2f32ac[_0xd566('0x14')](_0x47c8a4,function(_0x19a55b){if(_0x19a55b[_0xd566('0x15')]!==0xc8){logger[_0xd566('0x16')]('request\x20to\x20'+_0x3dc638+_0xd566('0x17')+_0x19a55b['statusCode']+'\x20('+_0x19a55b[_0xd566('0x18')]+')');_0x28c3b1(new Error(_0xd566('0x19')+_0x3dc638+_0xd566('0x17')+_0x19a55b[_0xd566('0x15')]+'\x20('+_0x19a55b[_0xd566('0x18')]+')'));return;}var _0x4bbec7=fs[_0xd566('0x1a')](_0x442eaa);_0x4bbec7['on'](_0xd566('0x1b'),function(){logger['info'](_0xd566('0x1c'));_0x4bbec7['close'](_0x51ea98);});_0x4bbec7['on']('error',function(_0x3eabc9){fs[_0xd566('0x1d')](_0x442eaa);logger['error'](_0xd566('0x1e'),_0x3eabc9);_0x28c3b1(_0x3eabc9);});_0x19a55b[_0xd566('0x1f')](_0x4bbec7);})['on'](_0xd566('0x16'),function(_0x54a4ee){logger[_0xd566('0x16')](_0x54a4ee);_0x28c3b1(_0x54a4ee);})[_0xd566('0x20')]();});}function uploadFile(_0x479e09){return new BPromise(function(_0x23d56c,_0x574663){var _0x5a0a8e=urlParse(_0x479e09);var _0x298a52=_0x5a0a8e[_0xd566('0xf')]===_0xd566('0x10')?https:http;var _0x4d9e80={'host':_0x5a0a8e['host'],'path':_0x5a0a8e[_0xd566('0x12')],'headers':{'user-agent':_0xd566('0x13')}};_0x298a52[_0xd566('0x14')](_0x4d9e80,function(_0x24af6f){if(_0x24af6f['statusCode']!==0xc8){_0x574663(new Error(_0xd566('0x19')+_0x479e09+_0xd566('0x17')+_0x24af6f[_0xd566('0x15')]+'\x20('+_0x24af6f['statusMessage']+')'));return;}var _0x94c73e='';_0x24af6f['on']('data',function(_0x22e7c6){_0x94c73e+=_0x22e7c6;});_0x24af6f['on']('end',function(){_0x23d56c(_0x94c73e);});})['on'](_0xd566('0x16'),function(_0x4bf4ad){_0x574663(_0x4bf4ad);})[_0xd566('0x20')]();});}function convertFile(_0x5d88ab,_0x455196){return new BPromise(function(_0xbe095d,_0x4259e0){var _0x3d21d3=sox[_0xd566('0x21')](_0x5d88ab,_0x455196,{'sampleRate':0x1f40,'format':'wav','channelCount':0x1,'bitRate':0xc0*0x400,'compressionQuality':0x5});_0x3d21d3['on']('error',function(_0x432b38){logger[_0xd566('0x16')](_0xd566('0x22'),_0x432b38);_0x4259e0(_0x432b38);});_0x3d21d3['on']('end',function(){logger[_0xd566('0x23')](_0xd566('0x24'));_0xbe095d();});_0x3d21d3[_0xd566('0x25')]();});}function base64Decode(_0x4cd7fb,_0x12339a){var _0x6e0fbb=path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs[_0xd566('0x28')](0x4)+_0xd566('0x29'));fs[_0xd566('0x2a')](_0x6e0fbb,_0x4cd7fb,_0xd566('0x2b'));return convertFile(_0x6e0fbb,_0x12339a)['then'](function(){try{fs['unlink'](_0x6e0fbb);fs[_0xd566('0x2c')](_0x12339a,_0xd566('0x2d'));}catch(_0x26f1ca){logger[_0xd566('0x16')](_0x26f1ca);}return _0x12339a['split']('.')[0x0];});}function base64Encode(_0x343bf1){var _0x498454=fs['readFileSync'](_0x343bf1);return new Buffer(_0x498454)[_0xd566('0x2e')](_0xd566('0x2b'));}exports['googleCloudTTS']=function(_0xc9560d,_0x4ef247,_0x2c697a,_0x5d33e7,_0x36f008,_0x11394f){var _0x17ec68,_0x35146f;var _0x1eecbf=_0xd566('0x2f');var _0x262325='?key='+_0xc9560d;var _0x482815={};if(_0x4ef247===_0xd566('0x30')){_0x482815['input']={'ssml':_0x2c697a};}else{_0x482815[_0xd566('0x31')]={'text':_0x2c697a};};_0x482815[_0xd566('0x32')]={'languageCode':_0x5d33e7,'ssmlGender':_0x36f008};_0x482815[_0xd566('0x33')]={'audioEncoding':_0xd566('0x34'),'sampleRateHertz':0x1f40};var _0x501d6c={'url':_0x1eecbf+_0xd566('0x35')+_0x262325,'method':_0xd566('0x36'),'json':!![],'body':_0x482815};return rp(_0x501d6c)['then'](function(_0x3e2a50){return new BPromise(function(_0x19ba6d,_0x390bb5){_0x17ec68=path[_0xd566('0x26')](__dirname,'tmp',rs['generate'](0x4)+_0xd566('0x37'));var _0x3e248f=Buffer[_0xd566('0x38')](_0x3e2a50[_0xd566('0x39')],_0xd566('0x2b'));return fs['writeFile'](_0x17ec68,_0x3e248f,function(_0x141e9e){_0x390bb5(_0x141e9e);},function(_0x2bb1f5){fs[_0xd566('0x2c')](_0x17ec68,_0xd566('0x2d'));_0x19ba6d(_0x2bb1f5);});});})[_0xd566('0x3a')](function(_0x496063){_0x35146f=path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs[_0xd566('0x28')](0x4)+_0xd566('0x29'));return convertFile(_0x17ec68,_0x35146f);})[_0xd566('0x3a')](function(){try{fs[_0xd566('0x1d')](_0x17ec68);fs[_0xd566('0x2c')](_0x35146f,_0xd566('0x2d'));}catch(_0x47ddd2){logger[_0xd566('0x16')](_0x47ddd2);}logger[_0xd566('0x23')]('googleCloudTTS\x20path',_0x35146f['split']('.')[0x0]);return _0x35146f[_0xd566('0x3b')]('.')[0x0];});};exports[_0xd566('0x3c')]=function(_0x33adfd,_0x4b79d2){var _0x46522c,_0x5e369f;return tts(_0x33adfd,_0x4b79d2||'en',0x1)[_0xd566('0x3a')](function(_0x131c99){logger[_0xd566('0x23')](_0x131c99);_0x46522c=path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs['generate'](0x4)+'.mp3');return downloadFile(_0x131c99,_0x46522c);})[_0xd566('0x3a')](function(){_0x5e369f=path[_0xd566('0x26')](__dirname,'tmp',rs['generate'](0x4)+'.wav');return convertFile(_0x46522c,_0x5e369f);})[_0xd566('0x3a')](function(){try{fs['unlink'](_0x46522c);fs[_0xd566('0x2c')](_0x5e369f,_0xd566('0x2d'));}catch(_0x573f99){logger['error'](_0x573f99);}logger['info'](_0xd566('0x3d'),_0x5e369f['split']('.')[0x0]);return _0x5e369f['split']('.')[0x0];});};exports['googleASR']=function(_0x513e01,_0x311a90,_0x81a1b5){return google['asr'](_0x513e01,_0x311a90,_0x81a1b5)['then'](function(_0x792ddf){logger[_0xd566('0x23')](_0x792ddf['uri']);return rp(_0x792ddf);})['then'](function(_0x54c77b){var _0x1147a7='';var _0x65d230=0x0;try{fs['unlink'](_0x513e01);}catch(_0x445539){logger[_0xd566('0x16')](_0x445539);}if(_0x54c77b&&_0x54c77b[_0xd566('0x3e')]){_0x1147a7=_0x54c77b[_0xd566('0x3e')][_0xd566('0x3f')](function(_0x53b0fd){return _0x53b0fd&&_0x53b0fd[_0xd566('0x40')][0x0]&&_0x53b0fd[_0xd566('0x40')][0x0][_0xd566('0x41')]?_0x53b0fd[_0xd566('0x40')][0x0][_0xd566('0x41')]:'';})[_0xd566('0x42')]('\x0a');_0x65d230=_0x54c77b[_0xd566('0x3e')][_0xd566('0x3f')](function(_0x3ce00e){return _0x3ce00e&&_0x3ce00e['alternatives'][0x0]&&_0x3ce00e[_0xd566('0x40')][0x0][_0xd566('0x43')]?_0x3ce00e[_0xd566('0x40')][0x0]['confidence']:0x0;})[_0xd566('0x42')]('\x0a');}logger[_0xd566('0x23')](_0xd566('0x44'),_0x1147a7);logger[_0xd566('0x23')](_0xd566('0x45'),_0x65d230);return{'transcript':_0x1147a7,'confidence':_0x65d230};})['catch'](function(_0xa3701){logger['error'](_0xd566('0x46'),_0xa3701[_0xd566('0x15')],_0xa3701['name'],_0xa3701['message']);});};exports['googleDialogflow']=function(_0x429bd0,_0x4ef032,_0x4f4196,_0x25dd82){var _0x125962=apiai(_0x4ef032,{'language':_0x25dd82||'en'});return _0x125962[_0xd566('0x47')](_0x4f4196,{'sessionId':md5(_0x429bd0)})[_0xd566('0x3a')](function(_0x19ba63){logger[_0xd566('0x23')](JSON[_0xd566('0x48')](_0x19ba63));return{'source':_0x19ba63[_0xd566('0x49')][_0xd566('0x4a')],'resolvedQuery':_0x19ba63[_0xd566('0x49')][_0xd566('0x4b')],'action':_0x19ba63['result'][_0xd566('0x4c')],'actionIncomplete':_0x19ba63[_0xd566('0x49')][_0xd566('0x4d')],'speech':_0x19ba63[_0xd566('0x49')][_0xd566('0x4e')][_0xd566('0x4f')],'score':_0x19ba63[_0xd566('0x49')]['score'],'statusCode':_0x19ba63[_0xd566('0x50')]['code'],'endConversation':_0x19ba63[_0xd566('0x49')][_0xd566('0x51')][_0xd566('0x52')]||![],'isFallbackIntent':_0x19ba63['result'][_0xd566('0x51')][_0xd566('0x53')]};});};exports['googleDialogflowV2']=function(_0x2c59b2,_0x110fc4,_0x42f002,_0x5a44c4,_0x4af7ae,_0x406cfd){var _0x5749c0=_0x5a44c4[_0xd566('0x54')](/\\n/g,'\x0a');var _0x3d33bd={'credentials':{'private_key':_0x5749c0,'client_email':_0x42f002}};var _0x1b5976=new dialogflow[(_0xd566('0x55'))](_0x3d33bd);var _0x5d4902=_0x1b5976[_0xd566('0x56')](_0x110fc4,md5(_0x2c59b2));var _0x29e645={'session':_0x5d4902,'queryInput':{'text':{'text':_0x4af7ae,'languageCode':_0x406cfd}}};return _0x1b5976[_0xd566('0x57')](_0x29e645)[_0xd566('0x3a')](function(_0x547d2b){if(_0x547d2b&&_0x547d2b[_0xd566('0x58')]){logger['info'](_0xd566('0x59'),JSON[_0xd566('0x48')](_0x547d2b));var _0x381b79=_0x547d2b[0x0];if(_0x381b79){var _0x1523b7={'action':_0x381b79[_0xd566('0x5a')][_0xd566('0x4c')],'allRequiredParamsPresent':_0x381b79[_0xd566('0x5a')][_0xd566('0x5b')],'endConversation':_0x381b79[_0xd566('0x5a')][_0xd566('0x5c')]&&_0x381b79['queryResult'][_0xd566('0x5c')][_0xd566('0x5d')]?_0x381b79['queryResult']['diagnosticInfo'][_0xd566('0x5d')]['end_conversation']['boolValue']:![],'fulfillmentText':_0x381b79[_0xd566('0x5a')]['fulfillmentText'],'intentName':_0x381b79[_0xd566('0x5a')][_0xd566('0x5e')]['name'],'intentDisplayName':_0x381b79[_0xd566('0x5a')][_0xd566('0x5e')][_0xd566('0x5f')],'isFallbackIntent':_0x381b79[_0xd566('0x5a')][_0xd566('0x5e')][_0xd566('0x60')],'languageCode':_0x381b79[_0xd566('0x5a')][_0xd566('0x61')],'queryText':_0x381b79[_0xd566('0x5a')][_0xd566('0x62')],'responseId':_0x381b79[_0xd566('0x63')],'score':_0x381b79[_0xd566('0x5a')][_0xd566('0x64')],'speech':_0x381b79[_0xd566('0x5a')][_0xd566('0x65')],'providerResponse':JSON[_0xd566('0x48')](_0x547d2b)};return _0x1523b7;}}});};exports[_0xd566('0x66')]=function(_0x373389,_0x31b18b,_0x38cf0f,_0x36daf5){return tilde[_0xd566('0x67')](_0x373389,_0x31b18b,_0x38cf0f,_0x36daf5)[_0xd566('0x3a')](function(_0x40c8ad){try{fs[_0xd566('0x1d')](_0x373389);}catch(_0x3ea15c){logger['error'](_0x3ea15c);}logger[_0xd566('0x23')]('Tilde\x20ASR\x20transcription',_0x40c8ad[_0xd566('0x41')]);logger['info'](_0xd566('0x68'),_0x40c8ad[_0xd566('0x43')]);return _0x40c8ad;});};exports[_0xd566('0x69')]=function(_0x571dcc,_0xfd3b7d,_0x106519,_0x36b7db,_0x4280df,_0x1e58b1){var _0xdbca42=path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs[_0xd566('0x28')](0x4)+_0xd566('0x37'));var _0x266a78;return aws[_0xd566('0x6a')](_0x571dcc,_0xfd3b7d,_0x106519,_0x36b7db,_0x4280df,_0x1e58b1,_0xdbca42)['then'](function(){_0x266a78=path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs[_0xd566('0x28')](0x4)+_0xd566('0x29'));return convertFile(_0xdbca42,_0x266a78);})['then'](function(){try{fs[_0xd566('0x1d')](_0xdbca42);fs[_0xd566('0x2c')](_0x266a78,'777');}catch(_0x146f44){logger[_0xd566('0x16')](_0x146f44);}return _0x266a78[_0xd566('0x3b')]('.')[0x0];});};exports['awsLex']=function(_0x2dce2e,_0x2759d5,_0x1dfbe7,_0x1d5d71,_0x486547,_0x4b0979){return aws[_0xd566('0x6b')](_0x2dce2e,_0x2759d5,_0x1dfbe7,_0x1d5d71,_0x486547,_0x4b0979)[_0xd566('0x3a')](function(_0x522dc2){logger[_0xd566('0x23')](JSON[_0xd566('0x48')](_0x522dc2));return _0x522dc2;});};exports[_0xd566('0x6c')]=function(_0x4e7ef6,_0x2163cf,_0x38bf95,_0xb9f924){var _0x590642=util[_0xd566('0x6d')](_0xd566('0x6e'),ISPEECH_API,_0x4e7ef6,encodeURIComponent(_0x2163cf),_0x38bf95,_0xb9f924);var _0x518887=path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs[_0xd566('0x28')](0x4)+'.mp3');var _0x89d2c5;return downloadFile(_0x590642,_0x518887)['then'](function(){_0x89d2c5=path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs[_0xd566('0x28')](0x4)+_0xd566('0x29'));return convertFile(_0x518887,_0x89d2c5);})[_0xd566('0x3a')](function(){try{fs[_0xd566('0x1d')](_0x518887);fs['chmodSync'](_0x89d2c5,_0xd566('0x2d'));}catch(_0x3ed1d4){logger[_0xd566('0x16')](_0x3ed1d4);}return _0x89d2c5['split']('.')[0x0];});};exports[_0xd566('0x6f')]=function(_0x2fa10f,_0x587966,_0xc8c401,_0x52beab){var _0x2bbaa0=util[_0xd566('0x6d')](_0xd566('0x70'),ISPEECH_API,_0x587966,_0xc8c401,base64Encode(_0x2fa10f),_0x52beab?util[_0xd566('0x6d')]('model=%s',encodeURIComponent(_0x52beab)):_0xd566('0x71'));return uploadFile(_0x2bbaa0)[_0xd566('0x3a')](function(_0x1f4deb){return querystring[_0xd566('0x9')](_0x1f4deb);});};exports[_0xd566('0x72')]=function(_0x14b85b,_0x5089d9){return sestek[_0xd566('0x73')](_0x14b85b,_0x5089d9)[_0xd566('0x3a')](function(_0x82fe91){logger[_0xd566('0x23')](JSON[_0xd566('0x48')](_0x82fe91));var _0x16fedd={'speech':_0x82fe91[_0xd566('0x74')],'action':_0x82fe91[_0xd566('0x75')]?_0x82fe91['channelData'][_0xd566('0x76')]:undefined,'actiondata':_0x82fe91[_0xd566('0x75')]?_0x82fe91[_0xd566('0x75')][_0xd566('0x77')]:undefined};if(_0x82fe91[_0xd566('0x75')]&&_0x82fe91[_0xd566('0x75')][_0xd566('0x78')]){return base64Decode(_0x82fe91[_0xd566('0x75')][_0xd566('0x78')][_0xd566('0x79')],path[_0xd566('0x26')](__dirname,_0xd566('0x27'),rs[_0xd566('0x28')](0x4)+_0xd566('0x29')))[_0xd566('0x3a')](function(_0x1367f7){_0x16fedd[_0xd566('0x7a')]=_0x1367f7;return _0x16fedd;});}return _0x16fedd;});};exports['dirName']=function(){return __dirname;};
\ No newline at end of file
+var _0x0b06=['finish\x20download\x20file','close','unlink','pipe','end','get','data','wav','error\x20convert','finish\x20to\x20convert','tmp','generate','.wav','chmodSync','777','split','readFileSync','toString','base64','?key=','ssml','input','POST','resolve','.mp3','from','audioContent','writeFile','then','googleCloudTTS\x20path','googleTTS','https://translate.google.com/_/TranslateWebserverUi/data/batchexecute','utf8','application/x-www-form-urlencoded','f.req=','stringify','jQ1olc','generic','length','text\x20length\x20limit\x20reached','\x22\x20might\x20not\x20exist','writeFileSync','goggleTTS\x20path','googleASR','asr','results','alternatives','transcript','join','confidence','googleASR\x20transcription','googleASR\x20confidence','catch','[%s]\x20%s:%s','message','googleDialogflow','source','resolvedQuery','result','action','actionIncomplete','fulfillment','speech','status','code','metadata','endConversation','isFallbackIntent','googleDialogflowV2','SessionsClient','detectIntent','Dialogflow\x20V2\x20response:','queryResult','diagnosticInfo','fields','end_conversation','boolValue','intent','displayName','isFallback','queryText','responseId','intentDetectionConfidence','fulfillmentText','Tilde\x20ASR\x20transcription','awsPolly','awsLex','lex','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','model=%s','freeform=3','sestekNDA','nda','text','channelData','AudioFromTts','Data','apiai-promise','bluebird','dialogflow','http','md5','path','querystring','google-tts-api','url','parse','util','./aws','./google','./sestek','../../../config/logger','agi','https://api.ispeech.org/api/rest','protocol','https:','host','WHAT_EVER','error','request\x20to\x20','\x20failed,\x20status\x20code\x20=\x20','statusCode','statusMessage','createWriteStream','finish','info'];(function(_0x3b6cb5,_0x337346){var _0x277e53=function(_0x4f78b4){while(--_0x4f78b4){_0x3b6cb5['push'](_0x3b6cb5['shift']());}};_0x277e53(++_0x337346);}(_0x0b06,0xe5));var _0x60b0=function(_0x58fa5d,_0x3a7145){_0x58fa5d=_0x58fa5d-0x0;var _0xacfcc1=_0x0b06[_0x58fa5d];return _0xacfcc1;};'use strict';var apiai=require(_0x60b0('0x0'));var BPromise=require(_0x60b0('0x1'));var dialogflow=require(_0x60b0('0x2'));var fs=require('fs');var http=require(_0x60b0('0x3'));var https=require('https');var md5=require(_0x60b0('0x4'));var path=require(_0x60b0('0x5'));var querystring=require(_0x60b0('0x6'));var rp=require('request-promise');var rs=require('randomstring');var sox=require('sox');var tts=require(_0x60b0('0x7'));var urlParse=require(_0x60b0('0x8'))[_0x60b0('0x9')];var util=require(_0x60b0('0xa'));var aws=require(_0x60b0('0xb'));var google=require(_0x60b0('0xc'));var sestek=require(_0x60b0('0xd'));var tilde=require('./tilde');var logger=require(_0x60b0('0xe'))(_0x60b0('0xf'));var ISPEECH_API=_0x60b0('0x10');function downloadFile(_0x35665b,_0x590438){return new BPromise(function(_0x2aefc4,_0x952fb4){var _0x4c3a0e=urlParse(_0x35665b);var _0x262b65=_0x4c3a0e[_0x60b0('0x11')]===_0x60b0('0x12')?https:http;var _0x392a68={'host':_0x4c3a0e[_0x60b0('0x13')],'path':_0x4c3a0e[_0x60b0('0x5')],'headers':{'user-agent':_0x60b0('0x14')}};_0x262b65['get'](_0x392a68,function(_0x40625a){if(_0x40625a['statusCode']!==0xc8){logger[_0x60b0('0x15')](_0x60b0('0x16')+_0x35665b+_0x60b0('0x17')+_0x40625a[_0x60b0('0x18')]+'\x20('+_0x40625a[_0x60b0('0x19')]+')');_0x952fb4(new Error(_0x60b0('0x16')+_0x35665b+_0x60b0('0x17')+_0x40625a[_0x60b0('0x18')]+'\x20('+_0x40625a[_0x60b0('0x19')]+')'));return;}var _0x93d62c=fs[_0x60b0('0x1a')](_0x590438);_0x93d62c['on'](_0x60b0('0x1b'),function(){logger[_0x60b0('0x1c')](_0x60b0('0x1d'));_0x93d62c[_0x60b0('0x1e')](_0x2aefc4);});_0x93d62c['on'](_0x60b0('0x15'),function(_0x582d80){fs[_0x60b0('0x1f')](_0x590438);logger[_0x60b0('0x15')]('download\x20error',_0x582d80);_0x952fb4(_0x582d80);});_0x40625a[_0x60b0('0x20')](_0x93d62c);})['on'](_0x60b0('0x15'),function(_0x35ef37){logger[_0x60b0('0x15')](_0x35ef37);_0x952fb4(_0x35ef37);})[_0x60b0('0x21')]();});}function uploadFile(_0x257c18){return new BPromise(function(_0x5ed48e,_0x246951){var _0x365d98=urlParse(_0x257c18);var _0x25f6c8=_0x365d98[_0x60b0('0x11')]===_0x60b0('0x12')?https:http;var _0x438cfa={'host':_0x365d98[_0x60b0('0x13')],'path':_0x365d98[_0x60b0('0x5')],'headers':{'user-agent':'WHAT_EVER'}};_0x25f6c8[_0x60b0('0x22')](_0x438cfa,function(_0x273274){if(_0x273274[_0x60b0('0x18')]!==0xc8){_0x246951(new Error(_0x60b0('0x16')+_0x257c18+_0x60b0('0x17')+_0x273274['statusCode']+'\x20('+_0x273274[_0x60b0('0x19')]+')'));return;}var _0x50ac23='';_0x273274['on'](_0x60b0('0x23'),function(_0x1a85dd){_0x50ac23+=_0x1a85dd;});_0x273274['on'](_0x60b0('0x21'),function(){_0x5ed48e(_0x50ac23);});})['on'](_0x60b0('0x15'),function(_0x5389f8){_0x246951(_0x5389f8);})['end']();});}function convertFile(_0x1d52b9,_0x27fb3c){return new BPromise(function(_0x3243af,_0xf8c404){var _0x4c63c4=sox['transcode'](_0x1d52b9,_0x27fb3c,{'sampleRate':0x1f40,'format':_0x60b0('0x24'),'channelCount':0x1,'bitRate':0xc0*0x400,'compressionQuality':0x5});_0x4c63c4['on'](_0x60b0('0x15'),function(_0x5d1dd5){logger[_0x60b0('0x15')](_0x60b0('0x25'),_0x5d1dd5);_0xf8c404(_0x5d1dd5);});_0x4c63c4['on'](_0x60b0('0x21'),function(){logger[_0x60b0('0x1c')](_0x60b0('0x26'));_0x3243af();});_0x4c63c4['start']();});}function base64Decode(_0x13bf94,_0x200bbe){var _0x2ff11a=path['resolve'](__dirname,_0x60b0('0x27'),rs[_0x60b0('0x28')](0x4)+_0x60b0('0x29'));fs['writeFileSync'](_0x2ff11a,_0x13bf94,'base64');return convertFile(_0x2ff11a,_0x200bbe)['then'](function(){try{fs[_0x60b0('0x1f')](_0x2ff11a);fs[_0x60b0('0x2a')](_0x200bbe,_0x60b0('0x2b'));}catch(_0x280e30){logger[_0x60b0('0x15')](_0x280e30);}return _0x200bbe[_0x60b0('0x2c')]('.')[0x0];});}function base64Encode(_0x4b1648){var _0x33bb30=fs[_0x60b0('0x2d')](_0x4b1648);return new Buffer(_0x33bb30)[_0x60b0('0x2e')](_0x60b0('0x2f'));}exports['googleCloudTTS']=function(_0x28ae86,_0x29e1e2,_0x4d6f25,_0x3c7198,_0x1a510e,_0xe9938e){var _0x55c70a,_0x3019fe;var _0x36ff24='https://texttospeech.googleapis.com/v1/';var _0x134b26=_0x60b0('0x30')+_0x28ae86;var _0x3f1d56={};if(_0x29e1e2===_0x60b0('0x31')){_0x3f1d56[_0x60b0('0x32')]={'ssml':_0x4d6f25};}else{_0x3f1d56[_0x60b0('0x32')]={'text':_0x4d6f25};};_0x3f1d56['voice']={'languageCode':_0x3c7198,'ssmlGender':_0x1a510e};_0x3f1d56['audioConfig']={'audioEncoding':'MP3','sampleRateHertz':0x1f40};var _0x4d56d3={'url':_0x36ff24+'text:synthesize'+_0x134b26,'method':_0x60b0('0x33'),'json':!![],'body':_0x3f1d56};return rp(_0x4d56d3)['then'](function(_0x391559){return new BPromise(function(_0x753317,_0x32a773){_0x55c70a=path[_0x60b0('0x34')](__dirname,'tmp',rs[_0x60b0('0x28')](0x4)+_0x60b0('0x35'));var _0x10d5e8=Buffer[_0x60b0('0x36')](_0x391559[_0x60b0('0x37')],'base64');return fs[_0x60b0('0x38')](_0x55c70a,_0x10d5e8,function(_0x97e89c){_0x32a773(_0x97e89c);},function(_0x270444){fs[_0x60b0('0x2a')](_0x55c70a,'777');_0x753317(_0x270444);});});})[_0x60b0('0x39')](function(_0x5627be){_0x3019fe=path['resolve'](__dirname,_0x60b0('0x27'),rs[_0x60b0('0x28')](0x4)+'.wav');return convertFile(_0x55c70a,_0x3019fe);})[_0x60b0('0x39')](function(){try{fs[_0x60b0('0x1f')](_0x55c70a);fs[_0x60b0('0x2a')](_0x3019fe,'777');}catch(_0xd186fa){logger[_0x60b0('0x15')](_0xd186fa);}logger[_0x60b0('0x1c')](_0x60b0('0x3a'),_0x3019fe[_0x60b0('0x2c')]('.')[0x0]);return _0x3019fe['split']('.')[0x0];});};exports[_0x60b0('0x3b')]=function(_0x5c5001,_0x28098f){var _0x2ba8b7=_0x60b0('0x3c');var _0x2d76a1,_0x4490db;var _0x4775cf;var _0x3c33d2={'encoding':_0x60b0('0x3d'),'method':_0x60b0('0x33'),'timeout':0x2710,'url':_0x2ba8b7,'headers':{'Content-Type':_0x60b0('0x3e')},'body':_0x60b0('0x3f')+encodeURIComponent(JSON[_0x60b0('0x40')]([[[_0x60b0('0x41'),JSON[_0x60b0('0x40')]([_0x5c5001,_0x28098f||'en',![],'null']),null,_0x60b0('0x42')]]]))};return rp(_0x3c33d2)[_0x60b0('0x39')](function(_0x847eb6){try{_0x4775cf=eval(_0x847eb6['slice'](0x5))[0x0][0x2];}catch(_0x18e8cc){throw new Error('parse\x20response\x20failed:\x0a'+_0x847eb6[_0x60b0('0x23')]);}if(!_0x4775cf){if(_0x5c5001[_0x60b0('0x43')]>0xc8){throw new Error(_0x60b0('0x44'));}else{throw new Error('lang\x20\x22'+_0x28098f+_0x60b0('0x45'));}}try{_0x4775cf=eval(_0x4775cf)[0x0];}catch(_0x3b4480){throw new Error('parse\x20response\x20failed:\x0a'+res[_0x60b0('0x23')]);}const _0xb38f46=_0x4775cf;_0x2d76a1=path[_0x60b0('0x34')](__dirname,'tmp',rs[_0x60b0('0x28')](0x4)+_0x60b0('0x35'));fs[_0x60b0('0x46')](_0x2d76a1,_0x4775cf,{'encoding':_0x60b0('0x2f')});_0x4490db=path[_0x60b0('0x34')](__dirname,_0x60b0('0x27'),rs[_0x60b0('0x28')](0x4)+'.wav');return convertFile(_0x2d76a1,_0x4490db);})[_0x60b0('0x39')](function(){try{fs[_0x60b0('0x1f')](_0x2d76a1);fs[_0x60b0('0x2a')](_0x4490db,_0x60b0('0x2b'));}catch(_0x126eb1){logger['error'](_0x126eb1);}logger[_0x60b0('0x1c')](_0x60b0('0x47'),_0x4490db[_0x60b0('0x2c')]('.')[0x0]);return _0x4490db[_0x60b0('0x2c')]('.')[0x0];});};exports[_0x60b0('0x48')]=function(_0x3004dc,_0x371743,_0x301e4d){return google[_0x60b0('0x49')](_0x3004dc,_0x371743,_0x301e4d)['then'](function(_0x2b7fbe){logger[_0x60b0('0x1c')](_0x2b7fbe['uri']);return rp(_0x2b7fbe);})[_0x60b0('0x39')](function(_0x45cc2c){var _0x14845a='';var _0x469114=0x0;try{fs['unlink'](_0x3004dc);}catch(_0x4d79a8){logger['error'](_0x4d79a8);}if(_0x45cc2c&&_0x45cc2c[_0x60b0('0x4a')]){_0x14845a=_0x45cc2c[_0x60b0('0x4a')]['map'](function(_0x57061f){return _0x57061f&&_0x57061f[_0x60b0('0x4b')][0x0]&&_0x57061f[_0x60b0('0x4b')][0x0][_0x60b0('0x4c')]?_0x57061f[_0x60b0('0x4b')][0x0]['transcript']:'';})[_0x60b0('0x4d')]('\x0a');_0x469114=_0x45cc2c[_0x60b0('0x4a')]['map'](function(_0x4a1d08){return _0x4a1d08&&_0x4a1d08[_0x60b0('0x4b')][0x0]&&_0x4a1d08[_0x60b0('0x4b')][0x0]['confidence']?_0x4a1d08[_0x60b0('0x4b')][0x0][_0x60b0('0x4e')]:0x0;})[_0x60b0('0x4d')]('\x0a');}logger[_0x60b0('0x1c')](_0x60b0('0x4f'),_0x14845a);logger[_0x60b0('0x1c')](_0x60b0('0x50'),_0x469114);return{'transcript':_0x14845a,'confidence':_0x469114};})[_0x60b0('0x51')](function(_0x433f16){logger[_0x60b0('0x15')](_0x60b0('0x52'),_0x433f16[_0x60b0('0x18')],_0x433f16['name'],_0x433f16[_0x60b0('0x53')]);});};exports[_0x60b0('0x54')]=function(_0x32921c,_0x228bb6,_0x2e6dda,_0x5d08d2){var _0x218c12=apiai(_0x228bb6,{'language':_0x5d08d2||'en'});return _0x218c12['textRequest'](_0x2e6dda,{'sessionId':md5(_0x32921c)})['then'](function(_0x1d2ab4){logger[_0x60b0('0x1c')](JSON[_0x60b0('0x40')](_0x1d2ab4));return{'source':_0x1d2ab4['result'][_0x60b0('0x55')],'resolvedQuery':_0x1d2ab4['result'][_0x60b0('0x56')],'action':_0x1d2ab4[_0x60b0('0x57')][_0x60b0('0x58')],'actionIncomplete':_0x1d2ab4[_0x60b0('0x57')][_0x60b0('0x59')],'speech':_0x1d2ab4[_0x60b0('0x57')][_0x60b0('0x5a')][_0x60b0('0x5b')],'score':_0x1d2ab4[_0x60b0('0x57')]['score'],'statusCode':_0x1d2ab4[_0x60b0('0x5c')][_0x60b0('0x5d')],'endConversation':_0x1d2ab4[_0x60b0('0x57')][_0x60b0('0x5e')][_0x60b0('0x5f')]||![],'isFallbackIntent':_0x1d2ab4[_0x60b0('0x57')][_0x60b0('0x5e')][_0x60b0('0x60')]};});};exports[_0x60b0('0x61')]=function(_0x25e303,_0x1617e3,_0x3338b7,_0x33ba10,_0x306006,_0x1c4757){var _0x1960d6=_0x33ba10['replace'](/\\n/g,'\x0a');var _0x90a6ba={'credentials':{'private_key':_0x1960d6,'client_email':_0x3338b7}};var _0x3f4e44=new dialogflow[(_0x60b0('0x62'))](_0x90a6ba);var _0x18b946=_0x3f4e44['sessionPath'](_0x1617e3,md5(_0x25e303));var _0x3c5ca0={'session':_0x18b946,'queryInput':{'text':{'text':_0x306006,'languageCode':_0x1c4757}}};return _0x3f4e44[_0x60b0('0x63')](_0x3c5ca0)[_0x60b0('0x39')](function(_0x5c7851){if(_0x5c7851&&_0x5c7851[_0x60b0('0x43')]){logger[_0x60b0('0x1c')](_0x60b0('0x64'),JSON[_0x60b0('0x40')](_0x5c7851));var _0x1d9cb5=_0x5c7851[0x0];if(_0x1d9cb5){var _0xfedbd8={'action':_0x1d9cb5[_0x60b0('0x65')][_0x60b0('0x58')],'allRequiredParamsPresent':_0x1d9cb5[_0x60b0('0x65')]['allRequiredParamsPresent'],'endConversation':_0x1d9cb5[_0x60b0('0x65')]['diagnosticInfo']&&_0x1d9cb5[_0x60b0('0x65')][_0x60b0('0x66')]['fields']?_0x1d9cb5[_0x60b0('0x65')][_0x60b0('0x66')][_0x60b0('0x67')][_0x60b0('0x68')][_0x60b0('0x69')]:![],'fulfillmentText':_0x1d9cb5[_0x60b0('0x65')]['fulfillmentText'],'intentName':_0x1d9cb5['queryResult']['intent']['name'],'intentDisplayName':_0x1d9cb5[_0x60b0('0x65')][_0x60b0('0x6a')][_0x60b0('0x6b')],'isFallbackIntent':_0x1d9cb5['queryResult'][_0x60b0('0x6a')][_0x60b0('0x6c')],'languageCode':_0x1d9cb5[_0x60b0('0x65')]['languageCode'],'queryText':_0x1d9cb5['queryResult'][_0x60b0('0x6d')],'responseId':_0x1d9cb5[_0x60b0('0x6e')],'score':_0x1d9cb5['queryResult'][_0x60b0('0x6f')],'speech':_0x1d9cb5[_0x60b0('0x65')][_0x60b0('0x70')],'providerResponse':JSON[_0x60b0('0x40')](_0x5c7851)};return _0xfedbd8;}}});};exports['tildeASR']=function(_0x1dc05a,_0x2083f1,_0x95dd54,_0x565ca8){return tilde[_0x60b0('0x49')](_0x1dc05a,_0x2083f1,_0x95dd54,_0x565ca8)[_0x60b0('0x39')](function(_0x1e1e50){try{fs[_0x60b0('0x1f')](_0x1dc05a);}catch(_0x3fee49){logger[_0x60b0('0x15')](_0x3fee49);}logger[_0x60b0('0x1c')](_0x60b0('0x71'),_0x1e1e50[_0x60b0('0x4c')]);logger[_0x60b0('0x1c')]('Tilde\x20ASR\x20confidence',_0x1e1e50[_0x60b0('0x4e')]);return _0x1e1e50;});};exports[_0x60b0('0x72')]=function(_0x30258a,_0x7639bb,_0x574da4,_0x1c316f,_0x33088e,_0x31f569){var _0x44e7e6=path[_0x60b0('0x34')](__dirname,_0x60b0('0x27'),rs[_0x60b0('0x28')](0x4)+_0x60b0('0x35'));var _0x1a90bc;return aws['polly'](_0x30258a,_0x7639bb,_0x574da4,_0x1c316f,_0x33088e,_0x31f569,_0x44e7e6)['then'](function(){_0x1a90bc=path[_0x60b0('0x34')](__dirname,'tmp',rs['generate'](0x4)+_0x60b0('0x29'));return convertFile(_0x44e7e6,_0x1a90bc);})[_0x60b0('0x39')](function(){try{fs[_0x60b0('0x1f')](_0x44e7e6);fs[_0x60b0('0x2a')](_0x1a90bc,_0x60b0('0x2b'));}catch(_0x1737d8){logger[_0x60b0('0x15')](_0x1737d8);}return _0x1a90bc['split']('.')[0x0];});};exports[_0x60b0('0x73')]=function(_0x3d30cd,_0x54706f,_0xce3a09,_0x572ae9,_0x397809,_0x5938e1){return aws[_0x60b0('0x74')](_0x3d30cd,_0x54706f,_0xce3a09,_0x572ae9,_0x397809,_0x5938e1)[_0x60b0('0x39')](function(_0x386568){logger[_0x60b0('0x1c')](JSON[_0x60b0('0x40')](_0x386568));return _0x386568;});};exports['ispeechTTS']=function(_0x336892,_0x4118e5,_0x14c369,_0x368d78){var _0x4a30d9=util[_0x60b0('0x75')](_0x60b0('0x76'),ISPEECH_API,_0x336892,encodeURIComponent(_0x4118e5),_0x14c369,_0x368d78);var _0x2229f4=path['resolve'](__dirname,_0x60b0('0x27'),rs[_0x60b0('0x28')](0x4)+_0x60b0('0x35'));var _0x3ba818;return downloadFile(_0x4a30d9,_0x2229f4)[_0x60b0('0x39')](function(){_0x3ba818=path[_0x60b0('0x34')](__dirname,_0x60b0('0x27'),rs[_0x60b0('0x28')](0x4)+'.wav');return convertFile(_0x2229f4,_0x3ba818);})[_0x60b0('0x39')](function(){try{fs[_0x60b0('0x1f')](_0x2229f4);fs['chmodSync'](_0x3ba818,_0x60b0('0x2b'));}catch(_0x4adbbf){logger['error'](_0x4adbbf);}return _0x3ba818['split']('.')[0x0];});};exports[_0x60b0('0x77')]=function(_0x327939,_0x185b5f,_0x45acf9,_0xce825d){var _0x10d41b=util['format'](_0x60b0('0x78'),ISPEECH_API,_0x185b5f,_0x45acf9,base64Encode(_0x327939),_0xce825d?util['format'](_0x60b0('0x79'),encodeURIComponent(_0xce825d)):_0x60b0('0x7a'));return uploadFile(_0x10d41b)['then'](function(_0x1e78e3){return querystring[_0x60b0('0x9')](_0x1e78e3);});};exports[_0x60b0('0x7b')]=function(_0x53457b,_0x41979a){return sestek[_0x60b0('0x7c')](_0x53457b,_0x41979a)[_0x60b0('0x39')](function(_0x3d2f9e){logger[_0x60b0('0x1c')](JSON[_0x60b0('0x40')](_0x3d2f9e));var _0x581c3d={'speech':_0x3d2f9e[_0x60b0('0x7d')],'action':_0x3d2f9e[_0x60b0('0x7e')]?_0x3d2f9e[_0x60b0('0x7e')]['CustomAction']:undefined,'actiondata':_0x3d2f9e[_0x60b0('0x7e')]?_0x3d2f9e[_0x60b0('0x7e')]['CustomActionData']:undefined};if(_0x3d2f9e[_0x60b0('0x7e')]&&_0x3d2f9e['channelData'][_0x60b0('0x7f')]){return base64Decode(_0x3d2f9e[_0x60b0('0x7e')][_0x60b0('0x7f')][_0x60b0('0x80')],path[_0x60b0('0x34')](__dirname,_0x60b0('0x27'),rs[_0x60b0('0x28')](0x4)+_0x60b0('0x29')))[_0x60b0('0x39')](function(_0x2237a3){_0x581c3d['audiofile']=_0x2237a3;return _0x581c3d;});}return _0x581c3d;});};exports['dirName']=function(){return __dirname;};
\ No newline at end of file