Built motion from commit (unavailable).|2.5.26
[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 _0x8d5e=['Error\x20Tilde\x20ASR\x20socket','isNil','isObject','open','message','bluebird','lodash','moment','../../../../../../config/logger','exports','Tilde\x20URI','wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE','createHash','sha1','update','digest','hex','info','Open\x20Tilde\x20ASR\x20socket','stringify','close','send','EOS','Tilde\x20ASR\x20send\x20error','terminate','status','result','hypotheses','transcript','likelihood','Success.','No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech','Aborted.\x20Recognition\x20was\x20aborted\x20for\x20some\x20reason.','Not\x20available.\x20Max\x20load\x20limit\x20reached.','error','Tilde\x20ASR\x20parse\x20error','Close\x20Tilde\x20ASR\x20socket'];(function(_0x4c11a3,_0x441c5d){var _0x5377ec=function(_0x866a2b){while(--_0x866a2b){_0x4c11a3['push'](_0x4c11a3['shift']());}};_0x5377ec(++_0x441c5d);}(_0x8d5e,0xe3));var _0xe8d5=function(_0x126558,_0x143c9a){_0x126558=_0x126558-0x0;var _0x1f6d14=_0x8d5e[_0x126558];return _0x1f6d14;};'use strict';var BPromise=require(_0xe8d5('0x0'));var _=require(_0xe8d5('0x1'));var fs=require('fs');var WebSocket=require('ws');var moment=require(_0xe8d5('0x2'));var crypto=require('crypto');var logger=require(_0xe8d5('0x3'))('agi');module[_0xe8d5('0x4')]=function(_0x4a8b4a,_0x39a9c0,_0x4636f1,_0x36a3c6){return new BPromise(function(_0x259103,_0x43684d){logger['info'](_0xe8d5('0x5'),_0x36a3c6||'wss://runa.tilde.lv/client/ws/speech/LVASR-ONLINE');var _0x51ad19=new WebSocket(_0x36a3c6||_0xe8d5('0x6'),{'perMessageDeflate':![]});var _0x557a0a='';var _0x57afe2='0';var _0x20d042='1';var _0x3dacee='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';function _0x2b33ad(_0x106ef2){var _0x55ab22=crypto[_0xe8d5('0x7')](_0xe8d5('0x8'));_0x55ab22[_0xe8d5('0x9')](_0x106ef2);return _0x55ab22[_0xe8d5('0xa')](_0xe8d5('0xb'));}function _0x543e50(){try{logger[_0xe8d5('0xc')](_0xe8d5('0xd'));var _0x54a082=moment()['unix']();var _0x4c9406=_0x2b33ad(_0x54a082+_0x39a9c0+_0x4636f1);_0x51ad19['send'](JSON[_0xe8d5('0xe')]({'appID':_0x39a9c0,'timestamp':_0x54a082,'appKey':_0x4c9406}));var _0x4f400c=fs['createReadStream'](_0x4a8b4a);_0x4f400c['on']('data',function(_0x54f86d){_0x51ad19['send'](_0x54f86d);});_0x4f400c['on'](_0xe8d5('0xf'),function(){_0x51ad19[_0xe8d5('0x10')](_0xe8d5('0x11'));});}catch(_0xee5d81){logger['error'](_0xe8d5('0x12'),JSON[_0xe8d5('0xe')](_0xee5d81));_0x51ad19[_0xe8d5('0x13')]();}}function _0x293bc7(_0x3ab7b8){try{if(_0x3ab7b8){var _0x3490c2=JSON['parse'](_0x3ab7b8);switch(_0x3490c2[_0xe8d5('0x14')]){case 0x0:if(_0x3490c2[_0xe8d5('0x15')]){if(_0x3490c2[_0xe8d5('0x15')]['final']){logger[_0xe8d5('0xc')]('Tilde\x20ASR\x20hypoteses',JSON[_0xe8d5('0xe')](_0x3490c2[_0xe8d5('0x15')][_0xe8d5('0x16')]));_0x557a0a=_0x3490c2[_0xe8d5('0x15')][_0xe8d5('0x16')][0x0][_0xe8d5('0x17')];_0x57afe2=_0x3490c2['result'][_0xe8d5('0x16')][0x0][_0xe8d5('0x18')];_0x20d042='0';_0x3dacee=_0xe8d5('0x19');_0x51ad19[_0xe8d5('0x13')]();}}break;case 0x1:logger[_0xe8d5('0xc')](_0xe8d5('0x1a'));_0x20d042='1';_0x3dacee='No\x20speech.\x20Sent\x20when\x20the\x20incoming\x20audio\x20contains\x20a\x20large\x20portion\x20of\x20silence\x20or\x20non-speech';break;case 0x2:logger[_0xe8d5('0xc')](_0xe8d5('0x1b'));_0x20d042='2';_0x3dacee=_0xe8d5('0x1b');break;case 0x9:logger[_0xe8d5('0xc')](_0xe8d5('0x1c'));_0x20d042='9';_0x3dacee=_0xe8d5('0x1c');break;case 0xa:logger['info']('Authentication\x20failed.');_0x20d042='10';_0x3dacee='Authentication\x20failed.';break;case 0xb:logger['info']('All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.');_0x20d042='11';_0x3dacee='All\x20recognition\x20workers\x20are\x20currently\x20in\x20use\x20and\x20real-time\x20recognition\x20is\x20not\x20possible.';}}}catch(_0x3f80b8){logger[_0xe8d5('0x1d')](_0xe8d5('0x1e'),JSON['stringify'](_0x3f80b8));_0x51ad19['terminate']();}}function _0x5b5c5a(){logger[_0xe8d5('0xc')](_0xe8d5('0x1f'));_0x259103({'transcript':_0x557a0a,'confidence':_0x57afe2,'status':_0x20d042,'status_message':_0x3dacee});}function _0x1f7710(_0x34364c){logger[_0xe8d5('0x1d')](_0xe8d5('0x20'));if(!_[_0xe8d5('0x21')](_0x34364c)){logger[_0xe8d5('0x1d')](_[_0xe8d5('0x22')](_0x34364c)?JSON[_0xe8d5('0xe')](_0x34364c):_0x34364c);}}_0x51ad19['on'](_0xe8d5('0x23'),_0x543e50);_0x51ad19['on'](_0xe8d5('0x24'),_0x293bc7);_0x51ad19['on']('close',_0x5b5c5a);_0x51ad19['on'](_0xe8d5('0x1d'),_0x1f7710);});};