Built motion from commit (unavailable).|2.5.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 _0x5f4c=['Tilde\x20ASR\x20parse\x20error','Error\x20Tilde\x20ASR\x20socket','isNil','open','lodash','moment','crypto','../../../../../../config/logger','agi','info','Tilde\x20URI','wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE','No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech','createHash','sha1','update','digest','hex','unix','send','stringify','createReadStream','data','close','EOS','error','Tilde\x20ASR\x20send\x20error','terminate','parse','result','Tilde\x20ASR\x20hypoteses','hypotheses','transcript','likelihood','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.'];(function(_0x17e735,_0x328f40){var _0x1824d6=function(_0x4460fe){while(--_0x4460fe){_0x17e735['push'](_0x17e735['shift']());}};_0x1824d6(++_0x328f40);}(_0x5f4c,0x1f2));var _0xc5f4=function(_0x465028,_0x4570ac){_0x465028=_0x465028-0x0;var _0xb783d4=_0x5f4c[_0x465028];return _0xb783d4;};'use strict';var BPromise=require('bluebird');var _=require(_0xc5f4('0x0'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0xc5f4('0x1'));var crypto=require(_0xc5f4('0x2'));var logger=require(_0xc5f4('0x3'))(_0xc5f4('0x4'));module['exports']=function(_0x54e25a,_0xb100a9,_0x4b1bee,_0x2443db){return new BPromise(function(_0x3a5bfd,_0x43fef0){logger[_0xc5f4('0x5')](_0xc5f4('0x6'),_0x2443db||_0xc5f4('0x7'));var _0x25bb57=new WebSocket(_0x2443db||_0xc5f4('0x7'),{'perMessageDeflate':![]});var _0x13e63e='';var _0x125395='0';var _0x35e955='1';var _0x3a444d=_0xc5f4('0x8');function _0x10d830(_0x4974b0){var _0x56d8e3=crypto[_0xc5f4('0x9')](_0xc5f4('0xa'));_0x56d8e3[_0xc5f4('0xb')](_0x4974b0);return _0x56d8e3[_0xc5f4('0xc')](_0xc5f4('0xd'));}function _0x46fa61(){try{logger[_0xc5f4('0x5')]('Open\x20Tilde\x20ASR\x20socket');var _0x443add=moment()[_0xc5f4('0xe')]();var _0x380546=_0x10d830(_0x443add+_0xb100a9+_0x4b1bee);_0x25bb57[_0xc5f4('0xf')](JSON[_0xc5f4('0x10')]({'appID':_0xb100a9,'timestamp':_0x443add,'appKey':_0x380546}));var _0x5e7d7c=fs[_0xc5f4('0x11')](_0x54e25a);_0x5e7d7c['on'](_0xc5f4('0x12'),function(_0xe9ad41){_0x25bb57[_0xc5f4('0xf')](_0xe9ad41);});_0x5e7d7c['on'](_0xc5f4('0x13'),function(){_0x25bb57[_0xc5f4('0xf')](_0xc5f4('0x14'));});}catch(_0x1d7bbf){logger[_0xc5f4('0x15')](_0xc5f4('0x16'),JSON[_0xc5f4('0x10')](_0x1d7bbf));_0x25bb57[_0xc5f4('0x17')]();}}function _0x1cb504(_0x214a4f){try{if(_0x214a4f){var _0x3e5e1b=JSON[_0xc5f4('0x18')](_0x214a4f);switch(_0x3e5e1b['status']){case 0x0:if(_0x3e5e1b[_0xc5f4('0x19')]){if(_0x3e5e1b[_0xc5f4('0x19')]['final']){logger[_0xc5f4('0x5')](_0xc5f4('0x1a'),JSON[_0xc5f4('0x10')](_0x3e5e1b[_0xc5f4('0x19')]['hypotheses']));_0x13e63e=_0x3e5e1b[_0xc5f4('0x19')][_0xc5f4('0x1b')][0x0][_0xc5f4('0x1c')];_0x125395=_0x3e5e1b[_0xc5f4('0x19')]['hypotheses'][0x0][_0xc5f4('0x1d')];_0x35e955='0';_0x3a444d='Success.';_0x25bb57[_0xc5f4('0x17')]();}}break;case 0x1:logger['info'](_0xc5f4('0x8'));_0x35e955='1';_0x3a444d=_0xc5f4('0x8');break;case 0x2:logger[_0xc5f4('0x5')]('Aborted.\x20Recognition\x20was\x20aborted\x20for\x20some\x20reason.');_0x35e955='2';_0x3a444d=_0xc5f4('0x1e');break;case 0x9:logger['info'](_0xc5f4('0x1f'));_0x35e955='9';_0x3a444d=_0xc5f4('0x1f');break;case 0xa:logger[_0xc5f4('0x5')](_0xc5f4('0x20'));_0x35e955='10';_0x3a444d='Authentication\x20failed.';break;case 0xb:logger[_0xc5f4('0x5')](_0xc5f4('0x21'));_0x35e955='11';_0x3a444d=_0xc5f4('0x21');}}}catch(_0x264a73){logger[_0xc5f4('0x15')](_0xc5f4('0x22'),JSON[_0xc5f4('0x10')](_0x264a73));_0x25bb57[_0xc5f4('0x17')]();}}function _0x3d8a2b(){logger[_0xc5f4('0x5')]('Close\x20Tilde\x20ASR\x20socket');_0x3a5bfd({'transcript':_0x13e63e,'confidence':_0x125395,'status':_0x35e955,'status_message':_0x3a444d});}function _0x4a0122(_0x2085ca){logger[_0xc5f4('0x15')](_0xc5f4('0x23'));if(!_[_0xc5f4('0x24')](_0x2085ca)){logger['error'](_['isObject'](_0x2085ca)?JSON[_0xc5f4('0x10')](_0x2085ca):_0x2085ca);}}_0x25bb57['on'](_0xc5f4('0x25'),_0x46fa61);_0x25bb57['on']('message',_0x1cb504);_0x25bb57['on'](_0xc5f4('0x13'),_0x3d8a2b);_0x25bb57['on']('error',_0x4a0122);});};