Built motion from commit da617fac.|2.6.6
[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 _0xe075=['terminate','parse','status','result','final','Tilde\x20ASR\x20hypoteses','transcript','hypotheses','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.','Close\x20Tilde\x20ASR\x20socket','Error\x20Tilde\x20ASR\x20socket','isNil','isObject','open','bluebird','lodash','moment','crypto','../../../../../../config/logger','agi','exports','info','Tilde\x20URI','wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE','createHash','sha1','update','hex','Open\x20Tilde\x20ASR\x20socket','unix','send','stringify','data','close','EOS','Tilde\x20ASR\x20send\x20error'];(function(_0x391c5c,_0x534ad7){var _0x3c6772=function(_0x38987d){while(--_0x38987d){_0x391c5c['push'](_0x391c5c['shift']());}};_0x3c6772(++_0x534ad7);}(_0xe075,0x13a));var _0x5e07=function(_0x5581f9,_0x29ca4f){_0x5581f9=_0x5581f9-0x0;var _0x2d2e07=_0xe075[_0x5581f9];return _0x2d2e07;};'use strict';var BPromise=require(_0x5e07('0x0'));var _=require(_0x5e07('0x1'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0x5e07('0x2'));var crypto=require(_0x5e07('0x3'));var logger=require(_0x5e07('0x4'))(_0x5e07('0x5'));module[_0x5e07('0x6')]=function(_0x3deb08,_0x4c6b41,_0x26313c,_0x3afedf){return new BPromise(function(_0x4a8860,_0x14351b){logger[_0x5e07('0x7')](_0x5e07('0x8'),_0x3afedf||_0x5e07('0x9'));var _0x1f7b58=new WebSocket(_0x3afedf||_0x5e07('0x9'),{'perMessageDeflate':![]});var _0x84e4b8='';var _0x2a43fc='0';var _0x5dc06d='1';var _0x488809='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';function _0x529539(_0x3c05a5){var _0x6122ab=crypto[_0x5e07('0xa')](_0x5e07('0xb'));_0x6122ab[_0x5e07('0xc')](_0x3c05a5);return _0x6122ab['digest'](_0x5e07('0xd'));}function _0x2c66cc(){try{logger['info'](_0x5e07('0xe'));var _0x20ea37=moment()[_0x5e07('0xf')]();var _0x302393=_0x529539(_0x20ea37+_0x4c6b41+_0x26313c);_0x1f7b58[_0x5e07('0x10')](JSON[_0x5e07('0x11')]({'appID':_0x4c6b41,'timestamp':_0x20ea37,'appKey':_0x302393}));var _0x25ef71=fs['createReadStream'](_0x3deb08);_0x25ef71['on'](_0x5e07('0x12'),function(_0x405540){_0x1f7b58['send'](_0x405540);});_0x25ef71['on'](_0x5e07('0x13'),function(){_0x1f7b58[_0x5e07('0x10')](_0x5e07('0x14'));});}catch(_0xd77122){logger['error'](_0x5e07('0x15'),JSON[_0x5e07('0x11')](_0xd77122));_0x1f7b58[_0x5e07('0x16')]();}}function _0x9d1cbf(_0xf2dd50){try{if(_0xf2dd50){var _0x25d004=JSON[_0x5e07('0x17')](_0xf2dd50);switch(_0x25d004[_0x5e07('0x18')]){case 0x0:if(_0x25d004['result']){if(_0x25d004[_0x5e07('0x19')][_0x5e07('0x1a')]){logger[_0x5e07('0x7')](_0x5e07('0x1b'),JSON[_0x5e07('0x11')](_0x25d004[_0x5e07('0x19')]['hypotheses']));_0x84e4b8=_0x25d004[_0x5e07('0x19')]['hypotheses'][0x0][_0x5e07('0x1c')];_0x2a43fc=_0x25d004[_0x5e07('0x19')][_0x5e07('0x1d')][0x0][_0x5e07('0x1e')];_0x5dc06d='0';_0x488809=_0x5e07('0x1f');_0x1f7b58[_0x5e07('0x16')]();}}break;case 0x1:logger['info']('No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech');_0x5dc06d='1';_0x488809=_0x5e07('0x20');break;case 0x2:logger[_0x5e07('0x7')](_0x5e07('0x21'));_0x5dc06d='2';_0x488809=_0x5e07('0x21');break;case 0x9:logger[_0x5e07('0x7')]('Not\x20available.\x20Max\x20load\x20limit\x20reached.');_0x5dc06d='9';_0x488809=_0x5e07('0x22');break;case 0xa:logger[_0x5e07('0x7')](_0x5e07('0x23'));_0x5dc06d='10';_0x488809=_0x5e07('0x23');break;case 0xb:logger[_0x5e07('0x7')](_0x5e07('0x24'));_0x5dc06d='11';_0x488809=_0x5e07('0x24');}}}catch(_0x53d769){logger['error']('Tilde\x20ASR\x20parse\x20error',JSON[_0x5e07('0x11')](_0x53d769));_0x1f7b58[_0x5e07('0x16')]();}}function _0xeb2adc(){logger[_0x5e07('0x7')](_0x5e07('0x25'));_0x4a8860({'transcript':_0x84e4b8,'confidence':_0x2a43fc,'status':_0x5dc06d,'status_message':_0x488809});}function _0x4079b9(_0x5dd197){logger['error'](_0x5e07('0x26'));if(!_[_0x5e07('0x27')](_0x5dd197)){logger['error'](_[_0x5e07('0x28')](_0x5dd197)?JSON[_0x5e07('0x11')](_0x5dd197):_0x5dd197);}}_0x1f7b58['on'](_0x5e07('0x29'),_0x2c66cc);_0x1f7b58['on']('message',_0x9d1cbf);_0x1f7b58['on'](_0x5e07('0x13'),_0xeb2adc);_0x1f7b58['on']('error',_0x4079b9);});};