Built motion from commit (unavailable).|2.4.18
[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 _0x5f1f=['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','hex','Open\x20Tilde\x20ASR\x20socket','send','stringify','data','close','EOS','error','Tilde\x20ASR\x20send\x20error','terminate','parse','status','result','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','Error\x20Tilde\x20ASR\x20socket','isNil','open','message','bluebird','lodash','moment','crypto','../../../../../../config/logger','exports','info'];(function(_0x31e45c,_0xbb07fd){var _0x3d3542=function(_0x4ffda7){while(--_0x4ffda7){_0x31e45c['push'](_0x31e45c['shift']());}};_0x3d3542(++_0xbb07fd);}(_0x5f1f,0x129));var _0xf5f1=function(_0x1e3c02,_0x5c07a2){_0x1e3c02=_0x1e3c02-0x0;var _0x4d26d7=_0x5f1f[_0x1e3c02];return _0x4d26d7;};'use strict';var BPromise=require(_0xf5f1('0x0'));var _=require(_0xf5f1('0x1'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0xf5f1('0x2'));var crypto=require(_0xf5f1('0x3'));var logger=require(_0xf5f1('0x4'))('agi');module[_0xf5f1('0x5')]=function(_0x47b53a,_0x4f885e,_0x45da6b,_0x5d32b7){return new BPromise(function(_0x4545df,_0xa0bca4){logger[_0xf5f1('0x6')]('Tilde\x20URI',_0x5d32b7||_0xf5f1('0x7'));var _0x3cbbe1=new WebSocket(_0x5d32b7||_0xf5f1('0x7'),{'perMessageDeflate':![]});var _0x1df8e9='';var _0x5c4845='0';var _0xcfcc6b='1';var _0x2f98d5=_0xf5f1('0x8');function _0x36de8e(_0x1c9096){var _0x5e8426=crypto[_0xf5f1('0x9')](_0xf5f1('0xa'));_0x5e8426['update'](_0x1c9096);return _0x5e8426['digest'](_0xf5f1('0xb'));}function _0x1b0268(){try{logger[_0xf5f1('0x6')](_0xf5f1('0xc'));var _0x839e7e=moment()['unix']();var _0x161005=_0x36de8e(_0x839e7e+_0x4f885e+_0x45da6b);_0x3cbbe1[_0xf5f1('0xd')](JSON[_0xf5f1('0xe')]({'appID':_0x4f885e,'timestamp':_0x839e7e,'appKey':_0x161005}));var _0x34224b=fs['createReadStream'](_0x47b53a);_0x34224b['on'](_0xf5f1('0xf'),function(_0x312e8e){_0x3cbbe1[_0xf5f1('0xd')](_0x312e8e);});_0x34224b['on'](_0xf5f1('0x10'),function(){_0x3cbbe1['send'](_0xf5f1('0x11'));});}catch(_0x15d73e){logger[_0xf5f1('0x12')](_0xf5f1('0x13'),JSON['stringify'](_0x15d73e));_0x3cbbe1[_0xf5f1('0x14')]();}}function _0x10f2d9(_0x567adc){try{if(_0x567adc){var _0x58e8fa=JSON[_0xf5f1('0x15')](_0x567adc);switch(_0x58e8fa[_0xf5f1('0x16')]){case 0x0:if(_0x58e8fa[_0xf5f1('0x17')]){if(_0x58e8fa[_0xf5f1('0x17')]['final']){logger[_0xf5f1('0x6')](_0xf5f1('0x18'),JSON['stringify'](_0x58e8fa[_0xf5f1('0x17')]['hypotheses']));_0x1df8e9=_0x58e8fa[_0xf5f1('0x17')][_0xf5f1('0x19')][0x0][_0xf5f1('0x1a')];_0x5c4845=_0x58e8fa[_0xf5f1('0x17')][_0xf5f1('0x19')][0x0][_0xf5f1('0x1b')];_0xcfcc6b='0';_0x2f98d5=_0xf5f1('0x1c');_0x3cbbe1[_0xf5f1('0x14')]();}}break;case 0x1:logger[_0xf5f1('0x6')](_0xf5f1('0x8'));_0xcfcc6b='1';_0x2f98d5=_0xf5f1('0x8');break;case 0x2:logger[_0xf5f1('0x6')](_0xf5f1('0x1d'));_0xcfcc6b='2';_0x2f98d5=_0xf5f1('0x1d');break;case 0x9:logger[_0xf5f1('0x6')](_0xf5f1('0x1e'));_0xcfcc6b='9';_0x2f98d5=_0xf5f1('0x1e');break;case 0xa:logger['info'](_0xf5f1('0x1f'));_0xcfcc6b='10';_0x2f98d5=_0xf5f1('0x1f');break;case 0xb:logger[_0xf5f1('0x6')](_0xf5f1('0x20'));_0xcfcc6b='11';_0x2f98d5=_0xf5f1('0x20');}}}catch(_0x691f1a){logger['error'](_0xf5f1('0x21'),JSON[_0xf5f1('0xe')](_0x691f1a));_0x3cbbe1[_0xf5f1('0x14')]();}}function _0x5c6539(){logger['info']('Close\x20Tilde\x20ASR\x20socket');_0x4545df({'transcript':_0x1df8e9,'confidence':_0x5c4845,'status':_0xcfcc6b,'status_message':_0x2f98d5});}function _0x1ffedc(_0x353d92){logger['error'](_0xf5f1('0x22'));if(!_[_0xf5f1('0x23')](_0x353d92)){logger[_0xf5f1('0x12')](_['isObject'](_0x353d92)?JSON[_0xf5f1('0xe')](_0x353d92):_0x353d92);}}_0x3cbbe1['on'](_0xf5f1('0x24'),_0x1b0268);_0x3cbbe1['on'](_0xf5f1('0x25'),_0x10f2d9);_0x3cbbe1['on'](_0xf5f1('0x10'),_0x5c6539);_0x3cbbe1['on'](_0xf5f1('0x12'),_0x1ffedc);});};