From f011e20a1facd0f95ad9980f83306ef5b32d8cb1 Mon Sep 17 00:00:00 2001 From: Nikhilesh Katakam Date: Fri, 16 Jan 2015 12:12:46 -0800 Subject: [PATCH 1/9] Adding pause and resume methods Consider a scenario where annyang is in listening mode and is executing a command callback function, and within the command we are using speechsynthesis to speak out a particular text, if the text in the speach matches with one of the registered annyang command, it would cause that command to be executed. See the code below Ideally, it would be nice if we could pause annyang when speachSynthesis is active mode and resume it when the speachSynthesis ends as shown below This PR implements a simple solution to achieve this. Please suggest if there is a better way of doing this. --- annyang.js | 23 +++ annyang.min.js | 2 +- docs/README.md | 329 ++++++------------------------------------ sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 5 files changed, 71 insertions(+), 287 deletions(-) diff --git a/annyang.js b/annyang.js index eea2678..88bfb65 100644 --- a/annyang.js +++ b/annyang.js @@ -41,6 +41,7 @@ var lastStartedAt = 0; var debugState = false; var debugStyle = 'font-weight: bold; color: #00f;'; + var pauseListening = false; // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license. var optionalParam = /\s*\((.*?)\)\s*/g; @@ -163,6 +164,10 @@ }; recognition.onresult = function(event) { + if(pauseListening) { + return; + } + invokeCallbacks(callbacks.result); var results = event.results[event.resultIndex]; var commandText; @@ -264,6 +269,24 @@ } }, + /** + * Pause listening and prevents command callback execution when a result matches. + * + * @method pause + */ + pause: function() { + pauseListening = true; + }, + + /** + * Resumes listening and restores command callback execution when a result matches. + * + * @method resume + */ + resume: function() { + pauseListening = false; + }, + /** * Set the language the user will speak in. If this method is not called, defaults to 'en-US'. * diff --git a/annyang.min.js b/annyang.min.js index 0869435..4c3754c 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=/\s*\((.*?)\)\s*/g,l=/(\(\?:[^)]+\))\?/g,m=/(\(\?)?:\w+/g,n=/\*\w+/g,o=/[\-{}\[\]+?.,\\\^$|#]/g,p=function(a){return a=a.replace(o,"\\$&").replace(k,"(?:$1)?").replace(m,function(a,b){return b?a:"([^\\s]+)"}).replace(n,"(.*?)").replace(l,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},q=function(a){a.forEach(function(a){a.callback.apply(a.context)})},r=function(){s()||b.annyang.init({},!1)},s=function(){return d!==a};b.annyang={init:function(k,l){l=l===a?!0:!!l,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){q(g.start)},d.onerror=function(a){switch(q(g.error),a.error){case"network":q(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,q((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(q(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){q(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var l=f[h].command.exec(c);if(l){var m=l.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),m.length&&b.console.log("with parameters",m)),f[h].callback.apply(this,m),q(g.resultMatch),!0}}}return q(g.resultNoMatch),!1},l&&(f=[]),k.length&&this.addCommands(k)},start:function(b){r(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,s&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){r(),d.lang=a},addCommands:function(a){var c,d;r();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=p(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(!k){r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1}},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c + - + + + + +## () + +## + + -# Quick Tutorial, Intro and Demos - -The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). - -For a more in-depth look at annyang, read on. - -# API Reference - -## init(commands, [resetCommands=true]) - -Initialize annyang with a list of commands to recognize. - -### Examples: - - var commands = {'hello :name': helloFunction}; - var commands2 = {'hi': helloFunction}; - - // initialize annyang, overwriting any previously added commands - annyang.init(commands, true); - // adds an additional command without removing the previous commands - annyang.init(commands2, false); - -As of v1.1.0 it is no longer required to call init(). Just start() listening whenever you want, and addCommands() whenever, and as often as you like. + + **Deprecated** - -See: [Commands Object](#commands-object) - -### Params: - -* **Object** *commands* - Commands that annyang should listen to -* **Boolean** *[resetCommands=true]* - Remove all commands before initializing? - -## start([options]) - -Start listening. -It's a good idea to call this after adding some commands first, but not mandatory. - -Receives an optional options object which supports the following options: -- `autoRestart` (Boolean, default: true) Should annyang restart itself if it is closed indirectly, because of silence or window conflicts? -- `continuous` (Boolean, default: undefined) Allow forcing continuous mode on or off. Annyang is pretty smart about this, so only set this if you know what you're doing. - -### Examples: - // Start listening, don't restart automatically - annyang.start({ autoRestart: false }); - // Start listening, don't restart automatically, stop recognition after first phrase recognized - annyang.start({ autoRestart: false, continuous: false }); - -### Params: - -* **Object** *[options]* - Optional options. - -## abort() - -Stop listening. - -## debug([newState=true]) - -Turn on output of debug messages to the console. Ugly, but super-handy! - -### Params: - -* **Boolean** *[newState=true]* - Turn on/off debug messages - -## setLanguage(language) - -Set the language the user will speak in. If this method is not called, defaults to 'en-US'. - -See: [Languages](#languages) - -### Params: - -* **String** *language* - The language (locale) - -## addCommands(commands) - -Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands. - -### Examples: - - var commands = {'hello :name': helloFunction, 'howdy': helloFunction}; - var commands2 = {'hi': helloFunction}; - - annyang.addCommands(commands); - annyang.addCommands(commands2); - // annyang will now listen to all three commands - -See: [Commands Object](#commands-object) - -### Params: - -* **Object** *commands* - Commands that annyang should listen to - -## removeCommands([commandsToRemove]) - -Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands. - -### Examples: - - var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction}; - - // Remove all existing commands - annyang.removeCommands(); - - // Add some commands - annyang.addCommands(commands); - - // Don't respond to hello - annyang.removeCommands('hello'); - - // Don't respond to howdy or hi - annyang.removeCommands(['howdy', 'hi']); - -### Params: - -* **String|Array|Undefined** *[commandsToRemove]* - Commands to remove - -## addCallback(type, callback, [context]) - -Add a callback function to be called in case one of the following events happens: - -start, error, end, result, resultMatch, resultNoMatch, errorNetwork, errorPermissionBlocked, errorPermissionDenied. - -### Examples: - - annyang.addCallback('error', function () { - $('.myErrorText').text('There was an error!'); - }); - - // pass local context to a global function called notConnected - annyang.addCallback('errorNetwork', notConnected, this); - -### Params: - -* **String** *type* - Name of event that will trigger this callback -* **Function** *callback* - The function to call when event is triggered -* **Object** *[context]* - Optional context for the callback function - -# Good to Know - -## Commands Object - -Both the [init()]() and addCommands() methods receive a `commands` object. - -annyang understands commands with `named variables`, `splats`, and `optional words`. - -* Use `named variables` for one word arguments in your command. -* Use `splats` to capture multi-word text at the end of your command (greedy). -* Use `optional words` or phrases to define a part of the command as optional. - -### Examples: - - - -## Languages - -While there isn't an official list of supported languages (cultures? locales?), here is a list based on [anecdotal evidence](http://stackoverflow.com/a/14302134/338039). - -* Afrikaans `af` -* Basque `eu` -* Bulgarian `bg` -* Catalan `ca` -* Arabic (Egypt) `ar-EG` -* Arabic (Jordan) `ar-JO` -* Arabic (Kuwait) `ar-KW` -* Arabic (Lebanon) `ar-LB` -* Arabic (Qatar) `ar-QA` -* Arabic (UAE) `ar-AE` -* Arabic (Morocco) `ar-MA` -* Arabic (Iraq) `ar-IQ` -* Arabic (Algeria) `ar-DZ` -* Arabic (Bahrain) `ar-BH` -* Arabic (Lybia) `ar-LY` -* Arabic (Oman) `ar-OM` -* Arabic (Saudi Arabia) `ar-SA` -* Arabic (Tunisia) `ar-TN` -* Arabic (Yemen) `ar-YE` -* Czech `cs` -* Dutch `nl-NL` -* English (Australia) `en-AU` -* English (Canada) `en-CA` -* English (India) `en-IN` -* English (New Zealand) `en-NZ` -* English (South Africa) `en-ZA` -* English(UK) `en-GB` -* English(US) `en-US` -* Finnish `fi` -* French `fr-FR` -* Galician `gl` -* German `de-DE` -* Hebrew `he` -* Hungarian `hu` -* Icelandic `is` -* Italian `it-IT` -* Indonesian `id` -* Japanese `ja` -* Korean `ko` -* Latin `la` -* Mandarin Chinese `zh-CN` -* Traditional Taiwan `zh-TW` -* Simplified China zh-CN `?` -* Simplified Hong Kong `zh-HK` -* Yue Chinese (Traditional Hong Kong) `zh-yue` -* Malaysian `ms-MY` -* Norwegian `no-NO` -* Polish `pl` -* Pig Latin `xx-piglatin` -* Portuguese `pt-PT` -* Portuguese (Brasil) `pt-BR` -* Romanian `ro-RO` -* Russian `ru` -* Serbian `sr-SP` -* Slovak `sk` -* Spanish (Argentina) `es-AR` -* Spanish (Bolivia) `es-BO` -* Spanish (Chile) `es-CL` -* Spanish (Colombia) `es-CO` -* Spanish (Costa Rica) `es-CR` -* Spanish (Dominican Republic) `es-DO` -* Spanish (Ecuador) `es-EC` -* Spanish (El Salvador) `es-SV` -* Spanish (Guatemala) `es-GT` -* Spanish (Honduras) `es-HN` -* Spanish (Mexico) `es-MX` -* Spanish (Nicaragua) `es-NI` -* Spanish (Panama) `es-PA` -* Spanish (Paraguay) `es-PY` -* Spanish (Peru) `es-PE` -* Spanish (Puerto Rico) `es-PR` -* Spanish (Spain) `es-ES` -* Spanish (US) `es-US` -* Spanish (Uruguay) `es-UY` -* Spanish (Venezuela) `es-VE` -* Swedish `sv-SE` -* Turkish `tr` -* Zulu `zu` - -## Developing - -Prerequisities: node.js - -First, install dependencies in your local annyang copy: - - npm install - -Make sure to run the default grunt task after each change to annyang.js. This can also be done automatically by running: - - grunt watch - -You can also run a local server for testing your work with: - - grunt dev - -Point your browser to `https://localhost:8443/demo/` to see the demo page. -Since it's using self-signed certificate, you might need to click *"Proceed Anyway"*. - - - + + + +Author: + + + +Version: + + + +See: + + + 0) { ?> +### Params: + +* **** ** + + + 0) { ?> +### Return: + +* **** + + + + + + + + \ No newline at end of file diff --git a/sites/facebook.min.js b/sites/facebook.min.js index daef81b..4c1101d 100644 --- a/sites/facebook.min.js +++ b/sites/facebook.min.js @@ -3,7 +3,7 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=/\s*\((.*?)\)\s*/g,l=/(\(\?:[^)]+\))\?/g,m=/(\(\?)?:\w+/g,n=/\*\w+/g,o=/[\-{}\[\]+?.,\\\^$|#]/g,p=function(a){return a=a.replace(o,"\\$&").replace(k,"(?:$1)?").replace(m,function(a,b){return b?a:"([^\\s]+)"}).replace(n,"(.*?)").replace(l,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},q=function(a){a.forEach(function(a){a.callback.apply(a.context)})},r=function(){s()||b.annyang.init({},!1)},s=function(){return d!==a};b.annyang={init:function(k,l){l=l===a?!0:!!l,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){q(g.start)},d.onerror=function(a){switch(q(g.error),a.error){case"network":q(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,q((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(q(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){q(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var l=f[h].command.exec(c);if(l){var m=l.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),m.length&&b.console.log("with parameters",m)),f[h].callback.apply(this,m),q(g.resultMatch),!0}}}return q(g.resultNoMatch),!1},l&&(f=[]),k.length&&this.addCommands(k)},start:function(b){r(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,s&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){r(),d.lang=a},addCommands:function(a){var c,d;r();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=p(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(!k){r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1}},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){q(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var l=f[h].command.exec(c);if(l){var m=l.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),m.length&&b.console.log("with parameters",m)),f[h].callback.apply(this,m),q(g.resultMatch),!0}}}return q(g.resultNoMatch),!1},l&&(f=[]),k.length&&this.addCommands(k)},start:function(b){r(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,s&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){r(),d.lang=a},addCommands:function(a){var c,d;r();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=p(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(!k){r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1}},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c Date: Sun, 8 Feb 2015 22:20:08 +0200 Subject: [PATCH 2/9] Rebuilt README --- docs/README.md | 337 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 292 insertions(+), 45 deletions(-) diff --git a/docs/README.md b/docs/README.md index c059a5f..e4ab012 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,50 +1,297 @@ - - - - - - -## () - -## - - + - +# Quick Tutorial, Intro and Demos + +The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). + +For a more in-depth look at annyang, read on. + +# API Reference + +## init(commands, [resetCommands=true]) + +Initialize annyang with a list of commands to recognize. + +### Examples: + + var commands = {'hello :name': helloFunction}; + var commands2 = {'hi': helloFunction}; + + // initialize annyang, overwriting any previously added commands + annyang.init(commands, true); + // adds an additional command without removing the previous commands + annyang.init(commands2, false); + +As of v1.1.0 it is no longer required to call init(). Just start() listening whenever you want, and addCommands() whenever, and as often as you like. - **Deprecated** - - - -Author: - - - -Version: - - - -See: - - - 0) { ?> -### Params: - -* **** ** - - - 0) { ?> -### Return: - -* **** - - - - - - - - \ No newline at end of file + +See: [Commands Object](#commands-object) + +### Params: + +* **Object** *commands* - Commands that annyang should listen to +* **Boolean** *[resetCommands=true]* - Remove all commands before initializing? + +## start([options]) + +Start listening. +It's a good idea to call this after adding some commands first, but not mandatory. + +Receives an optional options object which supports the following options: +- `autoRestart` (Boolean, default: true) Should annyang restart itself if it is closed indirectly, because of silence or window conflicts? +- `continuous` (Boolean, default: undefined) Allow forcing continuous mode on or off. Annyang is pretty smart about this, so only set this if you know what you're doing. + +### Examples: + // Start listening, don't restart automatically + annyang.start({ autoRestart: false }); + // Start listening, don't restart automatically, stop recognition after first phrase recognized + annyang.start({ autoRestart: false, continuous: false }); + +### Params: + +* **Object** *[options]* - Optional options. + +## abort() + +Stop listening. + +## debug([newState=true]) + +Turn on output of debug messages to the console. Ugly, but super-handy! + +### Params: + +* **Boolean** *[newState=true]* - Turn on/off debug messages + +## pause() + +Pause listening and prevents command callback execution when a result matches. + +## resume() + +Resumes listening and restores command callback execution when a result matches. + +## setLanguage(language) + +Set the language the user will speak in. If this method is not called, defaults to 'en-US'. + +See: [Languages](#languages) + +### Params: + +* **String** *language* - The language (locale) + +## addCommands(commands) + +Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands. + +### Examples: + + var commands = {'hello :name': helloFunction, 'howdy': helloFunction}; + var commands2 = {'hi': helloFunction}; + + annyang.addCommands(commands); + annyang.addCommands(commands2); + // annyang will now listen to all three commands + +See: [Commands Object](#commands-object) + +### Params: + +* **Object** *commands* - Commands that annyang should listen to + +## removeCommands([commandsToRemove]) + +Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands. + +### Examples: + + var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction}; + + // Remove all existing commands + annyang.removeCommands(); + + // Add some commands + annyang.addCommands(commands); + + // Don't respond to hello + annyang.removeCommands('hello'); + + // Don't respond to howdy or hi + annyang.removeCommands(['howdy', 'hi']); + +### Params: + +* **String|Array|Undefined** *[commandsToRemove]* - Commands to remove + +## addCallback(type, callback, [context]) + +Add a callback function to be called in case one of the following events happens: + +start, error, end, result, resultMatch, resultNoMatch, errorNetwork, errorPermissionBlocked, errorPermissionDenied. + +### Examples: + + annyang.addCallback('error', function () { + $('.myErrorText').text('There was an error!'); + }); + + // pass local context to a global function called notConnected + annyang.addCallback('errorNetwork', notConnected, this); + +### Params: + +* **String** *type* - Name of event that will trigger this callback +* **Function** *callback* - The function to call when event is triggered +* **Object** *[context]* - Optional context for the callback function + +# Good to Know + +## Commands Object + +Both the [init()]() and addCommands() methods receive a `commands` object. + +annyang understands commands with `named variables`, `splats`, and `optional words`. + +* Use `named variables` for one word arguments in your command. +* Use `splats` to capture multi-word text at the end of your command (greedy). +* Use `optional words` or phrases to define a part of the command as optional. + +### Examples: + + + +## Languages + +While there isn't an official list of supported languages (cultures? locales?), here is a list based on [anecdotal evidence](http://stackoverflow.com/a/14302134/338039). + +* Afrikaans `af` +* Basque `eu` +* Bulgarian `bg` +* Catalan `ca` +* Arabic (Egypt) `ar-EG` +* Arabic (Jordan) `ar-JO` +* Arabic (Kuwait) `ar-KW` +* Arabic (Lebanon) `ar-LB` +* Arabic (Qatar) `ar-QA` +* Arabic (UAE) `ar-AE` +* Arabic (Morocco) `ar-MA` +* Arabic (Iraq) `ar-IQ` +* Arabic (Algeria) `ar-DZ` +* Arabic (Bahrain) `ar-BH` +* Arabic (Lybia) `ar-LY` +* Arabic (Oman) `ar-OM` +* Arabic (Saudi Arabia) `ar-SA` +* Arabic (Tunisia) `ar-TN` +* Arabic (Yemen) `ar-YE` +* Czech `cs` +* Dutch `nl-NL` +* English (Australia) `en-AU` +* English (Canada) `en-CA` +* English (India) `en-IN` +* English (New Zealand) `en-NZ` +* English (South Africa) `en-ZA` +* English(UK) `en-GB` +* English(US) `en-US` +* Finnish `fi` +* French `fr-FR` +* Galician `gl` +* German `de-DE` +* Hebrew `he` +* Hungarian `hu` +* Icelandic `is` +* Italian `it-IT` +* Indonesian `id` +* Japanese `ja` +* Korean `ko` +* Latin `la` +* Mandarin Chinese `zh-CN` +* Traditional Taiwan `zh-TW` +* Simplified China zh-CN `?` +* Simplified Hong Kong `zh-HK` +* Yue Chinese (Traditional Hong Kong) `zh-yue` +* Malaysian `ms-MY` +* Norwegian `no-NO` +* Polish `pl` +* Pig Latin `xx-piglatin` +* Portuguese `pt-PT` +* Portuguese (Brasil) `pt-BR` +* Romanian `ro-RO` +* Russian `ru` +* Serbian `sr-SP` +* Slovak `sk` +* Spanish (Argentina) `es-AR` +* Spanish (Bolivia) `es-BO` +* Spanish (Chile) `es-CL` +* Spanish (Colombia) `es-CO` +* Spanish (Costa Rica) `es-CR` +* Spanish (Dominican Republic) `es-DO` +* Spanish (Ecuador) `es-EC` +* Spanish (El Salvador) `es-SV` +* Spanish (Guatemala) `es-GT` +* Spanish (Honduras) `es-HN` +* Spanish (Mexico) `es-MX` +* Spanish (Nicaragua) `es-NI` +* Spanish (Panama) `es-PA` +* Spanish (Paraguay) `es-PY` +* Spanish (Peru) `es-PE` +* Spanish (Puerto Rico) `es-PR` +* Spanish (Spain) `es-ES` +* Spanish (US) `es-US` +* Spanish (Uruguay) `es-UY` +* Spanish (Venezuela) `es-VE` +* Swedish `sv-SE` +* Turkish `tr` +* Zulu `zu` + +## Developing + +Prerequisities: node.js + +First, install dependencies in your local annyang copy: + + npm install + +Make sure to run the default grunt task after each change to annyang.js. This can also be done automatically by running: + + grunt watch + +You can also run a local server for testing your work with: + + grunt dev + +Point your browser to `https://localhost:8443/demo/` to see the demo page. +Since it's using self-signed certificate, you might need to click *"Proceed Anyway"*. + + + From 3eae9fc9d28c0c6febfe79b55d474f4bb12e85b0 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Sun, 8 Feb 2015 22:45:59 +0200 Subject: [PATCH 3/9] Changed pause, resume, abort comments to clarify differences. resume() also runs start(). --- annyang.js | 14 +++++++++++--- annyang.min.js | 2 +- docs/README.md | 11 ++++++++++- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/annyang.js b/annyang.js index 88bfb65..49178cc 100644 --- a/annyang.js +++ b/annyang.js @@ -165,9 +165,9 @@ recognition.onresult = function(event) { if(pauseListening) { - return; + return false; } - + invokeCallbacks(callbacks.result); var results = event.results[event.resultIndex]; var commandText; @@ -246,6 +246,9 @@ /** * Stop listening. * + * Alternatively, to pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead. + * @see [pause()](#pause) + * * @method abort */ abort: function() { @@ -270,7 +273,10 @@ }, /** - * Pause listening and prevents command callback execution when a result matches. + * Pause listening. annyang will stop responding to commands (until the resume method is called), without turning off the browser's SpeechRecognition engine + * + * Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead. + * @see [abort()](#abort) * * @method pause */ @@ -280,11 +286,13 @@ /** * Resumes listening and restores command callback execution when a result matches. + * If SpeechRecognition was aborted (stopped), start it. * * @method resume */ resume: function() { pauseListening = false; + root.annyang.start(); }, /** diff --git a/annyang.min.js b/annyang.min.js index 4c3754c..8e676db 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=/\s*\((.*?)\)\s*/g,m=/(\(\?:[^)]+\))\?/g,n=/(\(\?)?:\w+/g,o=/\*\w+/g,p=/[\-{}\[\]+?.,\\\^$|#]/g,q=function(a){return a=a.replace(p,"\\$&").replace(l,"(?:$1)?").replace(n,function(a,b){return b?a:"([^\\s]+)"}).replace(o,"(.*?)").replace(m,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},r=function(a){a.forEach(function(a){a.callback.apply(a.context)})},s=function(){t()||b.annyang.init({},!1)},t=function(){return d!==a};b.annyang={init:function(l,m){m=m===a?!0:!!m,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){r(g.start)},d.onerror=function(a){switch(r(g.error),a.error){case"network":r(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,r((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(r(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(!k){r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1}},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(!k){r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1}},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(!k){r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1}},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c Date: Sun, 8 Feb 2015 22:49:25 +0200 Subject: [PATCH 4/9] Moved pause and resume code next to abort code. --- annyang.js | 28 ++++++++++++++-------------- annyang.min.js | 2 +- docs/README.md | 16 ++++++++-------- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/annyang.js b/annyang.js index 49178cc..e6c54d9 100644 --- a/annyang.js +++ b/annyang.js @@ -258,20 +258,6 @@ } }, - /** - * Turn on output of debug messages to the console. Ugly, but super-handy! - * - * @param {Boolean} [newState=true] - Turn on/off debug messages - * @method debug - */ - debug: function(newState) { - if (arguments.length > 0) { - debugState = !!newState; - } else { - debugState = true; - } - }, - /** * Pause listening. annyang will stop responding to commands (until the resume method is called), without turning off the browser's SpeechRecognition engine * @@ -295,6 +281,20 @@ root.annyang.start(); }, + /** + * Turn on output of debug messages to the console. Ugly, but super-handy! + * + * @param {Boolean} [newState=true] - Turn on/off debug messages + * @method debug + */ + debug: function(newState) { + if (arguments.length > 0) { + debugState = !!newState; + } else { + debugState = true; + } + }, + /** * Set the language the user will speak in. If this method is not called, defaults to 'en-US'. * diff --git a/annyang.min.js b/annyang.min.js index 8e676db..2f1bdcf 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=/\s*\((.*?)\)\s*/g,m=/(\(\?:[^)]+\))\?/g,n=/(\(\?)?:\w+/g,o=/\*\w+/g,p=/[\-{}\[\]+?.,\\\^$|#]/g,q=function(a){return a=a.replace(p,"\\$&").replace(l,"(?:$1)?").replace(n,function(a,b){return b?a:"([^\\s]+)"}).replace(o,"(.*?)").replace(m,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},r=function(a){a.forEach(function(a){a.callback.apply(a.context)})},s=function(){t()||b.annyang.init({},!1)},t=function(){return d!==a};b.annyang={init:function(l,m){m=m===a?!0:!!m,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){r(g.start)},d.onerror=function(a){switch(r(g.error),a.error){case"network":r(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,r((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(r(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},debug:function(a){i=arguments.length>0?!!a:!0},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c Date: Sun, 8 Feb 2015 22:54:19 +0200 Subject: [PATCH 5/9] Added logging onresult when paused --- annyang.js | 3 +++ annyang.min.js | 2 +- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/annyang.js b/annyang.js index e6c54d9..48926bb 100644 --- a/annyang.js +++ b/annyang.js @@ -165,6 +165,9 @@ recognition.onresult = function(event) { if(pauseListening) { + if (debugState) { + root.console.log('Speech heard, but annyang is paused', debugStyle); + } return false; } diff --git a/annyang.min.js b/annyang.min.js index 2f1bdcf..3c5082b 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=/\s*\((.*?)\)\s*/g,m=/(\(\?:[^)]+\))\?/g,n=/(\(\?)?:\w+/g,o=/\*\w+/g,p=/[\-{}\[\]+?.,\\\^$|#]/g,q=function(a){return a=a.replace(p,"\\$&").replace(l,"(?:$1)?").replace(n,function(a,b){return b?a:"([^\\s]+)"}).replace(o,"(.*?)").replace(m,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},r=function(a){a.forEach(function(a){a.callback.apply(a.context)})},s=function(){t()||b.annyang.init({},!1)},t=function(){return d!==a};b.annyang={init:function(l,m){m=m===a?!0:!!m,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){r(g.start)},d.onerror=function(a){switch(r(g.error),a.error){case"network":r(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,r((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(r(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused",j),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused",j),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused",j),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c Date: Sun, 8 Feb 2015 22:56:58 +0200 Subject: [PATCH 6/9] Fixed debug statement onresult when paused --- annyang.js | 2 +- annyang.min.js | 2 +- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/annyang.js b/annyang.js index 48926bb..19e7fa6 100644 --- a/annyang.js +++ b/annyang.js @@ -166,7 +166,7 @@ recognition.onresult = function(event) { if(pauseListening) { if (debugState) { - root.console.log('Speech heard, but annyang is paused', debugStyle); + root.console.log('Speech heard, but annyang is paused'); } return false; } diff --git a/annyang.min.js b/annyang.min.js index 3c5082b..5ac8262 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=/\s*\((.*?)\)\s*/g,m=/(\(\?:[^)]+\))\?/g,n=/(\(\?)?:\w+/g,o=/\*\w+/g,p=/[\-{}\[\]+?.,\\\^$|#]/g,q=function(a){return a=a.replace(p,"\\$&").replace(l,"(?:$1)?").replace(n,function(a,b){return b?a:"([^\\s]+)"}).replace(o,"(.*?)").replace(m,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},r=function(a){a.forEach(function(a){a.callback.apply(a.context)})},s=function(){t()||b.annyang.init({},!1)},t=function(){return d!==a};b.annyang={init:function(l,m){m=m===a?!0:!!m,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){r(g.start)},d.onerror=function(a){switch(r(g.error),a.error){case"network":r(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,r((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(r(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused",j),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused",j),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused",j),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c Date: Sun, 8 Feb 2015 23:06:46 +0200 Subject: [PATCH 7/9] Catch exceptions if trying to start SpeechRecognition and it is already running --- annyang.js | 8 +++++++- annyang.min.js | 2 +- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/annyang.js b/annyang.js index 19e7fa6..01ec6b4 100644 --- a/annyang.js +++ b/annyang.js @@ -243,7 +243,13 @@ } lastStartedAt = new Date().getTime(); - recognition.start(); + try { + recognition.start(); + } catch(e) { + if (debugState) { + root.console.log(e.message); + } + } }, /** diff --git a/annyang.min.js b/annyang.min.js index 5ac8262..eea079d 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=/\s*\((.*?)\)\s*/g,m=/(\(\?:[^)]+\))\?/g,n=/(\(\?)?:\w+/g,o=/\*\w+/g,p=/[\-{}\[\]+?.,\\\^$|#]/g,q=function(a){return a=a.replace(p,"\\$&").replace(l,"(?:$1)?").replace(n,function(a,b){return b?a:"([^\\s]+)"}).replace(o,"(.*?)").replace(m,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},r=function(a){a.forEach(function(a){a.callback.apply(a.context)})},s=function(){t()||b.annyang.init({},!1)},t=function(){return d!==a};b.annyang={init:function(l,m){m=m===a?!0:!!m,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){r(g.start)},d.onerror=function(a){switch(r(g.error),a.error){case"network":r(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,r((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(r(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(b){s(),b=b||{},e=b.autoRestart!==a?!!b.autoRestart:!0,b.continuous!==a&&(d.continuous=!!b.continuous),h=(new Date).getTime(),d.start()},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c Date: Sun, 8 Feb 2015 23:16:05 +0200 Subject: [PATCH 8/9] Tweaked abort comment to clarify difference with pause --- annyang.js | 2 +- docs/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/annyang.js b/annyang.js index 01ec6b4..acbc730 100644 --- a/annyang.js +++ b/annyang.js @@ -255,7 +255,7 @@ /** * Stop listening. * - * Alternatively, to pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead. + * Alternatively, to only temporarily pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead. * @see [pause()](#pause) * * @method abort diff --git a/docs/README.md b/docs/README.md index 5896443..963fd2f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -58,7 +58,7 @@ Receives an optional options object which supports the following options: Stop listening. -Alternatively, to pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead. +Alternatively, to only temporarily pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead. See: [pause()](#pause) From 93c3e229765e6d5812617a16ce6052cadb1e172e Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Thu, 12 Mar 2015 18:27:06 +0200 Subject: [PATCH 9/9] start() method will also disable pause mode. pause and abort documentation improved slightly --- annyang.js | 6 +++--- annyang.min.js | 2 +- demo/css/main.min.css | 2 +- docs/README.md | 18 +++++++++--------- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/annyang.js b/annyang.js index acbc730..4754461 100644 --- a/annyang.js +++ b/annyang.js @@ -231,6 +231,7 @@ * @method start */ start: function(options) { + pauseListening = false; initIfNeeded(); options = options || {}; if (options.autoRestart !== undefined) { @@ -253,7 +254,7 @@ }, /** - * Stop listening. + * Stop listening, and turn off mic. * * Alternatively, to only temporarily pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead. * @see [pause()](#pause) @@ -268,7 +269,7 @@ }, /** - * Pause listening. annyang will stop responding to commands (until the resume method is called), without turning off the browser's SpeechRecognition engine + * Pause listening. annyang will stop responding to commands (until the resume or start methods are called), without turning off the browser's SpeechRecognition engine or the mic. * * Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead. * @see [abort()](#abort) @@ -286,7 +287,6 @@ * @method resume */ resume: function() { - pauseListening = false; root.annyang.start(); }, diff --git a/annyang.min.js b/annyang.min.js index eea079d..14315c0 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -3,4 +3,4 @@ //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ -(function(a){"use strict";var b=this,c=b.SpeechRecognition||b.webkitSpeechRecognition||b.mozSpeechRecognition||b.msSpeechRecognition||b.oSpeechRecognition;if(!c)return b.annyang=null,a;var d,e,f=[],g={start:[],error:[],end:[],result:[],resultMatch:[],resultNoMatch:[],errorNetwork:[],errorPermissionBlocked:[],errorPermissionDenied:[]},h=0,i=!1,j="font-weight: bold; color: #00f;",k=!1,l=/\s*\((.*?)\)\s*/g,m=/(\(\?:[^)]+\))\?/g,n=/(\(\?)?:\w+/g,o=/\*\w+/g,p=/[\-{}\[\]+?.,\\\^$|#]/g,q=function(a){return a=a.replace(p,"\\$&").replace(l,"(?:$1)?").replace(n,function(a,b){return b?a:"([^\\s]+)"}).replace(o,"(.*?)").replace(m,"\\s*$1?\\s*"),new RegExp("^"+a+"$","i")},r=function(a){a.forEach(function(a){a.callback.apply(a.context)})},s=function(){t()||b.annyang.init({},!1)},t=function(){return d!==a};b.annyang={init:function(l,m){m=m===a?!0:!!m,d&&d.abort&&d.abort(),d=new c,d.maxAlternatives=5,d.continuous="http:"===b.location.protocol,d.lang="en-US",d.onstart=function(){r(g.start)},d.onerror=function(a){switch(r(g.error),a.error){case"network":r(g.errorNetwork);break;case"not-allowed":case"service-not-allowed":e=!1,r((new Date).getTime()-h<200?g.errorPermissionBlocked:g.errorPermissionDenied)}},d.onend=function(){if(r(g.end),e){var a=(new Date).getTime()-h;1e3>a?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){k=!1,s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){k=!1,s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){k=!1,b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;ca?setTimeout(b.annyang.start,1e3-a):b.annyang.start()}},d.onresult=function(a){if(k)return i&&b.console.log("Speech heard, but annyang is paused"),!1;r(g.result);for(var c,d=a.results[a.resultIndex],e=0;eh;h++){var m=f[h].command.exec(c);if(m){var n=m.slice(1);return i&&(b.console.log("command matched: %c"+f[h].originalPhrase,j),n.length&&b.console.log("with parameters",n)),f[h].callback.apply(this,n),r(g.resultMatch),!0}}}return r(g.resultNoMatch),!1},m&&(f=[]),l.length&&this.addCommands(l)},start:function(c){k=!1,s(),c=c||{},e=c.autoRestart!==a?!!c.autoRestart:!0,c.continuous!==a&&(d.continuous=!!c.continuous),h=(new Date).getTime();try{d.start()}catch(f){i&&b.console.log(f.message)}},abort:function(){e=!1,t&&d.abort()},pause:function(){k=!0},resume:function(){b.annyang.start()},debug:function(a){i=arguments.length>0?!!a:!0},setLanguage:function(a){s(),d.lang=a},addCommands:function(a){var c,d;s();for(var e in a)if(a.hasOwnProperty(e)){if(c=b[a[e]]||a[e],"function"!=typeof c)continue;d=q(e),f.push({command:d,callback:c,originalPhrase:e})}i&&b.console.log("Commands successfully loaded: %c"+f.length,j)},removeCommands:function(b){return b===a?void(f=[]):(b=Array.isArray(b)?b:[b],void(f=f.filter(function(a){for(var c=0;c