-->"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var Artyom=function(){function a(){this.ArtyomCommands=[],this.ArtyomVoicesIdentifiers={"de-DE":["Google Deutsch","de-DE","de_DE"],"es-ES":["Google espa\xF1ol","es-ES","es_ES","es-MX","es_MX"],"it-IT":["Google italiano","it-IT","it_IT"],"jp-JP":["Google \u65E5\u672C\u4EBA","ja-JP","ja_JP"],"en-US":["Google US English","en-US","en_US"],"en-GB":["Google UK English Male","Google UK English Female","en-GB","en_GB"],"pt-BR":["Google portugu\xEAs do Brasil","pt-PT","pt-BR","pt_PT","pt_BR"],"pt-PT":["Google portugu\xEAs do Brasil","pt-PT","pt_PT"],"ru-RU":["Google \u0440\u0443\u0441\u0441\u043A\u0438\u0439","ru-RU","ru_RU"],"nl-NL":["Google Nederlands","nl-NL","nl_NL"],"fr-FR":["Google fran\xE7ais","fr-FR","fr_FR"],"pl-PL":["Google polski","pl-PL","pl_PL"],"id-ID":["Google Bahasa Indonesia","id-ID","id_ID"],"hi-IN":["Google \u0939\u093F\u0928\u094D\u0926\u0940","hi-IN","hi_IN"],"zh-CN":["Google \u666E\u901A\u8BDD\uFF08\u4E2D\u56FD\u5927\u9646\uFF09","zh-CN","zh_CN"],"zh-HK":["Google \u7CA4\u8A9E\uFF08\u9999\u6E2F\uFF09","zh-HK","zh_HK"],native:["native"]},window.hasOwnProperty("speechSynthesis")?speechSynthesis.getVoices():console.error("Artyom.js can't speak without the Speech Synthesis API."),window.hasOwnProperty("webkitSpeechRecognition")?this.ArtyomWebkitSpeechRecognition=new window.webkitSpeechRecognition:console.error("Artyom.js can't recognize voice without the Speech Recognition API."),this.ArtyomProperties={lang:"en-GB",recognizing:!1,continuous:!1,speed:1,volume:1,listen:!1,mode:"normal",debug:!1,helpers:{redirectRecognizedTextOutput:null,remoteProcessorHandler:null,lastSay:null,fatalityPromiseCallback:null},executionKeyword:null,obeyKeyword:null,speaking:!1,obeying:!0,soundex:!1,name:null},this.ArtyomGarbageCollection=[],this.ArtyomFlags={restartRecognition:!1},this.ArtyomGlobalEvents={ERROR:"ERROR",SPEECH_SYNTHESIS_START:"SPEECH_SYNTHESIS_START",SPEECH_SYNTHESIS_END:"SPEECH_SYNTHESIS_END",TEXT_RECOGNIZED:"TEXT_RECOGNIZED",COMMAND_RECOGNITION_START:"COMMAND_RECOGNITION_START",COMMAND_RECOGNITION_END:"COMMAND_RECOGNITION_END",COMMAND_MATCHED:"COMMAND_MATCHED",NOT_COMMAND_MATCHED:"NOT_COMMAND_MATCHED"},this.Device={isMobile:!1,isChrome:!0},(navigator.userAgent.match(/Android/i)||navigator.userAgent.match(/webOS/i)||navigator.userAgent.match(/iPhone/i)||navigator.userAgent.match(/iPad/i)||navigator.userAgent.match(/iPod/i)||navigator.userAgent.match(/BlackBerry/i)||navigator.userAgent.match(/Windows Phone/i))&&(this.Device.isMobile=!0),-1==navigator.userAgent.indexOf("Chrome")&&(this.Device.isChrome=!1),this.ArtyomVoice={default:!1,lang:"en-GB",localService:!1,name:"Google UK English Male",voiceURI:"Google UK English Male"}}return a.prototype.addCommands=function(a){var b=this,c=function(a){a.hasOwnProperty("indexes")?b.ArtyomCommands.push(a):console.error("The given command doesn't provide any index to execute.")};if(a instanceof Array)for(var d=0;d> "+a);for(var d=0;d> REGEX "+e.toString()+" MATCHED AGAINST "+a+" WITH INDEX "+j+" IN COMMAND ","info"),h=parseInt(j.toString()));else if(-1!=e.indexOf("*")){var c=e.split("*");if(2> MATCHED FULL EXACT OPTION "+e+" AGAINST "+a+" WITH INDEX "+j+" IN COMMAND ","info"),h=parseInt(j.toString());break}else if(a.toLowerCase()===e.toLowerCase()){b.debug(">> MATCHED OPTION CHANGING ALL TO LOWERCASE "+e+" AGAINST "+a+" WITH INDEX "+j+" IN COMMAND ","info"),h=parseInt(j.toString());break}if(0<=h){b.triggerEvent(b.ArtyomGlobalEvents.COMMAND_MATCHED);var m={index:h,instruction:f};return m}}for(var d=0;d> MATCHED INDEX EXACT OPTION "+e+" AGAINST "+a+" WITH INDEX "+j+" IN COMMAND ","info"),h=parseInt(j.toString());break}else if(0<=a.toLowerCase().indexOf(e.toLowerCase())){b.debug(">> MATCHED INDEX OPTION CHANGING ALL TO LOWERCASE "+e+" AGAINST "+a+" WITH INDEX "+j+" IN COMMAND ","info"),h=parseInt(j.toString());break}}if(0<=h){b.triggerEvent(b.ArtyomGlobalEvents.COMMAND_MATCHED);var m={index:h,instruction:f};return m}}if(b.ArtyomProperties.soundex)for(var d=0;d> Matched Soundex command '"+e+"' AGAINST '"+a+"' with index "+j,"info"),h=parseInt(j.toString()),b.triggerEvent(b.ArtyomGlobalEvents.COMMAND_MATCHED);var m={index:h,instruction:f};return m}return b.debug("Event reached : "+b.ArtyomGlobalEvents.NOT_COMMAND_MATCHED),void b.triggerEvent(b.ArtyomGlobalEvents.NOT_COMMAND_MATCHED)},a.prototype.fatality=function(){var a=this;return new Promise(function(b,c){a.ArtyomProperties.helpers.fatalityPromiseCallback=b;try{a.ArtyomFlags.restartRecognition=!1,a.ArtyomWebkitSpeechRecognition.stop()}catch(a){c(a)}})},a.prototype.getAvailableCommands=function(){return this.ArtyomCommands},a.prototype.getVoices=function(){return window.speechSynthesis.getVoices()},a.prototype.speechSupported=function(){return"speechSynthesis"in window},a.prototype.recognizingSupported=function(){return"webkitSpeechRecognition"in window},a.prototype.shutUp=function(){if("speechSynthesis"in window)do window.speechSynthesis.cancel();while(!0===window.speechSynthesis.pending);this.ArtyomProperties.speaking=!1,this.clearGarbageCollection()},a.prototype.getProperties=function(){return this.ArtyomProperties},a.prototype.getLanguage=function(){return this.ArtyomProperties.lang},a.prototype.getVersion=function(){return"1.0.6"},a.prototype.hey=function(a,b){var c,d,e=this;this.Device.isMobile?(this.ArtyomWebkitSpeechRecognition.continuous=!1,this.ArtyomWebkitSpeechRecognition.interimResults=!1,this.ArtyomWebkitSpeechRecognition.maxAlternatives=1):(this.ArtyomWebkitSpeechRecognition.continuous=!0,this.ArtyomWebkitSpeechRecognition.interimResults=!0),this.ArtyomWebkitSpeechRecognition.lang=this.ArtyomProperties.lang,this.ArtyomWebkitSpeechRecognition.onstart=function(){e.debug("Event reached : "+e.ArtyomGlobalEvents.COMMAND_RECOGNITION_START),e.triggerEvent(e.ArtyomGlobalEvents.COMMAND_RECOGNITION_START),e.ArtyomProperties.recognizing=!0,d=!0,a()},this.ArtyomWebkitSpeechRecognition.onerror=function(a){b(a.error),e.triggerEvent(e.ArtyomGlobalEvents.ERROR,{code:a.error}),"audio-capture"==a.error&&(d=!1),"not-allowed"==a.error&&(d=!1,100>a.timeStamp-c?e.triggerEvent(e.ArtyomGlobalEvents.ERROR,{code:"info-blocked",message:"Artyom needs the permision of the microphone, is blocked."}):e.triggerEvent(e.ArtyomGlobalEvents.ERROR,{code:"info-denied",message:"Artyom needs the permision of the microphone, is denied"}))},e.ArtyomWebkitSpeechRecognition.onend=function(){!0===e.ArtyomFlags.restartRecognition?(!0===d?(e.ArtyomWebkitSpeechRecognition.start(),e.debug("Continuous mode enabled, restarting","info")):console.error("Verify the microphone and check for the table of errors in sdkcarlos.github.io/sites/artyom.html to solve your problem. If you want to give your user a message when an error appears add an artyom listener"),e.triggerEvent(e.ArtyomGlobalEvents.COMMAND_RECOGNITION_END,{code:"continuous_mode_enabled",message:"OnEnd event reached with continuous mode"})):e.ArtyomProperties.helpers.fatalityPromiseCallback&&(setTimeout(function(){e.ArtyomProperties.helpers.fatalityPromiseCallback()},500),e.triggerEvent(e.ArtyomGlobalEvents.COMMAND_RECOGNITION_END,{code:"continuous_mode_disabled",message:"OnEnd event reached without continuous mode"})),e.ArtyomProperties.recognizing=!1};var f;if("normal"==e.ArtyomProperties.mode&&(f=function(a){if(!e.ArtyomCommands.length)return void e.debug("No commands to process in normal mode.");var b=a.results.length;e.triggerEvent(e.ArtyomGlobalEvents.TEXT_RECOGNIZED);for(var c,d=a.resultIndex;d>","info"),e.ArtyomWebkitSpeechRecognition.stop(),e.ArtyomProperties.recognizing=!1,f.wildcard?f.instruction.action(f.index,f.wildcard.item,f.wildcard.full):f.instruction.action(f.index);break}}else{if("function"===typeof e.ArtyomProperties.helpers.redirectRecognizedTextOutput&&e.ArtyomProperties.helpers.redirectRecognizedTextOutput(c,!1),"string"===typeof e.ArtyomProperties.executionKeyword&&-1!=c.indexOf(e.ArtyomProperties.executionKeyword)){var f=e.execute(c.replace(e.ArtyomProperties.executionKeyword,"").trim());if(f&&!0==e.ArtyomProperties.recognizing){e.debug("<< Executing command ordered by ExecutionKeyword >>","info"),e.ArtyomWebkitSpeechRecognition.stop(),e.ArtyomProperties.recognizing=!1,f.wildcard?f.instruction.action(f.index,f.wildcard.item,f.wildcard.full):f.instruction.action(f.index);break}}e.debug("Normal mode : "+c)}}),"quick"==e.ArtyomProperties.mode&&(f=function(a){if(!e.ArtyomCommands.length)return void e.debug("No commands to process.");var b=a.results.length;e.triggerEvent(e.ArtyomGlobalEvents.TEXT_RECOGNIZED);for(var c,d=a.resultIndex;d>","info"),e.ArtyomWebkitSpeechRecognition.stop(),e.ArtyomProperties.recognizing=!1,f.wildcard?f.instruction.action(f.index,f.wildcard.item):f.instruction.action(f.index);break}}else{var f=e.execute(c.trim());if("function"===typeof e.ArtyomProperties.helpers.redirectRecognizedTextOutput&&e.ArtyomProperties.helpers.redirectRecognizedTextOutput(c,!1),f&&!0==e.ArtyomProperties.recognizing){e.debug("<< Executing Matching Recognition in quick mode >>","info"),e.ArtyomWebkitSpeechRecognition.stop(),e.ArtyomProperties.recognizing=!1,f.wildcard?f.instruction.action(f.index,f.wildcard.item):f.instruction.action(f.index);break}}e.debug("Quick mode : "+c)}}),"remote"==e.ArtyomProperties.mode&&(f=function(a){var b=a.results.length;if(e.triggerEvent(e.ArtyomGlobalEvents.TEXT_RECOGNIZED),"function"!==typeof e.ArtyomProperties.helpers.remoteProcessorHandler)return e.debug("The remoteProcessorService is undefined.","warn");for(var c,d=a.resultIndex;d=c&&f.addEventListener("end",function(){e.ArtyomProperties.speaking=!1,e.debug("Event reached : "+e.ArtyomGlobalEvents.SPEECH_SYNTHESIS_END),e.triggerEvent(e.ArtyomGlobalEvents.SPEECH_SYNTHESIS_END),d&&"function"==typeof d.onEnd&&d.onEnd.call(f)}),this.debug(b+" text chunk processed succesfully out of "+c),this.ArtyomGarbageCollection.push(f),window.speechSynthesis.speak(f)},a.prototype.say=function(a,b){var c=115,d=this,e=[];if(this.speechSupported()){if("string"!=typeof a)return console.warn("Artyom expects a string to speak "+typeof a+" given");if(!a.length)return console.warn("Cannot speak empty string");if(a.length>c){var f=a.split(/,|:|\. |;/);f.forEach(function(a){if(a.length>c){var b=d.splitStringByChunks(a,c);e.push.apply(e,b)}else e.push(a)})}else e.push(a);e=e.filter(function(a){return a}),e.forEach(function(a,c){a&&d.talk(a,c+1,e.length,b)}),d.ArtyomProperties.helpers.lastSay={text:a,date:new Date}}},a)}();exports.default=Artyom;