0d63c4ccf25faddf25fa36b16983d9741c7a09a1
[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 _0xfbff=['EOS','stringify','terminate','status','result','final','Tilde\x20ASR\x20hypoteses','hypotheses','transcript','likelihood','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','Close\x20Tilde\x20ASR\x20socket','error','Error\x20Tilde\x20ASR\x20socket','isNil','isObject','open','bluebird','lodash','../../../../../../config/logger','exports','Tilde\x20URI','No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech','sha1','update','digest','hex','info','Open\x20Tilde\x20ASR\x20socket','createReadStream','data','send','close'];(function(_0x5d9946,_0x20d340){var _0xa8d586=function(_0x245652){while(--_0x245652){_0x5d9946['push'](_0x5d9946['shift']());}};_0xa8d586(++_0x20d340);}(_0xfbff,0x192));var _0xffbf=function(_0x9ea933,_0x565d76){_0x9ea933=_0x9ea933-0x0;var _0x4fdcd0=_0xfbff[_0x9ea933];return _0x4fdcd0;};'use strict';var BPromise=require(_0xffbf('0x0'));var _=require(_0xffbf('0x1'));var fs=require('fs');var WebSocket=require('ws');var moment=require('moment');var crypto=require('crypto');var logger=require(_0xffbf('0x2'))('agi');module[_0xffbf('0x3')]=function(_0x11d6d0,_0x4dd786,_0xf32129,_0x297fb0){return new BPromise(function(_0x47c635,_0x5e0a95){logger['info'](_0xffbf('0x4'),_0x297fb0||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE');var _0x19f78f=new WebSocket(_0x297fb0||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE',{'perMessageDeflate':![]});var _0x4fe75c='';var _0x43fd05='0';var _0x3840ff='1';var _0x451cb1=_0xffbf('0x5');function _0x58a65c(_0x4aae4c){var _0x299cda=crypto['createHash'](_0xffbf('0x6'));_0x299cda[_0xffbf('0x7')](_0x4aae4c);return _0x299cda[_0xffbf('0x8')](_0xffbf('0x9'));}function _0x536682(){try{logger[_0xffbf('0xa')](_0xffbf('0xb'));var _0x4a4f7b=moment()['unix']();var _0x5bb536=_0x58a65c(_0x4a4f7b+_0x4dd786+_0xf32129);_0x19f78f['send'](JSON['stringify']({'appID':_0x4dd786,'timestamp':_0x4a4f7b,'appKey':_0x5bb536}));var _0x290335=fs[_0xffbf('0xc')](_0x11d6d0);_0x290335['on'](_0xffbf('0xd'),function(_0x16e447){_0x19f78f[_0xffbf('0xe')](_0x16e447);});_0x290335['on'](_0xffbf('0xf'),function(){_0x19f78f[_0xffbf('0xe')](_0xffbf('0x10'));});}catch(_0x4ac8ae){logger['error']('Tilde\x20ASR\x20send\x20error',JSON[_0xffbf('0x11')](_0x4ac8ae));_0x19f78f[_0xffbf('0x12')]();}}function _0x512dbc(_0x379bf1){try{if(_0x379bf1){var _0x38392d=JSON['parse'](_0x379bf1);switch(_0x38392d[_0xffbf('0x13')]){case 0x0:if(_0x38392d[_0xffbf('0x14')]){if(_0x38392d[_0xffbf('0x14')][_0xffbf('0x15')]){logger[_0xffbf('0xa')](_0xffbf('0x16'),JSON['stringify'](_0x38392d['result'][_0xffbf('0x17')]));_0x4fe75c=_0x38392d['result'][_0xffbf('0x17')][0x0][_0xffbf('0x18')];_0x43fd05=_0x38392d['result'][_0xffbf('0x17')][0x0][_0xffbf('0x19')];_0x3840ff='0';_0x451cb1=_0xffbf('0x1a');_0x19f78f['terminate']();}}break;case 0x1:logger['info']('No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech');_0x3840ff='1';_0x451cb1=_0xffbf('0x5');break;case 0x2:logger[_0xffbf('0xa')](_0xffbf('0x1b'));_0x3840ff='2';_0x451cb1=_0xffbf('0x1b');break;case 0x9:logger[_0xffbf('0xa')](_0xffbf('0x1c'));_0x3840ff='9';_0x451cb1='Not\x20available.\x20Max\x20load\x20limit\x20reached.';break;case 0xa:logger['info']('Authentication\x20failed.');_0x3840ff='10';_0x451cb1=_0xffbf('0x1d');break;case 0xb:logger[_0xffbf('0xa')](_0xffbf('0x1e'));_0x3840ff='11';_0x451cb1=_0xffbf('0x1e');}}}catch(_0x32da5d){logger['error'](_0xffbf('0x1f'),JSON['stringify'](_0x32da5d));_0x19f78f[_0xffbf('0x12')]();}}function _0x6cc6d0(){logger[_0xffbf('0xa')](_0xffbf('0x20'));_0x47c635({'transcript':_0x4fe75c,'confidence':_0x43fd05,'status':_0x3840ff,'status_message':_0x451cb1});}function _0x2194e3(_0x2badf1){logger[_0xffbf('0x21')](_0xffbf('0x22'));if(!_[_0xffbf('0x23')](_0x2badf1)){logger[_0xffbf('0x21')](_[_0xffbf('0x24')](_0x2badf1)?JSON[_0xffbf('0x11')](_0x2badf1):_0x2badf1);}}_0x19f78f['on'](_0xffbf('0x25'),_0x536682);_0x19f78f['on']('message',_0x512dbc);_0x19f78f['on'](_0xffbf('0xf'),_0x6cc6d0);_0x19f78f['on'](_0xffbf('0x21'),_0x2194e3);});};