Built motion from commit (unavailable).|2.1.0
[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 _0x57a1=['Success.','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','isNil','isObject','message','bluebird','moment','crypto','../../../../../../config/logger','agi','exports','info','Tilde\x20URI','wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE','createHash','update','digest','hex','Open\x20Tilde\x20ASR\x20socket','unix','send','stringify','createReadStream','data','close','EOS','error','Tilde\x20ASR\x20send\x20error','terminate','parse','status','result','final','Tilde\x20ASR\x20hypoteses','hypotheses','likelihood'];(function(_0x4627e8,_0x48c929){var _0x34e0d2=function(_0x5250f2){while(--_0x5250f2){_0x4627e8['push'](_0x4627e8['shift']());}};_0x34e0d2(++_0x48c929);}(_0x57a1,0x199));var _0x157a=function(_0x29982b,_0x594e0){_0x29982b=_0x29982b-0x0;var _0xb1f0a9=_0x57a1[_0x29982b];return _0xb1f0a9;};'use strict';var BPromise=require(_0x157a('0x0'));var _=require('lodash');var fs=require('fs');var WebSocket=require('ws');var moment=require(_0x157a('0x1'));var crypto=require(_0x157a('0x2'));var logger=require(_0x157a('0x3'))(_0x157a('0x4'));module[_0x157a('0x5')]=function(_0x42f269,_0x8d2bdc,_0x4fc889,_0x227e35){return new BPromise(function(_0x15457b,_0x7b115){logger[_0x157a('0x6')](_0x157a('0x7'),_0x227e35||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE');var _0x37e774=new WebSocket(_0x227e35||_0x157a('0x8'),{'perMessageDeflate':![]});var _0xa2f40f='';var _0xaef34b='0';var _0x2df474='1';var _0x3a1e5a='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';function _0xbad100(_0x114c9a){var _0x4d1f95=crypto[_0x157a('0x9')]('sha1');_0x4d1f95[_0x157a('0xa')](_0x114c9a);return _0x4d1f95[_0x157a('0xb')](_0x157a('0xc'));}function _0x219f8c(){try{logger[_0x157a('0x6')](_0x157a('0xd'));var _0x16cffb=moment()[_0x157a('0xe')]();var _0x10f679=_0xbad100(_0x16cffb+_0x8d2bdc+_0x4fc889);_0x37e774[_0x157a('0xf')](JSON[_0x157a('0x10')]({'appID':_0x8d2bdc,'timestamp':_0x16cffb,'appKey':_0x10f679}));var _0x1aa61b=fs[_0x157a('0x11')](_0x42f269);_0x1aa61b['on'](_0x157a('0x12'),function(_0x347bcf){_0x37e774[_0x157a('0xf')](_0x347bcf);});_0x1aa61b['on'](_0x157a('0x13'),function(){_0x37e774[_0x157a('0xf')](_0x157a('0x14'));});}catch(_0x3a5a19){logger[_0x157a('0x15')](_0x157a('0x16'),JSON[_0x157a('0x10')](_0x3a5a19));_0x37e774[_0x157a('0x17')]();}}function _0x452b87(_0x294912){try{if(_0x294912){var _0x42fc40=JSON[_0x157a('0x18')](_0x294912);switch(_0x42fc40[_0x157a('0x19')]){case 0x0:if(_0x42fc40[_0x157a('0x1a')]){if(_0x42fc40['result'][_0x157a('0x1b')]){logger['info'](_0x157a('0x1c'),JSON['stringify'](_0x42fc40[_0x157a('0x1a')][_0x157a('0x1d')]));_0xa2f40f=_0x42fc40[_0x157a('0x1a')][_0x157a('0x1d')][0x0]['transcript'];_0xaef34b=_0x42fc40[_0x157a('0x1a')][_0x157a('0x1d')][0x0][_0x157a('0x1e')];_0x2df474='0';_0x3a1e5a=_0x157a('0x1f');_0x37e774[_0x157a('0x17')]();}}break;case 0x1:logger['info']('No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech');_0x2df474='1';_0x3a1e5a='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';break;case 0x2:logger[_0x157a('0x6')](_0x157a('0x20'));_0x2df474='2';_0x3a1e5a='Aborted.\x20Recognition\x20was\x20aborted\x20for\x20some\x20reason.';break;case 0x9:logger[_0x157a('0x6')](_0x157a('0x21'));_0x2df474='9';_0x3a1e5a=_0x157a('0x21');break;case 0xa:logger['info'](_0x157a('0x22'));_0x2df474='10';_0x3a1e5a=_0x157a('0x22');break;case 0xb:logger[_0x157a('0x6')](_0x157a('0x23'));_0x2df474='11';_0x3a1e5a='All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.';}}}catch(_0x315c30){logger[_0x157a('0x15')](_0x157a('0x24'),JSON[_0x157a('0x10')](_0x315c30));_0x37e774[_0x157a('0x17')]();}}function _0x22d230(){logger[_0x157a('0x6')]('Close\x20Tilde\x20ASR\x20socket');_0x15457b({'transcript':_0xa2f40f,'confidence':_0xaef34b,'status':_0x2df474,'status_message':_0x3a1e5a});}function _0x3141f5(_0x37164e){logger[_0x157a('0x15')]('Error\x20Tilde\x20ASR\x20socket');if(!_[_0x157a('0x25')](_0x37164e)){logger['error'](_[_0x157a('0x26')](_0x37164e)?JSON[_0x157a('0x10')](_0x37164e):_0x37164e);}}_0x37e774['on']('open',_0x219f8c);_0x37e774['on'](_0x157a('0x27'),_0x452b87);_0x37e774['on']('close',_0x22d230);_0x37e774['on'](_0x157a('0x15'),_0x3141f5);});};