Built motion from commit 092f8824.|2.5.49
[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 _0xb0f5=['crypto','../../../../../../config/logger','agi','exports','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','Open\x20Tilde\x20ASR\x20socket','unix','send','stringify','close','terminate','parse','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.','error','Close\x20Tilde\x20ASR\x20socket','isNil','isObject','message','bluebird','lodash','moment'];(function(_0x5d5e89,_0x79d8af){var _0x524532=function(_0x290d85){while(--_0x290d85){_0x5d5e89['push'](_0x5d5e89['shift']());}};_0x524532(++_0x79d8af);}(_0xb0f5,0x99));var _0x5b0f=function(_0x68c979,_0x431cff){_0x68c979=_0x68c979-0x0;var _0x4f0001=_0xb0f5[_0x68c979];return _0x4f0001;};'use strict';var BPromise=require(_0x5b0f('0x0'));var _=require(_0x5b0f('0x1'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0x5b0f('0x2'));var crypto=require(_0x5b0f('0x3'));var logger=require(_0x5b0f('0x4'))(_0x5b0f('0x5'));module[_0x5b0f('0x6')]=function(_0x590051,_0x243cd8,_0x2caffb,_0x54c1d3){return new BPromise(function(_0x2852ac,_0x1caf4a){logger[_0x5b0f('0x7')](_0x5b0f('0x8'),_0x54c1d3||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE');var _0x1e5be8=new WebSocket(_0x54c1d3||_0x5b0f('0x9'),{'perMessageDeflate':![]});var _0x55f274='';var _0x4c5bc6='0';var _0x1a8ae5='1';var _0xaa2d33=_0x5b0f('0xa');function _0x2a5021(_0x6ab980){var _0xedd708=crypto[_0x5b0f('0xb')](_0x5b0f('0xc'));_0xedd708[_0x5b0f('0xd')](_0x6ab980);return _0xedd708[_0x5b0f('0xe')](_0x5b0f('0xf'));}function _0x516d11(){try{logger[_0x5b0f('0x7')](_0x5b0f('0x10'));var _0x12e27c=moment()[_0x5b0f('0x11')]();var _0x59e509=_0x2a5021(_0x12e27c+_0x243cd8+_0x2caffb);_0x1e5be8[_0x5b0f('0x12')](JSON[_0x5b0f('0x13')]({'appID':_0x243cd8,'timestamp':_0x12e27c,'appKey':_0x59e509}));var _0x16ade5=fs['createReadStream'](_0x590051);_0x16ade5['on']('data',function(_0x3bad03){_0x1e5be8[_0x5b0f('0x12')](_0x3bad03);});_0x16ade5['on'](_0x5b0f('0x14'),function(){_0x1e5be8[_0x5b0f('0x12')]('EOS');});}catch(_0x3e406a){logger['error']('Tilde\x20ASR\x20send\x20error',JSON[_0x5b0f('0x13')](_0x3e406a));_0x1e5be8[_0x5b0f('0x15')]();}}function _0x19a930(_0x672f58){try{if(_0x672f58){var _0x375c6c=JSON[_0x5b0f('0x16')](_0x672f58);switch(_0x375c6c[_0x5b0f('0x17')]){case 0x0:if(_0x375c6c[_0x5b0f('0x18')]){if(_0x375c6c[_0x5b0f('0x18')][_0x5b0f('0x19')]){logger[_0x5b0f('0x7')](_0x5b0f('0x1a'),JSON['stringify'](_0x375c6c[_0x5b0f('0x18')][_0x5b0f('0x1b')]));_0x55f274=_0x375c6c[_0x5b0f('0x18')][_0x5b0f('0x1b')][0x0][_0x5b0f('0x1c')];_0x4c5bc6=_0x375c6c[_0x5b0f('0x18')]['hypotheses'][0x0][_0x5b0f('0x1d')];_0x1a8ae5='0';_0xaa2d33=_0x5b0f('0x1e');_0x1e5be8[_0x5b0f('0x15')]();}}break;case 0x1:logger['info'](_0x5b0f('0xa'));_0x1a8ae5='1';_0xaa2d33=_0x5b0f('0xa');break;case 0x2:logger['info'](_0x5b0f('0x1f'));_0x1a8ae5='2';_0xaa2d33=_0x5b0f('0x1f');break;case 0x9:logger[_0x5b0f('0x7')](_0x5b0f('0x20'));_0x1a8ae5='9';_0xaa2d33=_0x5b0f('0x20');break;case 0xa:logger[_0x5b0f('0x7')]('Authentication\x20failed.');_0x1a8ae5='10';_0xaa2d33=_0x5b0f('0x21');break;case 0xb:logger[_0x5b0f('0x7')]('All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.');_0x1a8ae5='11';_0xaa2d33='All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.';}}}catch(_0x53fe09){logger[_0x5b0f('0x22')]('Tilde\x20ASR\x20parse\x20error',JSON['stringify'](_0x53fe09));_0x1e5be8[_0x5b0f('0x15')]();}}function _0x8078a2(){logger[_0x5b0f('0x7')](_0x5b0f('0x23'));_0x2852ac({'transcript':_0x55f274,'confidence':_0x4c5bc6,'status':_0x1a8ae5,'status_message':_0xaa2d33});}function _0x317e1b(_0x50c8a7){logger['error']('Error\x20Tilde\x20ASR\x20socket');if(!_[_0x5b0f('0x24')](_0x50c8a7)){logger[_0x5b0f('0x22')](_[_0x5b0f('0x25')](_0x50c8a7)?JSON['stringify'](_0x50c8a7):_0x50c8a7);}}_0x1e5be8['on']('open',_0x516d11);_0x1e5be8['on'](_0x5b0f('0x26'),_0x19a930);_0x1e5be8['on'](_0x5b0f('0x14'),_0x8078a2);_0x1e5be8['on'](_0x5b0f('0x22'),_0x317e1b);});};