Built motion from commit 932cf0d0.|2.5.42
[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 _0x8c3f=['exports','info','No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech','createHash','digest','hex','Open\x20Tilde\x20ASR\x20socket','unix','send','createReadStream','data','close','EOS','error','terminate','parse','status','result','final','Tilde\x20ASR\x20hypoteses','stringify','hypotheses','transcript','Success.','Aborted.\x20Recognition\x20was\x20aborted\x20for\x20some\x20reason.','Not\x20available.\x20Max\x20load\x20limit\x20reached.','Authentication\x20failed.','Tilde\x20ASR\x20parse\x20error','Close\x20Tilde\x20ASR\x20socket','Error\x20Tilde\x20ASR\x20socket','isNil','isObject','open','message','bluebird','lodash','moment','crypto','../../../../../../config/logger','agi'];(function(_0x1ae5ab,_0xc5d441){var _0x1ce001=function(_0x5ef96d){while(--_0x5ef96d){_0x1ae5ab['push'](_0x1ae5ab['shift']());}};_0x1ce001(++_0xc5d441);}(_0x8c3f,0x13a));var _0xf8c3=function(_0x2a1b7f,_0x191e86){_0x2a1b7f=_0x2a1b7f-0x0;var _0x275051=_0x8c3f[_0x2a1b7f];return _0x275051;};'use strict';var BPromise=require(_0xf8c3('0x0'));var _=require(_0xf8c3('0x1'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0xf8c3('0x2'));var crypto=require(_0xf8c3('0x3'));var logger=require(_0xf8c3('0x4'))(_0xf8c3('0x5'));module[_0xf8c3('0x6')]=function(_0x37a28e,_0x35c4ed,_0x544f61,_0x51503d){return new BPromise(function(_0x3ec08c,_0x39d891){logger[_0xf8c3('0x7')]('Tilde\x20URI',_0x51503d||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE');var _0x2211b7=new WebSocket(_0x51503d||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE',{'perMessageDeflate':![]});var _0x2d4fe5='';var _0x11529c='0';var _0x16bd7f='1';var _0x1b4d2d=_0xf8c3('0x8');function _0x111507(_0x265845){var _0x4ec887=crypto[_0xf8c3('0x9')]('sha1');_0x4ec887['update'](_0x265845);return _0x4ec887[_0xf8c3('0xa')](_0xf8c3('0xb'));}function _0x134e1c(){try{logger['info'](_0xf8c3('0xc'));var _0x5f1815=moment()[_0xf8c3('0xd')]();var _0x509494=_0x111507(_0x5f1815+_0x35c4ed+_0x544f61);_0x2211b7[_0xf8c3('0xe')](JSON['stringify']({'appID':_0x35c4ed,'timestamp':_0x5f1815,'appKey':_0x509494}));var _0x465241=fs[_0xf8c3('0xf')](_0x37a28e);_0x465241['on'](_0xf8c3('0x10'),function(_0x2447e3){_0x2211b7['send'](_0x2447e3);});_0x465241['on'](_0xf8c3('0x11'),function(){_0x2211b7['send'](_0xf8c3('0x12'));});}catch(_0xd3088f){logger[_0xf8c3('0x13')]('Tilde\x20ASR\x20send\x20error',JSON['stringify'](_0xd3088f));_0x2211b7[_0xf8c3('0x14')]();}}function _0x11235f(_0x483f32){try{if(_0x483f32){var _0x306a07=JSON[_0xf8c3('0x15')](_0x483f32);switch(_0x306a07[_0xf8c3('0x16')]){case 0x0:if(_0x306a07[_0xf8c3('0x17')]){if(_0x306a07[_0xf8c3('0x17')][_0xf8c3('0x18')]){logger[_0xf8c3('0x7')](_0xf8c3('0x19'),JSON[_0xf8c3('0x1a')](_0x306a07[_0xf8c3('0x17')][_0xf8c3('0x1b')]));_0x2d4fe5=_0x306a07[_0xf8c3('0x17')][_0xf8c3('0x1b')][0x0][_0xf8c3('0x1c')];_0x11529c=_0x306a07[_0xf8c3('0x17')][_0xf8c3('0x1b')][0x0]['likelihood'];_0x16bd7f='0';_0x1b4d2d=_0xf8c3('0x1d');_0x2211b7[_0xf8c3('0x14')]();}}break;case 0x1:logger[_0xf8c3('0x7')](_0xf8c3('0x8'));_0x16bd7f='1';_0x1b4d2d=_0xf8c3('0x8');break;case 0x2:logger[_0xf8c3('0x7')](_0xf8c3('0x1e'));_0x16bd7f='2';_0x1b4d2d=_0xf8c3('0x1e');break;case 0x9:logger['info'](_0xf8c3('0x1f'));_0x16bd7f='9';_0x1b4d2d=_0xf8c3('0x1f');break;case 0xa:logger['info'](_0xf8c3('0x20'));_0x16bd7f='10';_0x1b4d2d=_0xf8c3('0x20');break;case 0xb:logger['info']('All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.');_0x16bd7f='11';_0x1b4d2d='All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.';}}}catch(_0x211c76){logger[_0xf8c3('0x13')](_0xf8c3('0x21'),JSON[_0xf8c3('0x1a')](_0x211c76));_0x2211b7[_0xf8c3('0x14')]();}}function _0x4ca0f5(){logger[_0xf8c3('0x7')](_0xf8c3('0x22'));_0x3ec08c({'transcript':_0x2d4fe5,'confidence':_0x11529c,'status':_0x16bd7f,'status_message':_0x1b4d2d});}function _0x2fe1d8(_0x506c6f){logger[_0xf8c3('0x13')](_0xf8c3('0x23'));if(!_[_0xf8c3('0x24')](_0x506c6f)){logger[_0xf8c3('0x13')](_[_0xf8c3('0x25')](_0x506c6f)?JSON[_0xf8c3('0x1a')](_0x506c6f):_0x506c6f);}}_0x2211b7['on'](_0xf8c3('0x26'),_0x134e1c);_0x2211b7['on'](_0xf8c3('0x27'),_0x11235f);_0x2211b7['on'](_0xf8c3('0x11'),_0x4ca0f5);_0x2211b7['on'](_0xf8c3('0x13'),_0x2fe1d8);});};