Built motion from commit (unavailable).|2.5.3
[motion2.git] / server / services / agi / scripts / tilde / asr / lib / api.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xd14e=['EOS','error','Tilde\x20ASR\x20send\x20error','terminate','status','result','final','Tilde\x20ASR\x20hypoteses','hypotheses','transcript','likelihood','Success.','No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech','Aborted.\x20Recognition\x20was\x20aborted\x20for\x20some\x20reason.','Not\x20available.\x20Max\x20load\x20limit\x20reached.','Authentication\x20failed.','All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.','Tilde\x20ASR\x20parse\x20error','Close\x20Tilde\x20ASR\x20socket','Error\x20Tilde\x20ASR\x20socket','isObject','open','message','close','bluebird','lodash','moment','crypto','agi','exports','info','Tilde\x20URI','wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE','createHash','sha1','update','digest','hex','Open\x20Tilde\x20ASR\x20socket','unix','send','stringify','createReadStream','data'];(function(_0x2641f9,_0x26715f){var _0x585741=function(_0x2d1462){while(--_0x2d1462){_0x2641f9['push'](_0x2641f9['shift']());}};_0x585741(++_0x26715f);}(_0xd14e,0xc8));var _0xed14=function(_0x338df0,_0x10e28a){_0x338df0=_0x338df0-0x0;var _0x528d87=_0xd14e[_0x338df0];return _0x528d87;};'use strict';var BPromise=require(_0xed14('0x0'));var _=require(_0xed14('0x1'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0xed14('0x2'));var crypto=require(_0xed14('0x3'));var logger=require('../../../../../../config/logger')(_0xed14('0x4'));module[_0xed14('0x5')]=function(_0x5d8ac2,_0x2f8e65,_0x40dd0a,_0x406080){return new BPromise(function(_0x106098,_0x4cb580){logger[_0xed14('0x6')](_0xed14('0x7'),_0x406080||_0xed14('0x8'));var _0x135647=new WebSocket(_0x406080||_0xed14('0x8'),{'perMessageDeflate':![]});var _0x25b737='';var _0x5feb2='0';var _0x4f6b21='1';var _0x5ee823='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';function _0x55cdf8(_0x78a337){var _0x57c065=crypto[_0xed14('0x9')](_0xed14('0xa'));_0x57c065[_0xed14('0xb')](_0x78a337);return _0x57c065[_0xed14('0xc')](_0xed14('0xd'));}function _0x2b82cd(){try{logger['info'](_0xed14('0xe'));var _0x1eba0e=moment()[_0xed14('0xf')]();var _0x531a91=_0x55cdf8(_0x1eba0e+_0x2f8e65+_0x40dd0a);_0x135647[_0xed14('0x10')](JSON[_0xed14('0x11')]({'appID':_0x2f8e65,'timestamp':_0x1eba0e,'appKey':_0x531a91}));var _0x5f3be9=fs[_0xed14('0x12')](_0x5d8ac2);_0x5f3be9['on'](_0xed14('0x13'),function(_0x718d8){_0x135647[_0xed14('0x10')](_0x718d8);});_0x5f3be9['on']('close',function(){_0x135647[_0xed14('0x10')](_0xed14('0x14'));});}catch(_0x12c5ec){logger[_0xed14('0x15')](_0xed14('0x16'),JSON[_0xed14('0x11')](_0x12c5ec));_0x135647[_0xed14('0x17')]();}}function _0x624e96(_0x28ea34){try{if(_0x28ea34){var _0x5b465a=JSON['parse'](_0x28ea34);switch(_0x5b465a[_0xed14('0x18')]){case 0x0:if(_0x5b465a[_0xed14('0x19')]){if(_0x5b465a[_0xed14('0x19')][_0xed14('0x1a')]){logger['info'](_0xed14('0x1b'),JSON[_0xed14('0x11')](_0x5b465a[_0xed14('0x19')]['hypotheses']));_0x25b737=_0x5b465a[_0xed14('0x19')][_0xed14('0x1c')][0x0][_0xed14('0x1d')];_0x5feb2=_0x5b465a['result'][_0xed14('0x1c')][0x0][_0xed14('0x1e')];_0x4f6b21='0';_0x5ee823=_0xed14('0x1f');_0x135647[_0xed14('0x17')]();}}break;case 0x1:logger['info'](_0xed14('0x20'));_0x4f6b21='1';_0x5ee823='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';break;case 0x2:logger[_0xed14('0x6')](_0xed14('0x21'));_0x4f6b21='2';_0x5ee823=_0xed14('0x21');break;case 0x9:logger['info'](_0xed14('0x22'));_0x4f6b21='9';_0x5ee823='Not\x20available.\x20Max\x20load\x20limit\x20reached.';break;case 0xa:logger['info'](_0xed14('0x23'));_0x4f6b21='10';_0x5ee823=_0xed14('0x23');break;case 0xb:logger[_0xed14('0x6')]('All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.');_0x4f6b21='11';_0x5ee823=_0xed14('0x24');}}}catch(_0x32f1d2){logger[_0xed14('0x15')](_0xed14('0x25'),JSON[_0xed14('0x11')](_0x32f1d2));_0x135647['terminate']();}}function _0x121eb6(){logger[_0xed14('0x6')](_0xed14('0x26'));_0x106098({'transcript':_0x25b737,'confidence':_0x5feb2,'status':_0x4f6b21,'status_message':_0x5ee823});}function _0x1f6feb(_0x25fb63){logger[_0xed14('0x15')](_0xed14('0x27'));if(!_['isNil'](_0x25fb63)){logger[_0xed14('0x15')](_[_0xed14('0x28')](_0x25fb63)?JSON[_0xed14('0x11')](_0x25fb63):_0x25fb63);}}_0x135647['on'](_0xed14('0x29'),_0x2b82cd);_0x135647['on'](_0xed14('0x2a'),_0x624e96);_0x135647['on'](_0xed14('0x2b'),_0x121eb6);_0x135647['on']('error',_0x1f6feb);});};