From 182ac4498e90a0a1fc0461c22a3a2541fc778432 Mon Sep 17 00:00:00 2001 From: Kean Walmsley Date: Tue, 18 Nov 2014 10:44:04 +0100 Subject: [PATCH 1/5] Added forceContinuous option --- annyang.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/annyang.js b/annyang.js index a004d99..0d2ef7d 100644 --- a/annyang.js +++ b/annyang.js @@ -38,6 +38,7 @@ var recognition; var callbacks = { start: [], error: [], end: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] }; var autoRestart; + var forceContinuous; var lastStartedAt = 0; var debugState = false; var debugStyle = 'font-weight: bold; color: #00f;'; @@ -121,7 +122,7 @@ // In HTTPS, turn off continuous mode for faster results. // In HTTP, turn on continuous mode for much slower results, but no repeating security notices - recognition.continuous = root.location.protocol === 'http:'; + recognition.continuous = forceContinuous || root.location.protocol === 'http:'; // Sets the language to the default 'en-US'. This can be changed with annyang.setLanguage() recognition.lang = 'en-US'; @@ -227,6 +228,11 @@ } else { autoRestart = true; } + if (options.forceContinuous !== undefined) { + forceContinuous = !!options.forceContinuous; + } else { + forceContinuous = false; + } lastStartedAt = new Date().getTime(); recognition.start(); }, From 352970aa4309f0eb243b4f02828da0b9fe63a11a Mon Sep 17 00:00:00 2001 From: Kean Walmsley Date: Tue, 18 Nov 2014 10:49:20 +0100 Subject: [PATCH 2/5] Removed clause that reset flag on restart --- annyang.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/annyang.js b/annyang.js index 0d2ef7d..7db0aae 100644 --- a/annyang.js +++ b/annyang.js @@ -230,9 +230,7 @@ } if (options.forceContinuous !== undefined) { forceContinuous = !!options.forceContinuous; - } else { - forceContinuous = false; - } + } lastStartedAt = new Date().getTime(); recognition.start(); }, From e9847b5e4319491541a4efba9071bcd57befec3d Mon Sep 17 00:00:00 2001 From: Kean Walmsley Date: Mon, 24 Nov 2014 14:21:22 +0100 Subject: [PATCH 3/5] Minor change to the option name, removed variable --- annyang.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/annyang.js b/annyang.js index 7db0aae..47cc1ed 100644 --- a/annyang.js +++ b/annyang.js @@ -38,7 +38,6 @@ var recognition; var callbacks = { start: [], error: [], end: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] }; var autoRestart; - var forceContinuous; var lastStartedAt = 0; var debugState = false; var debugStyle = 'font-weight: bold; color: #00f;'; @@ -122,7 +121,7 @@ // In HTTPS, turn off continuous mode for faster results. // In HTTP, turn on continuous mode for much slower results, but no repeating security notices - recognition.continuous = forceContinuous || root.location.protocol === 'http:'; + recognition.continuous = root.location.protocol === 'http:'; // Sets the language to the default 'en-US'. This can be changed with annyang.setLanguage() recognition.lang = 'en-US'; @@ -228,9 +227,10 @@ } else { autoRestart = true; } - if (options.forceContinuous !== undefined) { - forceContinuous = !!options.forceContinuous; + if (options.continuous !== undefined) { + recognition.continuous = !!options.continuous; } + lastStartedAt = new Date().getTime(); recognition.start(); }, From 6738065be6848f8216436230380fddee895fbb81 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Mon, 24 Nov 2014 21:21:30 +0200 Subject: [PATCH 4/5] Added documentation for new contiuous option. Rebuilt all files --- annyang.js | 15 +++++++++------ annyang.min.js | 2 +- docs/README.md | 7 +++++-- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/annyang.js b/annyang.js index 47cc1ed..7dba25d 100644 --- a/annyang.js +++ b/annyang.js @@ -209,12 +209,15 @@ * Start listening. * It's a good idea to call this after adding some commands first, but not mandatory. * - * Receives an optional options object which currently only supports one option: + * 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, but don't restart automatically + * // 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 }); * * @param {Object} [options] - Optional options. * @method start @@ -227,10 +230,10 @@ } else { autoRestart = true; } - if (options.continuous !== undefined) { - recognition.continuous = !!options.continuous; - } - + if (options.continuous !== undefined) { + recognition.continuous = !!options.continuous; + } + lastStartedAt = new Date().getTime(); recognition.start(); }, diff --git a/annyang.min.js b/annyang.min.js index 0b24ca6..b5f1178 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,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){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){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,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){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){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,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){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;c Date: Mon, 24 Nov 2014 21:26:15 +0200 Subject: [PATCH 5/5] Bumped to version 1.5.0 --- annyang.js | 2 +- annyang.min.js | 2 +- bower.json | 2 +- package.json | 2 +- sites/facebook.min.js | 2 +- sites/geektime.min.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/annyang.js b/annyang.js index 7dba25d..eea2678 100644 --- a/annyang.js +++ b/annyang.js @@ -1,5 +1,5 @@ //! annyang -//! version : 1.4.0 +//! version : 1.5.0 //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ diff --git a/annyang.min.js b/annyang.min.js index b5f1178..0869435 100644 --- a/annyang.min.js +++ b/annyang.min.js @@ -1,5 +1,5 @@ //! annyang -//! version : 1.4.0 +//! version : 1.5.0 //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ diff --git a/bower.json b/bower.json index dc41992..a94fa31 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "annyang", - "version": "1.4.0", + "version": "1.5.0", "description": "A javascript library for adding voice commands to your site, using speech recognition", "main": "annyang.js", "keywords": [ diff --git a/package.json b/package.json index 461f774..3ae5637 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "annyang", - "version": "1.4.0", + "version": "1.5.0", "description": "A javascript library for adding voice commands to your site, using speech recognition", "homepage": "https://www.talater.com/annyang/", "main": "annyang.js", diff --git a/sites/facebook.min.js b/sites/facebook.min.js index b572ca7..daef81b 100644 --- a/sites/facebook.min.js +++ b/sites/facebook.min.js @@ -1,5 +1,5 @@ //! annyang -//! version : 1.4.0 +//! version : 1.5.0 //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/ diff --git a/sites/geektime.min.js b/sites/geektime.min.js index 59347c1..d35ecb2 100644 --- a/sites/geektime.min.js +++ b/sites/geektime.min.js @@ -1,5 +1,5 @@ //! annyang -//! version : 1.4.0 +//! version : 1.5.0 //! author : Tal Ater @TalAter //! license : MIT //! https://www.TalAter.com/annyang/