Built motion from commit b0a9a629.|2.6.33
[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 _0x0c94=['Authentication\x20failed.','All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.','error','Tilde\x20ASR\x20parse\x20error','Close\x20Tilde\x20ASR\x20socket','Error\x20Tilde\x20ASR\x20socket','isNil','isObject','open','message','lodash','moment','crypto','../../../../../../config/logger','agi','exports','info','Tilde\x20URI','wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE','createHash','sha1','digest','Open\x20Tilde\x20ASR\x20socket','stringify','data','close','send','EOS','terminate','status','result','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.'];(function(_0x2d2824,_0xdaffc9){var _0x218bab=function(_0x22b126){while(--_0x22b126){_0x2d2824['push'](_0x2d2824['shift']());}};_0x218bab(++_0xdaffc9);}(_0x0c94,0xc8));var _0x40c9=function(_0x1a36a5,_0x746928){_0x1a36a5=_0x1a36a5-0x0;var _0x746243=_0x0c94[_0x1a36a5];return _0x746243;};'use strict';var BPromise=require('bluebird');var _=require(_0x40c9('0x0'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0x40c9('0x1'));var crypto=require(_0x40c9('0x2'));var logger=require(_0x40c9('0x3'))(_0x40c9('0x4'));module[_0x40c9('0x5')]=function(_0x3e347f,_0x47e62b,_0x719b32,_0x20637a){return new BPromise(function(_0x22dd1e,_0x5bd7a9){logger[_0x40c9('0x6')](_0x40c9('0x7'),_0x20637a||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE');var _0x5313ec=new WebSocket(_0x20637a||_0x40c9('0x8'),{'perMessageDeflate':![]});var _0x597809='';var _0x376686='0';var _0x376e01='1';var _0x2a004f='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';function _0x56655f(_0x341adb){var _0xfa56a0=crypto[_0x40c9('0x9')](_0x40c9('0xa'));_0xfa56a0['update'](_0x341adb);return _0xfa56a0[_0x40c9('0xb')]('hex');}function _0x3ff00c(){try{logger['info'](_0x40c9('0xc'));var _0x368032=moment()['unix']();var _0x2bce8d=_0x56655f(_0x368032+_0x47e62b+_0x719b32);_0x5313ec['send'](JSON[_0x40c9('0xd')]({'appID':_0x47e62b,'timestamp':_0x368032,'appKey':_0x2bce8d}));var _0x1daf09=fs['createReadStream'](_0x3e347f);_0x1daf09['on'](_0x40c9('0xe'),function(_0x5bd039){_0x5313ec['send'](_0x5bd039);});_0x1daf09['on'](_0x40c9('0xf'),function(){_0x5313ec[_0x40c9('0x10')](_0x40c9('0x11'));});}catch(_0x45942c){logger['error']('Tilde\x20ASR\x20send\x20error',JSON[_0x40c9('0xd')](_0x45942c));_0x5313ec[_0x40c9('0x12')]();}}function _0x362ed0(_0x3253c1){try{if(_0x3253c1){var _0x14059a=JSON['parse'](_0x3253c1);switch(_0x14059a[_0x40c9('0x13')]){case 0x0:if(_0x14059a[_0x40c9('0x14')]){if(_0x14059a['result']['final']){logger[_0x40c9('0x6')]('Tilde\x20ASR\x20hypoteses',JSON[_0x40c9('0xd')](_0x14059a[_0x40c9('0x14')][_0x40c9('0x15')]));_0x597809=_0x14059a[_0x40c9('0x14')]['hypotheses'][0x0][_0x40c9('0x16')];_0x376686=_0x14059a['result'][_0x40c9('0x15')][0x0][_0x40c9('0x17')];_0x376e01='0';_0x2a004f=_0x40c9('0x18');_0x5313ec['terminate']();}}break;case 0x1:logger['info']('No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech');_0x376e01='1';_0x2a004f=_0x40c9('0x19');break;case 0x2:logger['info'](_0x40c9('0x1a'));_0x376e01='2';_0x2a004f=_0x40c9('0x1a');break;case 0x9:logger['info']('Not\x20available.\x20Max\x20load\x20limit\x20reached.');_0x376e01='9';_0x2a004f=_0x40c9('0x1b');break;case 0xa:logger[_0x40c9('0x6')](_0x40c9('0x1c'));_0x376e01='10';_0x2a004f=_0x40c9('0x1c');break;case 0xb:logger[_0x40c9('0x6')](_0x40c9('0x1d'));_0x376e01='11';_0x2a004f='All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.';}}}catch(_0x544689){logger[_0x40c9('0x1e')](_0x40c9('0x1f'),JSON[_0x40c9('0xd')](_0x544689));_0x5313ec[_0x40c9('0x12')]();}}function _0x1c9885(){logger[_0x40c9('0x6')](_0x40c9('0x20'));_0x22dd1e({'transcript':_0x597809,'confidence':_0x376686,'status':_0x376e01,'status_message':_0x2a004f});}function _0xfa28af(_0x5c15e9){logger[_0x40c9('0x1e')](_0x40c9('0x21'));if(!_[_0x40c9('0x22')](_0x5c15e9)){logger['error'](_[_0x40c9('0x23')](_0x5c15e9)?JSON[_0x40c9('0xd')](_0x5c15e9):_0x5c15e9);}}_0x5313ec['on'](_0x40c9('0x24'),_0x3ff00c);_0x5313ec['on'](_0x40c9('0x25'),_0x362ed0);_0x5313ec['on'](_0x40c9('0xf'),_0x1c9885);_0x5313ec['on']('error',_0xfa28af);});};