3d2173da860e0435171b0a4d08d80f526b537b97
[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 _0xc5f6=['data','close','send','EOS','Tilde\x20ASR\x20send\x20error','terminate','parse','result','Tilde\x20ASR\x20hypoteses','hypotheses','transcript','No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech','Aborted.\x20Recognition\x20was\x20aborted\x20for\x20some\x20reason.','Authentication\x20failed.','All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.','Tilde\x20ASR\x20parse\x20error','error','Error\x20Tilde\x20ASR\x20socket','isNil','isObject','bluebird','moment','crypto','../../../../../../config/logger','agi','exports','Tilde\x20URI','wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE','createHash','sha1','digest','info','Open\x20Tilde\x20ASR\x20socket','unix','stringify','createReadStream'];(function(_0x209bbf,_0x2e2375){var _0x592d4b=function(_0x419947){while(--_0x419947){_0x209bbf['push'](_0x209bbf['shift']());}};_0x592d4b(++_0x2e2375);}(_0xc5f6,0x110));var _0x6c5f=function(_0x198d6c,_0xc44044){_0x198d6c=_0x198d6c-0x0;var _0x2c9842=_0xc5f6[_0x198d6c];return _0x2c9842;};'use strict';var BPromise=require(_0x6c5f('0x0'));var _=require('lodash');var fs=require('fs');var WebSocket=require('ws');var moment=require(_0x6c5f('0x1'));var crypto=require(_0x6c5f('0x2'));var logger=require(_0x6c5f('0x3'))(_0x6c5f('0x4'));module[_0x6c5f('0x5')]=function(_0x53d4c8,_0x1ca149,_0x4d04fe,_0x2c3fbe){return new BPromise(function(_0xf73deb,_0x4db694){logger['info'](_0x6c5f('0x6'),_0x2c3fbe||_0x6c5f('0x7'));var _0x4c85bb=new WebSocket(_0x2c3fbe||_0x6c5f('0x7'),{'perMessageDeflate':![]});var _0xcbb09c='';var _0x7c59f0='0';var _0x36d110='1';var _0x41770f='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';function _0x438f9e(_0x3d1618){var _0xe042ae=crypto[_0x6c5f('0x8')](_0x6c5f('0x9'));_0xe042ae['update'](_0x3d1618);return _0xe042ae[_0x6c5f('0xa')]('hex');}function _0x143df3(){try{logger[_0x6c5f('0xb')](_0x6c5f('0xc'));var _0x590de3=moment()[_0x6c5f('0xd')]();var _0x194c74=_0x438f9e(_0x590de3+_0x1ca149+_0x4d04fe);_0x4c85bb['send'](JSON[_0x6c5f('0xe')]({'appID':_0x1ca149,'timestamp':_0x590de3,'appKey':_0x194c74}));var _0x4db06f=fs[_0x6c5f('0xf')](_0x53d4c8);_0x4db06f['on'](_0x6c5f('0x10'),function(_0x55498d){_0x4c85bb['send'](_0x55498d);});_0x4db06f['on'](_0x6c5f('0x11'),function(){_0x4c85bb[_0x6c5f('0x12')](_0x6c5f('0x13'));});}catch(_0x1eb76d){logger['error'](_0x6c5f('0x14'),JSON[_0x6c5f('0xe')](_0x1eb76d));_0x4c85bb[_0x6c5f('0x15')]();}}function _0x337148(_0x2324b3){try{if(_0x2324b3){var _0x480f1b=JSON[_0x6c5f('0x16')](_0x2324b3);switch(_0x480f1b['status']){case 0x0:if(_0x480f1b['result']){if(_0x480f1b[_0x6c5f('0x17')]['final']){logger[_0x6c5f('0xb')](_0x6c5f('0x18'),JSON['stringify'](_0x480f1b[_0x6c5f('0x17')][_0x6c5f('0x19')]));_0xcbb09c=_0x480f1b[_0x6c5f('0x17')]['hypotheses'][0x0][_0x6c5f('0x1a')];_0x7c59f0=_0x480f1b[_0x6c5f('0x17')][_0x6c5f('0x19')][0x0]['likelihood'];_0x36d110='0';_0x41770f='Success.';_0x4c85bb[_0x6c5f('0x15')]();}}break;case 0x1:logger['info'](_0x6c5f('0x1b'));_0x36d110='1';_0x41770f=_0x6c5f('0x1b');break;case 0x2:logger[_0x6c5f('0xb')]('Aborted.\x20Recognition\x20was\x20aborted\x20for\x20some\x20reason.');_0x36d110='2';_0x41770f=_0x6c5f('0x1c');break;case 0x9:logger[_0x6c5f('0xb')]('Not\x20available.\x20Max\x20load\x20limit\x20reached.');_0x36d110='9';_0x41770f='Not\x20available.\x20Max\x20load\x20limit\x20reached.';break;case 0xa:logger[_0x6c5f('0xb')](_0x6c5f('0x1d'));_0x36d110='10';_0x41770f=_0x6c5f('0x1d');break;case 0xb:logger[_0x6c5f('0xb')](_0x6c5f('0x1e'));_0x36d110='11';_0x41770f=_0x6c5f('0x1e');}}}catch(_0x212b4d){logger['error'](_0x6c5f('0x1f'),JSON[_0x6c5f('0xe')](_0x212b4d));_0x4c85bb[_0x6c5f('0x15')]();}}function _0x48f376(){logger[_0x6c5f('0xb')]('Close\x20Tilde\x20ASR\x20socket');_0xf73deb({'transcript':_0xcbb09c,'confidence':_0x7c59f0,'status':_0x36d110,'status_message':_0x41770f});}function _0xe45e8b(_0x34d572){logger[_0x6c5f('0x20')](_0x6c5f('0x21'));if(!_[_0x6c5f('0x22')](_0x34d572)){logger['error'](_[_0x6c5f('0x23')](_0x34d572)?JSON['stringify'](_0x34d572):_0x34d572);}}_0x4c85bb['on']('open',_0x143df3);_0x4c85bb['on']('message',_0x337148);_0x4c85bb['on']('close',_0x48f376);_0x4c85bb['on'](_0x6c5f('0x20'),_0xe45e8b);});};