diff --git a/dist/annyang.js b/dist/annyang.js index 25745e5..6c9b562 100644 --- a/dist/annyang.js +++ b/dist/annyang.js @@ -381,16 +381,19 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol * var commands2 = {'hi': helloFunction}; * * annyang.addCommands(commands); - * annyang.addCommands(commands2); + * annyang.addCommands(commands2, 'Okay js'); + * // commands2 will listen for 'Okay js hi' * // annyang will now listen to all three commands * ```` * * @param {Object} commands - Commands that annyang should listen to + * @param {string} [commandPrefix] - Prefix command by a string (like "Ok Google") * @method addCommands * @see [Commands Object](#commands-object) */ - addCommands: function addCommands(commands) { + addCommands: function addCommands(commands, commandPrefix) { var cb; + commandPrefix = commandPrefix || ''; initIfNeeded(); @@ -399,10 +402,10 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol cb = root[commands[phrase]] || commands[phrase]; if (typeof cb === 'function') { // convert command to regex then register the command - registerCommand(commandToRegExp(phrase), cb, phrase); + registerCommand(commandToRegExp(commandPrefix + phrase), cb, commandPrefix + phrase); } else if ((typeof cb === 'undefined' ? 'undefined' : _typeof(cb)) === 'object' && cb.regexp instanceof RegExp) { // register the command - registerCommand(new RegExp(cb.regexp.source, 'i'), cb.callback, phrase); + registerCommand(new RegExp(commandPrefix + cb.regexp.source, 'i'), cb.callback, commandPrefix + phrase); } else { if (debugState) { logMessage('Can not register command: %c' + phrase, debugStyle); diff --git a/dist/annyang.js.map b/dist/annyang.js.map index e60fadc..4d89a45 100644 --- a/dist/annyang.js.map +++ b/dist/annyang.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/annyang.js"],"names":["root","factory","define","amd","annyang","module","exports","window","undefined","SpeechRecognition","webkitSpeechRecognition","mozSpeechRecognition","msSpeechRecognition","oSpeechRecognition","commandsList","recognition","callbacks","start","error","end","soundstart","result","resultMatch","resultNoMatch","errorNetwork","errorPermissionBlocked","errorPermissionDenied","autoRestart","lastStartedAt","autoRestartCount","debugState","debugStyle","pauseListening","isListening","optionalParam","optionalRegex","namedParam","splatParam","escapeRegExp","commandToRegExp","command","replace","match","optional","RegExp","invokeCallbacks","args","forEach","callback","apply","context","isInitialized","logMessage","text","extraParameters","indexOf","console","log","initIfNeeded","init","registerCommand","originalPhrase","push","parseResults","results","commandText","i","length","trim","j","l","currentCommand","exec","parameters","slice","commands","resetCommands","abort","maxAlternatives","continuous","location","protocol","lang","onstart","onsoundstart","onerror","event","Date","getTime","onend","timeSinceLastStart","setTimeout","paused","onresult","SpeechRecognitionResult","resultIndex","k","transcript","addCommands","options","e","message","pause","resume","debug","newState","setLanguage","language","cb","phrase","hasOwnProperty","regexp","source","removeCommands","commandsToRemove","Array","isArray","filter","addCallback","type","removeCallback","compareWithCallbackParameter","callbackType","getSpeechRecognizer","trigger","sentences"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACC,WAAUA,IAAV,EAAgBC,OAAhB,EAAyB;AACxB;;AACA,MAAI,OAAOC,MAAP,KAAkB,UAAlB,IAAgCA,OAAOC,GAA3C,EAAgD;AAAE;AAChDD,WAAO,EAAP,EAAW,YAAY;AACrB,aAAQF,KAAKI,OAAL,GAAeH,QAAQD,IAAR,CAAvB;AACD,KAFD;AAGD,GAJD,MAIO,IAAI,QAAOK,MAAP,yCAAOA,MAAP,OAAkB,QAAlB,IAA8BA,OAAOC,OAAzC,EAAkD;AAAE;AACzDD,WAAOC,OAAP,GAAiBL,QAAQD,IAAR,CAAjB;AACD,GAFM,MAEA;AAAE;AACPA,SAAKI,OAAL,GAAeH,QAAQD,IAAR,CAAf;AACD;AACF,CAXA,EAWC,OAAOO,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,YAXD,EAWgD,UAAUP,IAAV,EAAgBQ,SAAhB,EAA2B;AAC1E;;AAEA;;;;;;;;;;AAUA,MAAIJ,OAAJ;;AAEA;AACA,MAAIK,oBAAoBT,KAAKS,iBAAL,IACAT,KAAKU,uBADL,IAEAV,KAAKW,oBAFL,IAGAX,KAAKY,mBAHL,IAIAZ,KA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D;AAGA;AACA,WAAK,IAAI0E,YAAT,IAAyB1G,SAAzB,EAAoC;AAClC,YAAIA,UAAU8F,cAAV,CAAyBY,YAAzB,CAAJ,EAA4C;AAC1C;AACA,cAAIH,SAAS/G,SAAT,IAAsB+G,SAASG,YAAnC,EAAiD;AAC/C;AACA,gBAAI1E,aAAaxC,SAAjB,EAA4B;AACxBQ,wBAAU0G,YAAV,IAA0B,EAA1B;AACD,aAFH,MAES;AACL;AACA1G,wBAAU0G,YAAV,IAA0B1G,UAAU0G,YAAV,EAAwBL,MAAxB,CAA+BI,4BAA/B,CAA1B;AACH;AACF;AACF;AACF;AACF,KA3ZO;;AA6ZR;;;;;;;AAOAxF,iBAAa,uBAAW;AACtB,aAAOA,gBAAe,CAACD,cAAvB;AACD,KAtaO;;AAwaR;;;;;;;AAOA2F,yBAAqB,+BAAW;AAC9B,aAAO5G,WAAP;AACD,KAjbO;;AAmbR;;;;;;;;;;;;;;;;;;;AAmBA6G,aAAS,iBAASC,SAAT,EAAoB;AAC3B,UAAG,CAACzH,QAAQ6B,WAAR,EAAJ,EAA2B;AACzB,YAAIH,UAAJ,EAAgB;AACd,cAAI,CAACG,YAAL,EAAkB;AAChBmB,uBAAW,yCAAX;AACD,WAFD,MAEO;AACLA,uBAAW,qCAAX;AACD;AACF;AACD;AACD;;AAED,UAAI,CAAC+D,MAAMC,OAAN,CAAcS,SAAd,CAAL,EAA+B;AAC7BA,oBAAY,CAACA,SAAD,CAAZ;AACD;;AAED9D,mBAAa8D,SAAb;AACD;AAvdO,GAAV;;AA0dA,SAAOzH,OAAP;AAED,CAjmBA,CAAD;;AAmmBA","file":"annyang.js","sourcesContent":["//! annyang\n//! version : 2.6.0\n//! author : Tal Ater @TalAter\n//! license : MIT\n//! https://www.TalAter.com/annyang/\n(function (root, factory) {\n \"use strict\";\n if (typeof define === 'function' && define.amd) { // AMD + global\n define([], function () {\n return (root.annyang = factory(root));\n });\n } else if (typeof module === 'object' && module.exports) { // CommonJS\n module.exports = factory(root);\n } else { // Browser globals\n root.annyang = factory(root);\n }\n}(typeof window !== 'undefined' ? window : this, function (root, undefined) {\n \"use strict\";\n\n /**\n * # Quick Tutorial, Intro and Demos\n *\n * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/).\n *\n * For a more in-depth look at annyang, read on.\n *\n * # API Reference\n */\n\n var annyang;\n\n // Get the SpeechRecognition object, while handling browser prefixes\n var SpeechRecognition = root.SpeechRecognition ||\n root.webkitSpeechRecognition ||\n root.mozSpeechRecognition ||\n root.msSpeechRecognition ||\n root.oSpeechRecognition;\n\n // Check browser support\n // This is done as early as possible, to make it as fast as possible for unsupported browsers\n if (!SpeechRecognition) {\n return null;\n }\n\n var commandsList = [];\n var recognition;\n var callbacks = { start: [], error: [], end: [], soundstart: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] };\n var autoRestart;\n var lastStartedAt = 0;\n var autoRestartCount = 0;\n var debugState = false;\n var debugStyle = 'font-weight: bold; color: #00f;';\n var pauseListening = false;\n var isListening = false;\n\n // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license.\n var optionalParam = /\\s*\\((.*?)\\)\\s*/g;\n var optionalRegex = /(\\(\\?:[^)]+\\))\\?/g;\n var namedParam = /(\\(\\?)?:\\w+/g;\n var splatParam = /\\*\\w+/g;\n var escapeRegExp = /[\\-{}\\[\\]+?.,\\\\\\^$|#]/g;\n var commandToRegExp = function(command) {\n command = command.replace(escapeRegExp, '\\\\$&')\n .replace(optionalParam, '(?:$1)?')\n .replace(namedParam, function(match, optional) {\n return optional ? match : '([^\\\\s]+)';\n })\n .replace(splatParam, '(.*?)')\n .replace(optionalRegex, '\\\\s*$1?\\\\s*');\n return new RegExp('^' + command + '$', 'i');\n };\n\n // This method receives an array of callbacks to iterate over, and invokes each of them\n var invokeCallbacks = function(callbacks, ...args) {\n callbacks.forEach(function(callback) {\n callback.callback.apply(callback.context, args);\n });\n };\n\n var isInitialized = function() {\n return recognition !== undefined;\n };\n\n // method for logging in developer console when debug mode is on\n var logMessage = function(text, extraParameters) {\n if (text.indexOf('%c') === -1 && !extraParameters) {\n console.log(text);\n } else {\n console.log(text, extraParameters || debugStyle);\n }\n };\n\n var initIfNeeded = function() {\n if (!isInitialized()) {\n annyang.init({}, false);\n }\n };\n\n var registerCommand = function(command, callback, originalPhrase) {\n commandsList.push({ command, callback, originalPhrase });\n if (debugState) {\n logMessage('Command successfully loaded: %c'+originalPhrase, debugStyle);\n }\n };\n\n var parseResults = function(results) {\n invokeCallbacks(callbacks.result, results);\n var commandText;\n // go over each of the 5 results and alternative results received (we've set maxAlternatives to 5 above)\n for (let i = 0; i {\n for (let i = 0; i\n * var commands = {\n * // annyang will capture anything after a splat (*) and pass it to the function.\n * // e.g. saying \"Show me Batman and Robin\" will call showFlickr('Batman and Robin');\n * 'show me *tag': showFlickr,\n *\n * // A named variable is a one word variable, that can fit anywhere in your command.\n * // e.g. saying \"calculate October stats\" will call calculateStats('October');\n * 'calculate :month stats': calculateStats,\n *\n * // By defining a part of the following command as optional, annyang will respond\n * // to both: \"say hello to my little friend\" as well as \"say hello friend\"\n * 'say hello (to my little) friend': greeting\n * };\n *\n * var showFlickr = function(tag) {\n * var url = 'http://api.flickr.com/services/rest/?tags='+tag;\n * $.getJSON(url);\n * }\n *\n * var calculateStats = function(month) {\n * $('#stats').text('Statistics for '+month);\n * }\n *\n * var greeting = function() {\n * $('#greeting').text('Hello!');\n * }\n * \n * ````\n *\n * ### Using Regular Expressions in commands\n * For advanced commands, you can pass a regular expression object, instead of\n * a simple string command.\n *\n * This is done by passing an object containing two properties: `regexp`, and\n * `callback` instead of the function.\n *\n * #### Examples:\n * ````javascript\n * var calculateFunction = function(month) { console.log(month); }\n * var commands = {\n * // This example will accept any word as the \"month\"\n * 'calculate :month stats': calculateFunction,\n * // This example will only accept months which are at the start of a quarter\n * 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction}\n * }\n ````\n *\n */\n"]} \ No newline at end of file +{"version":3,"sources":["../src/annyang.js"],"names":["root","factory","define","amd","annyang","module","exports","window","undefined","SpeechRecognition","webkitSpeechRecognition","mozSpeechRecognition","msSpeechRecognition","oSpeechRecognition","commandsList","recognition","callbacks","start","error","end","soundstart","result","resultMatch","resultNoMatch","errorNetwork","errorPermissionBlocked","errorPermissionDenied","autoRestart","lastStartedAt","autoRestartCount","debugState","debugStyle","pauseListening","isListening","optionalParam","optionalRegex","namedParam","splatParam","escapeRegExp","commandToRegExp","command","replace","match","optional","RegExp","invokeCallbacks","args","forEach","callback","apply","context","isInitialized","logMessage","text","extraParameters","indexOf","console","log","initIfNeeded","init","registerCommand","originalPhrase","push","parseResults","results","commandText","i","length","trim","j","l","currentCommand","exec","parameters","slice","commands","resetCommands","abort","maxAlternatives","continuous","location","protocol","lang","onstart","onsoundstart","onerror","event","Date","getTime","onend","timeSinceLastStart","setTimeout","paused","onresult","SpeechRecognitionResult","resultIndex","k","transcript","addCommands","options","e","message","pause","resume","debug","newState","setLanguage","language","commandPrefix","cb","phrase","hasOwnProperty","regexp","source","removeCommands","commandsToRemove","Array","isArray","filter","addCallback","type","removeCallback","compareWithCallbackParameter","callbackType","getSpeechRecognizer","trigger","sentences"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACC,WAAUA,IAAV,EAAgBC,OAAhB,EAAyB;AACxB;;AACA,MAAI,OAAOC,MAAP,KAAkB,UAAlB,IAAgCA,OAAOC,GAA3C,EAAgD;AAAE;AAChDD,WAAO,EAAP,EAAW,YAAY;AACrB,aAAQF,KAAKI,OAAL,GAAeH,QAAQD,IAAR,CAAvB;AACD,KAFD;AAGD,GAJD,MAIO,IAAI,QAAOK,MAAP,yCAAOA,MAAP,OAAkB,QAAlB,IAA8BA,OAAOC,OAAzC,EAAkD;AAAE;AACzDD,WAAOC,OAAP,GAAiBL,QAAQD,IAAR,CAAjB;AACD,GAFM,MAEA;AAAE;AACPA,SAAKI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E,MAAMC,OAAN,CAAcS,SAAd,CAAL,EAA+B;AAC7BA,oBAAY,CAACA,SAAD,CAAZ;AACD;;AAED/D,mBAAa+D,SAAb;AACD;AA1dO,GAAV;;AA6dA,SAAO1H,OAAP;AAED,CApmBA,CAAD;;AAsmBA","file":"annyang.js","sourcesContent":["//! annyang\n//! version : 2.6.0\n//! author : Tal Ater @TalAter\n//! license : MIT\n//! https://www.TalAter.com/annyang/\n(function (root, factory) {\n \"use strict\";\n if (typeof define === 'function' && define.amd) { // AMD + global\n define([], function () {\n return (root.annyang = factory(root));\n });\n } else if (typeof module === 'object' && module.exports) { // CommonJS\n module.exports = factory(root);\n } else { // Browser globals\n root.annyang = factory(root);\n }\n}(typeof window !== 'undefined' ? window : this, function (root, undefined) {\n \"use strict\";\n\n /**\n * # Quick Tutorial, Intro and Demos\n *\n * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/).\n *\n * For a more in-depth look at annyang, read on.\n *\n * # API Reference\n */\n\n var annyang;\n\n // Get the SpeechRecognition object, while handling browser prefixes\n var SpeechRecognition = root.SpeechRecognition ||\n root.webkitSpeechRecognition ||\n root.mozSpeechRecognition ||\n root.msSpeechRecognition ||\n root.oSpeechRecognition;\n\n // Check browser support\n // This is done as early as possible, to make it as fast as possible for unsupported browsers\n if (!SpeechRecognition) {\n return null;\n }\n\n var commandsList = [];\n var recognition;\n var callbacks = { start: [], error: [], end: [], soundstart: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] };\n var autoRestart;\n var lastStartedAt = 0;\n var autoRestartCount = 0;\n var debugState = false;\n var debugStyle = 'font-weight: bold; color: #00f;';\n var pauseListening = false;\n var isListening = false;\n\n // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license.\n var optionalParam = /\\s*\\((.*?)\\)\\s*/g;\n var optionalRegex = /(\\(\\?:[^)]+\\))\\?/g;\n var namedParam = /(\\(\\?)?:\\w+/g;\n var splatParam = /\\*\\w+/g;\n var escapeRegExp = /[\\-{}\\[\\]+?.,\\\\\\^$|#]/g;\n var commandToRegExp = function(command) {\n command = command.replace(escapeRegExp, '\\\\$&')\n .replace(optionalParam, '(?:$1)?')\n .replace(namedParam, function(match, optional) {\n return optional ? match : '([^\\\\s]+)';\n })\n .replace(splatParam, '(.*?)')\n .replace(optionalRegex, '\\\\s*$1?\\\\s*');\n return new RegExp('^' + command + '$', 'i');\n };\n\n // This method receives an array of callbacks to iterate over, and invokes each of them\n var invokeCallbacks = function(callbacks, ...args) {\n callbacks.forEach(function(callback) {\n callback.callback.apply(callback.context, args);\n });\n };\n\n var isInitialized = function() {\n return recognition !== undefined;\n };\n\n // method for logging in developer console when debug mode is on\n var logMessage = function(text, extraParameters) {\n if (text.indexOf('%c') === -1 && !extraParameters) {\n console.log(text);\n } else {\n console.log(text, extraParameters || debugStyle);\n }\n };\n\n var initIfNeeded = function() {\n if (!isInitialized()) {\n annyang.init({}, false);\n }\n };\n\n var registerCommand = function(command, callback, originalPhrase) {\n commandsList.push({ command, callback, originalPhrase });\n if (debugState) {\n logMessage('Command successfully loaded: %c'+originalPhrase, debugStyle);\n }\n };\n\n var parseResults = function(results) {\n invokeCallbacks(callbacks.result, results);\n var commandText;\n // go over each of the 5 results and alternative results received (we've set maxAlternatives to 5 above)\n for (let i = 0; i {\n for (let i = 0; i\n * var commands = {\n * // annyang will capture anything after a splat (*) and pass it to the function.\n * // e.g. saying \"Show me Batman and Robin\" will call showFlickr('Batman and Robin');\n * 'show me *tag': showFlickr,\n *\n * // A named variable is a one word variable, that can fit anywhere in your command.\n * // e.g. saying \"calculate October stats\" will call calculateStats('October');\n * 'calculate :month stats': calculateStats,\n *\n * // By defining a part of the following command as optional, annyang will respond\n * // to both: \"say hello to my little friend\" as well as \"say hello friend\"\n * 'say hello (to my little) friend': greeting\n * };\n *\n * var showFlickr = function(tag) {\n * var url = 'http://api.flickr.com/services/rest/?tags='+tag;\n * $.getJSON(url);\n * }\n *\n * var calculateStats = function(month) {\n * $('#stats').text('Statistics for '+month);\n * }\n *\n * var greeting = function() {\n * $('#greeting').text('Hello!');\n * }\n * \n * ````\n *\n * ### Using Regular Expressions in commands\n * For advanced commands, you can pass a regular expression object, instead of\n * a simple string command.\n *\n * This is done by passing an object containing two properties: `regexp`, and\n * `callback` instead of the function.\n *\n * #### Examples:\n * ````javascript\n * var calculateFunction = function(month) { console.log(month); }\n * var commands = {\n * // This example will accept any word as the \"month\"\n * 'calculate :month stats': calculateFunction,\n * // This example will only accept months which are at the start of a quarter\n * 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction}\n * }\n ````\n *\n */\n"]} \ No newline at end of file diff --git a/dist/annyang.min.js b/dist/annyang.min.js index ea1bb21..4e0ebc5 100644 --- a/dist/annyang.min.js +++ b/dist/annyang.min.js @@ -4,4 +4,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -!function(a,b){"function"==typeof define&&define.amd?define([],function(){return a.annyang=b(a)}):"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports?module.exports=b(a):a.annyang=b(a)}("undefined"!=typeof window?window:void 0,function(a,b){var c,d=a.SpeechRecognition||a.webkitSpeechRecognition||a.mozSpeechRecognition||a.msSpeechRecognition||a.oSpeechRecognition;if(!d)return null;var e,f,g=[],h={start:[],error:[],end:[],soundstart:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},i=0,j=0,k=!1,l="font-weight: bold; color: #00f;",m=!1,n=!1,o=/\s*\((.*?)\)\s*/g,p=/(\(\?:[^)]+\))\?/g,q=/(\(\?)?:\w+/g,r=/\*\w+/g,s=/[\-{}\[\]+?.,\\\^$|#]/g,t=function(a){return a=a.replace(s,"\\$&").replace(o,"(?:$1)?").replace(q,function(a,b){return b?a:"([^\\s]+)"}).replace(r,"(.*?)").replace(p,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},u=function(a){for(var b=arguments.length,c=Array(b>1?b-1:0),d=1;d1&&arguments[1]!==b)||arguments[1];e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){n=!0,u(h.start)},e.onsoundstart=function(){u(h.soundstart)},e.onerror=function(a){switch(u(h.error,a),a.error){case"network":u(h.errorNetwork,a);break;case"not-allowed":case"service-not-allowed":f=!1,(new Date).getTime()-i<200?u(h.errorPermissionBlocked,a):u(h.errorPermissionDenied,a)}},e.onend=function(){if(n=!1,u(h.end),f){var a=(new Date).getTime()-i;j+=1,j%10===0&&k&&w("Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips."),a<1e3?setTimeout(function(){c.start({paused:m})},1e3-a):c.start({paused:m})}},e.onresult=function(a){if(m)return k&&w("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;d0&&arguments[0]!==b)||arguments[0];k=!!a},setLanguage:function(a){x(),e.lang=a},addCommands:function(b){var c;x();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)y(t(d),c,d);else{if(!("object"===("undefined"==typeof c?"undefined":_typeof(c))&&c.regexp instanceof RegExp)){k&&w("Can not register command: %c"+d,l);continue}y(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){a===b?g=[]:(a=Array.isArray(a)?a:[a],g=g.filter(function(b){for(var c=0;c1?b-1:0),d=1;d1&&arguments[1]!==b)||arguments[1];e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){n=!0,u(h.start)},e.onsoundstart=function(){u(h.soundstart)},e.onerror=function(a){switch(u(h.error,a),a.error){case"network":u(h.errorNetwork,a);break;case"not-allowed":case"service-not-allowed":f=!1,(new Date).getTime()-i<200?u(h.errorPermissionBlocked,a):u(h.errorPermissionDenied,a)}},e.onend=function(){if(n=!1,u(h.end),f){var a=(new Date).getTime()-i;j+=1,j%10===0&&k&&w("Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips."),a<1e3?setTimeout(function(){c.start({paused:m})},1e3-a):c.start({paused:m})}},e.onresult=function(a){if(m)return k&&w("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;d0&&arguments[0]!==b)||arguments[0];k=!!a},setLanguage:function(a){x(),e.lang=a},addCommands:function(b,c){var d;c=c||"",x();for(var e in b)if(b.hasOwnProperty(e))if(d=a[b[e]]||b[e],"function"==typeof d)y(t(c+e),d,c+e);else{if(!("object"===("undefined"==typeof d?"undefined":_typeof(d))&&d.regexp instanceof RegExp)){k&&w("Can not register command: %c"+e,l);continue}y(new RegExp(c+d.regexp.source,"i"),d.callback,c+e)}},removeCommands:function(a){a===b?g=[]:(a=Array.isArray(a)?a:[a],g=g.filter(function(b){for(var c=0;c1?b-1:0),d=1;d1&&arguments[1]!==b)||arguments[1];e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){n=!0,u(h.start)},e.onsoundstart=function(){u(h.soundstart)},e.onerror=function(a){switch(u(h.error,a),a.error){case"network":u(h.errorNetwork,a);break;case"not-allowed":case"service-not-allowed":f=!1,(new Date).getTime()-i<200?u(h.errorPermissionBlocked,a):u(h.errorPermissionDenied,a)}},e.onend=function(){if(n=!1,u(h.end),f){var a=(new Date).getTime()-i;j+=1,j%10===0&&k&&w("Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips."),a<1e3?setTimeout(function(){c.start({paused:m})},1e3-a):c.start({paused:m})}},e.onresult=function(a){if(m)return k&&w("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;d0&&arguments[0]!==b)||arguments[0];k=!!a},setLanguage:function(a){x(),e.lang=a},addCommands:function(b){var c;x();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)y(t(d),c,d);else{if(!("object"===("undefined"==typeof c?"undefined":_typeof(c))&&c.regexp instanceof RegExp)){k&&w("Can not register command: %c"+d,l);continue}y(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){a===b?g=[]:(a=Array.isArray(a)?a:[a],g=g.filter(function(b){for(var c=0;c1?b-1:0),d=1;d1&&arguments[1]!==b)||arguments[1];e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){n=!0,u(h.start)},e.onsoundstart=function(){u(h.soundstart)},e.onerror=function(a){switch(u(h.error,a),a.error){case"network":u(h.errorNetwork,a);break;case"not-allowed":case"service-not-allowed":f=!1,(new Date).getTime()-i<200?u(h.errorPermissionBlocked,a):u(h.errorPermissionDenied,a)}},e.onend=function(){if(n=!1,u(h.end),f){var a=(new Date).getTime()-i;j+=1,j%10===0&&k&&w("Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips."),a<1e3?setTimeout(function(){c.start({paused:m})},1e3-a):c.start({paused:m})}},e.onresult=function(a){if(m)return k&&w("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;d0&&arguments[0]!==b)||arguments[0];k=!!a},setLanguage:function(a){x(),e.lang=a},addCommands:function(b,c){var d;c=c||"",x();for(var e in b)if(b.hasOwnProperty(e))if(d=a[b[e]]||b[e],"function"==typeof d)y(t(c+e),d,c+e);else{if(!("object"===("undefined"==typeof d?"undefined":_typeof(d))&&d.regexp instanceof RegExp)){k&&w("Can not register command: %c"+e,l);continue}y(new RegExp(c+d.regexp.source,"i"),d.callback,c+e)}},removeCommands:function(a){a===b?g=[]:(a=Array.isArray(a)?a:[a],g=g.filter(function(b){for(var c=0;c1?b-1:0),d=1;d1&&arguments[1]!==b)||arguments[1];e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){n=!0,u(h.start)},e.onsoundstart=function(){u(h.soundstart)},e.onerror=function(a){switch(u(h.error,a),a.error){case"network":u(h.errorNetwork,a);break;case"not-allowed":case"service-not-allowed":f=!1,(new Date).getTime()-i<200?u(h.errorPermissionBlocked,a):u(h.errorPermissionDenied,a)}},e.onend=function(){if(n=!1,u(h.end),f){var a=(new Date).getTime()-i;j+=1,j%10===0&&k&&w("Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips."),a<1e3?setTimeout(function(){c.start({paused:m})},1e3-a):c.start({paused:m})}},e.onresult=function(a){if(m)return k&&w("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;d0&&arguments[0]!==b)||arguments[0];k=!!a},setLanguage:function(a){x(),e.lang=a},addCommands:function(b){var c;x();for(var d in b)if(b.hasOwnProperty(d))if(c=a[b[d]]||b[d],"function"==typeof c)y(t(d),c,d);else{if(!("object"===("undefined"==typeof c?"undefined":_typeof(c))&&c.regexp instanceof RegExp)){k&&w("Can not register command: %c"+d,l);continue}y(new RegExp(c.regexp.source,"i"),c.callback,d)}},removeCommands:function(a){a===b?g=[]:(a=Array.isArray(a)?a:[a],g=g.filter(function(b){for(var c=0;c1?b-1:0),d=1;d1&&arguments[1]!==b)||arguments[1];e&&e.abort&&e.abort(),e=new d,e.maxAlternatives=5,e.continuous="http:"===a.location.protocol,e.lang="en-US",e.onstart=function(){n=!0,u(h.start)},e.onsoundstart=function(){u(h.soundstart)},e.onerror=function(a){switch(u(h.error,a),a.error){case"network":u(h.errorNetwork,a);break;case"not-allowed":case"service-not-allowed":f=!1,(new Date).getTime()-i<200?u(h.errorPermissionBlocked,a):u(h.errorPermissionDenied,a)}},e.onend=function(){if(n=!1,u(h.end),f){var a=(new Date).getTime()-i;j+=1,j%10===0&&k&&w("Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips."),a<1e3?setTimeout(function(){c.start({paused:m})},1e3-a):c.start({paused:m})}},e.onresult=function(a){if(m)return k&&w("Speech heard, but annyang is paused"),!1;for(var b=a.results[a.resultIndex],c=[],d=0;d0&&arguments[0]!==b)||arguments[0];k=!!a},setLanguage:function(a){x(),e.lang=a},addCommands:function(b,c){var d;c=c||"",x();for(var e in b)if(b.hasOwnProperty(e))if(d=a[b[e]]||b[e],"function"==typeof d)y(t(c+e),d,c+e);else{if(!("object"===("undefined"==typeof d?"undefined":_typeof(d))&&d.regexp instanceof RegExp)){k&&w("Can not register command: %c"+e,l);continue}y(new RegExp(c+d.regexp.source,"i"),d.callback,c+e)}},removeCommands:function(a){a===b?g=[]:(a=Array.isArray(a)?a:[a],g=g.filter(function(b){for(var c=0;c