From 9086fc66711c590dcd224d01aba2b8120cff51fd Mon Sep 17 00:00:00 2001 From: RocketBear27 <40366354+rocketbear27@users.noreply.github.com> Date: Mon, 18 Feb 2019 16:00:48 -0800 Subject: [PATCH 1/9] Fix grammar --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d3207f3..d0f673a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,7 +27,7 @@ A lot of annyang's functionality came from pull requests sent over GitHub. Here :bulb: A great alternative to repeatedly running `$ grunt` is to run `$ grunt watch` once, and leave this process running. It will continuously run all the tests and build the files every time you make a change to one of annyang's files. It will even *beep* if you make an error, and help you debug it. :+1: - [x] You can run a local server to test your work in the browser by running `$ grunt dev`. This will also automatically run `$ grunt watch` for you. 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"*. + Since it's using a self-signed certificate, you might need to click *"Proceed Anyway"*. - [x] Before committing your changes, the last step must always be running `$ grunt`. This makes sure everything works, and all files are kept up to date with your changes. - [x] Once you've made sure all your changes work correctly and have been committed, push your local changes back to github with `$ git push -u origin master` - [x] Visit your fork on GitHub.com ([https://github.com/YOUR-USER-NAME/annyang](https://github.com/YOUR-USER-NAME/annyang)) and create a pull request for your changes. @@ -50,7 +50,7 @@ annyang is tested using [Jasmine](http://jasmine.github.io/2.0/introduction.html Please include tests for any changes you make: * If you found a bug, please write a test that fails because of that bug, then fix the bug so that the test passes. * If you are adding a new feature, write tests that thoroughly test every possible use of your code. -* If you are changing existing functionality, make sure to update existing tests so they pass. (This is a last resort. Whenever possible try to maintain backwards compatibility) +* If you are changing existing functionality, make sure to update existing tests so they pass. (This is the last resort. Whenever possible try to maintain backward compatibility) The tests reside in *BasicSpec.js*. The file contains a series of spec groups (e.g. `describe('a spec group', function() {});`) which each contain 1 or more specs (e.g. `it('should do stuff', function() {});`). Some of the spec groups also contain some code which runs before each spec (`beforeEach(function() {});`). @@ -70,6 +70,6 @@ Explain the problem and include additional details to help maintainers reproduce ### Feature Requests and Ideas -We track discussions of new features, proposed changes and other ideas as [GitHub issues](https://github.com/TalAter/annyang/issues). If you would like to discuss one of those, please first look through existing open and closed [GitHub issues](https://github.com/TalAter/annyang/issues?q=is%3Aissue) and see if there is already a discussion on this topic which you can join. If there isn't, please open a [new issue](https://github.com/TalAter/annyang/issues/new). +We track discussions of new features, proposed changes, and other ideas as [GitHub issues](https://github.com/TalAter/annyang/issues). If you would like to discuss one of those, please first look through existing open and closed [GitHub issues](https://github.com/TalAter/annyang/issues?q=is%3Aissue) and see if there is already a discussion on this topic which you can join. If there isn't, please open a [new issue](https://github.com/TalAter/annyang/issues/new). When discussing new ideas or proposing changes, please take the time to be as descriptive as possible about the topic at hand. Please take the time to explain the issue you are facing, or the problem you propose to solve in as much detail as possible. From d24861699eef60c72819b59ecfe622f40d8d52f6 Mon Sep 17 00:00:00 2001 From: RocketBear27 <40366354+rocketbear27@users.noreply.github.com> Date: Mon, 18 Feb 2019 16:26:04 -0800 Subject: [PATCH 2/9] Fix grammar --- docs/README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/README.md b/docs/README.md index cf9f304..72163da 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,7 @@ -# Quick Tutorial, Intro and Demos +# Quick Tutorial, Intro, and Demos The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). @@ -68,20 +68,20 @@ See: [pause()](#pause) ## pause() -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. +Pause listening. annyang will stop responding to commands (until the resume or start methods are called), without turning off the browser's speech recognition engine or the mic. -Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead. +Alternatively, to stop the speech recognition engine and close the mic, use abort() instead. See: [abort()](#abort) ## resume() -Resumes listening and restores command callback execution when a result matches. +Resumes listening and restore command callback execution when a result matches. If SpeechRecognition was aborted (stopped), start it. ## debug([newState=true]) -Turn on output of debug messages to the console. Ugly, but super-handy! +Turn on the output of debug messages to the console. Ugly, but super-handy! ### Params: @@ -119,7 +119,7 @@ See: [Commands Object](#commands-object) ## removeCommands([commandsToRemove]) -Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands. +Remove existing commands. Called with a single phrase, an array of phrases, or methodically. Pass no params to remove all commands. #### Examples: ````javascript @@ -152,21 +152,21 @@ Add a callback function to be called in case one of the following events happens This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start. -* `error` - Fired when the browser's Speech Recogntion engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). +* `error` - Fired when the browser's Speech Recognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). - Callback function will be called with the error event as the first argument. + The callback function will be called with the error event as the first argument. * `errorNetwork` - Fired when Speech Recognition fails because of a network error. - Callback function will be called with the error event as the first argument. + The callback function will be called with the error event as the first argument. * `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition. - Callback function will be called with the error event as the first argument. + The callback function will be called with the error event as the first argument. * `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition. - Callback function will be called with the error event as the first argument. + The callback function will be called with the error event as the first argument. * `end` - Fired when the browser's Speech Recognition engine stops. @@ -269,7 +269,7 @@ Useful in case you want direct access to the browser's Speech Recognition engine Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition detects speech. -Can accept either a string containing a single sentence, or an array containing multiple sentences to be checked +Can accept either a string containing a single sentence or an array containing multiple sentences to be checked in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed) #### Examples: @@ -296,9 +296,9 @@ 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 `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. +* Use `optional words` or phrases to define a part of the command is optional. #### Examples: ````html @@ -308,7 +308,7 @@ var commands = { // e.g. saying "Show me Batman and Robin" will call showFlickr('Batman and Robin'); 'show me *tag': showFlickr, - // A named variable is a one word variable, that can fit anywhere in your command. + // A named variable is a one-word variable, that can fit anywhere in your command. // e.g. saying "calculate October stats" will call calculateStats('October'); 'calculate :month stats': calculateStats, From d812dcfd5661fae7fd0665f16862c4bcb4f92a01 Mon Sep 17 00:00:00 2001 From: RocketBear27 <40366354+rocketbear27@users.noreply.github.com> Date: Mon, 18 Feb 2019 16:28:52 -0800 Subject: [PATCH 3/9] Fix grammar --- docs/FAQ.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 9d85e96..b4a6d60 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -140,7 +140,7 @@ Another possible reason for this might be that you are offline. ## Can annyang work offline? -No. annyang relies on the browser's own speech recognition engine. In Chrome, this engine performs the recognition in the cloud. +No. annyang relies on the browser's own speech recognition engine. In Chrome, this engine performs recognition in the cloud. ## Which browsers are supported? @@ -207,11 +207,11 @@ annyang.addCallback('result', function() { ## Can annyang be used in Chromium or Electron? -Yes, however you must create your own Chromium keys and are limited to 50 requests/day. To do this you'll need to provide your own keys at runtime by following the instructions for [Acquiring Keys](https://www.chromium.org/developers/how-tos/api-keys) in the Chromium developer docs. +Yes, however, you must create your own Chromium keys and are limited to 50 requests/day. To do this you'll need to provide your own keys at runtime by following the instructions for [Acquiring Keys](https://www.chromium.org/developers/how-tos/api-keys) in the Chromium developer docs. ## Can annyang be used in Cordova? -Yes. In order to use `webKitSpeechRecognition` you will need to use [Crosswalk](https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview) and the [Cordova Media Plugin](https://github.com/apache/cordova-plugin-media). These can be added to an existing cordova project with the following commands: +Yes. In order to use `webKitSpeechRecognition` you will need to use [Crosswalk](https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview) and the [Cordova Media Plugin](https://github.com/apache/cordova-plugin-media). These can be added to an existing Cordova project with the following commands: ``` cordova plugin add cordova-plugin-crosswalk-webview From 3aea314bcb9ea82b42c14d4f82f58d996afb988f Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Tue, 19 Feb 2019 13:34:32 +0200 Subject: [PATCH 4/9] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d0f673a..4f416e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,7 +50,7 @@ annyang is tested using [Jasmine](http://jasmine.github.io/2.0/introduction.html Please include tests for any changes you make: * If you found a bug, please write a test that fails because of that bug, then fix the bug so that the test passes. * If you are adding a new feature, write tests that thoroughly test every possible use of your code. -* If you are changing existing functionality, make sure to update existing tests so they pass. (This is the last resort. Whenever possible try to maintain backward compatibility) +* If you are changing existing functionality, make sure to update existing tests so they pass. (This is a last resort move. Whenever possible try to maintain backward compatibility) The tests reside in *BasicSpec.js*. The file contains a series of spec groups (e.g. `describe('a spec group', function() {});`) which each contain 1 or more specs (e.g. `it('should do stuff', function() {});`). Some of the spec groups also contain some code which runs before each spec (`beforeEach(function() {});`). From e170f1ce8b83e9dbd4e04e939777217f99c9326a Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Tue, 19 Feb 2019 13:48:13 +0200 Subject: [PATCH 5/9] Update README.md --- docs/README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/README.md b/docs/README.md index 72163da..2266887 100644 --- a/docs/README.md +++ b/docs/README.md @@ -68,16 +68,16 @@ See: [pause()](#pause) ## pause() -Pause listening. annyang will stop responding to commands (until the resume or start methods are called), without turning off the browser's speech recognition engine or the mic. +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 speech recognition engine and close the mic, use abort() instead. +Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead. See: [abort()](#abort) ## resume() Resumes listening and restore command callback execution when a result matches. -If SpeechRecognition was aborted (stopped), start it. +If speech recognition was aborted (stopped), start it. ## debug([newState=true]) @@ -146,29 +146,29 @@ annyang.removeCommands(['howdy', 'hi']); Add a callback function to be called in case one of the following events happens: -* `start` - Fired as soon as the browser's Speech Recognition engine starts listening. +* `start` - Fired as soon as the browser's SpeechRecognition engine starts listening. * `soundstart` - Fired as soon as any sound (possibly speech) has been detected. - This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start. + This will fire once per SpeechRecognition starting. See https://is.gd/annyang_sound_start. -* `error` - Fired when the browser's Speech Recognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). +* `error` - Fired when the browser's SpeechRecognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). The callback function will be called with the error event as the first argument. -* `errorNetwork` - Fired when Speech Recognition fails because of a network error. +* `errorNetwork` - Fired when SpeechRecognition fails because of a network error. The callback function will be called with the error event as the first argument. -* `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition. +* `errorPermissionBlocked` - Fired when the browser blocks the permission request to use SpeechRecognition. The callback function will be called with the error event as the first argument. -* `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition. +* `errorPermissionDenied` - Fired when the user blocks the permission request to use SpeechRecognition. The callback function will be called with the error event as the first argument. -* `end` - Fired when the browser's Speech Recognition engine stops. +* `end` - Fired when the browser's SpeechRecognition engine stops. * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks. @@ -258,19 +258,19 @@ Returns false if speech recognition is off or annyang is paused. ## getSpeechRecognizer() Returns the instance of the browser's SpeechRecognition object used by annyang. -Useful in case you want direct access to the browser's Speech Recognition engine. +Useful in case you want direct access to the browser's SpeechRecognition engine. ### Return: -* SpeechRecognition The browser's Speech Recognizer currently used by annyang +* SpeechRecognition The browser's SpeechRecognition currently used by annyang ## trigger(string|array) -Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition +Simulate speech being recognized. This will trigger the same events and behavior as when the SpeechRecognition detects speech. Can accept either a string containing a single sentence or an array containing multiple sentences to be checked -in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed) +in order until one of them matches a command (similar to the way SpeechRecognition Alternatives are parsed) #### Examples: ````javascript @@ -298,7 +298,7 @@ annyang understands commands with `named variables`, `splats`, and `optional wor * 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 is optional. +* Use `optional words` or phrases to define a part of the command as optional. #### Examples: ````html From b9706d4da17e0fd88746ca7db3c5ed0f5c53b9cc Mon Sep 17 00:00:00 2001 From: RocketBear27 Date: Thu, 21 Feb 2019 15:47:19 -0800 Subject: [PATCH 6/9] Fix src doc grammar --- src/annyang.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/annyang.js b/src/annyang.js index 47230e9..c600f7a 100644 --- a/src/annyang.js +++ b/src/annyang.js @@ -18,7 +18,7 @@ 'use strict'; /** - * # Quick Tutorial, Intro and Demos + * # Quick Tutorial, Intro, and Demos * * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). * @@ -357,7 +357,7 @@ }, /** - * Resumes listening and restores command callback execution when a result matches. + * Resumes listening and restore command callback execution when a result matches. * If SpeechRecognition was aborted (stopped), start it. * * @method resume @@ -367,7 +367,7 @@ }, /** - * Turn on output of debug messages to the console. Ugly, but super-handy! + * Turn on the output of debug messages to the console. Ugly, but super-handy! * * @param {boolean} [newState=true] - Turn on/off debug messages * @method debug @@ -434,7 +434,7 @@ }, /** - * Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands. + * Remove existing commands. Called with a single phrase, an array of phrases, or methodically. Pass no params to remove all commands. * * #### Examples: * ````javascript @@ -480,31 +480,31 @@ * * This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start. * - * * `error` - Fired when the browser's Speech Recogntion engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). + * * `error` - Fired when the browser's Speech Recognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `errorNetwork` - Fired when Speech Recognition fails because of a network error. * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition. * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition. * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `end` - Fired when the browser's Speech Recognition engine stops. * * * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks. * - * Callback functions for this event will be called with an array of possible phrases the user said as the first argument. + * The Callback functions for this event will be called with an array of possible phrases the user said as the first argument. * * * `resultMatch` - Fired when annyang was able to match between what the user said and a registered command. * - * Callback functions for this event will be called with three arguments in the following order: + * The Callback functions for this event will be called with three arguments in the following order: * * * The phrase the user said that matched a command. * * The command that was matched. @@ -621,7 +621,7 @@ * Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition * detects speech. * - * Can accept either a string containing a single sentence, or an array containing multiple sentences to be checked + * Can accept either a string containing a single sentence or an array containing multiple sentences to be checked * in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed) * * #### Examples: @@ -668,7 +668,7 @@ * * annyang understands commands with `named variables`, `splats`, and `optional words`. * - * * Use `named variables` for one word arguments in your command. + * * 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. * @@ -680,7 +680,7 @@ * // e.g. saying "Show me Batman and Robin" will call showFlickr('Batman and Robin'); * 'show me *tag': showFlickr, * - * // A named variable is a one word variable, that can fit anywhere in your command. + * // A named variable is a one-word variable, that can fit anywhere in your command. * // e.g. saying "calculate October stats" will call calculateStats('October'); * 'calculate :month stats': calculateStats, * From a79463c6db9cb5de834d0a7fe502cf86723b672f Mon Sep 17 00:00:00 2001 From: RocketBear27 Date: Thu, 21 Feb 2019 15:51:00 -0800 Subject: [PATCH 7/9] Fix grammar --- docs/README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/README.md b/docs/README.md index 2266887..6b56661 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ - + # Quick Tutorial, Intro, and Demos @@ -77,7 +77,7 @@ See: [abort()](#abort) ## resume() Resumes listening and restore command callback execution when a result matches. -If speech recognition was aborted (stopped), start it. +If SpeechRecognition was aborted (stopped), start it. ## debug([newState=true]) @@ -146,37 +146,37 @@ annyang.removeCommands(['howdy', 'hi']); Add a callback function to be called in case one of the following events happens: -* `start` - Fired as soon as the browser's SpeechRecognition engine starts listening. +* `start` - Fired as soon as the browser's Speech Recognition engine starts listening. * `soundstart` - Fired as soon as any sound (possibly speech) has been detected. - This will fire once per SpeechRecognition starting. See https://is.gd/annyang_sound_start. + This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start. -* `error` - Fired when the browser's SpeechRecognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). +* `error` - Fired when the browser's Speech Recognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). - The callback function will be called with the error event as the first argument. + The Callback function will be called with the error event as the first argument. -* `errorNetwork` - Fired when SpeechRecognition fails because of a network error. +* `errorNetwork` - Fired when Speech Recognition fails because of a network error. - The callback function will be called with the error event as the first argument. + The Callback function will be called with the error event as the first argument. -* `errorPermissionBlocked` - Fired when the browser blocks the permission request to use SpeechRecognition. +* `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition. - The callback function will be called with the error event as the first argument. + The Callback function will be called with the error event as the first argument. -* `errorPermissionDenied` - Fired when the user blocks the permission request to use SpeechRecognition. +* `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition. - The callback function will be called with the error event as the first argument. + The Callback function will be called with the error event as the first argument. -* `end` - Fired when the browser's SpeechRecognition engine stops. +* `end` - Fired when the browser's Speech Recognition engine stops. * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks. - Callback functions for this event will be called with an array of possible phrases the user said as the first argument. + The Callback functions for this event will be called with an array of possible phrases the user said as the first argument. * `resultMatch` - Fired when annyang was able to match between what the user said and a registered command. - Callback functions for this event will be called with three arguments in the following order: + The Callback functions for this event will be called with three arguments in the following order: * The phrase the user said that matched a command. * The command that was matched. @@ -258,19 +258,19 @@ Returns false if speech recognition is off or annyang is paused. ## getSpeechRecognizer() Returns the instance of the browser's SpeechRecognition object used by annyang. -Useful in case you want direct access to the browser's SpeechRecognition engine. +Useful in case you want direct access to the browser's Speech Recognition engine. ### Return: -* SpeechRecognition The browser's SpeechRecognition currently used by annyang +* SpeechRecognition The browser's Speech Recognizer currently used by annyang ## trigger(string|array) -Simulate speech being recognized. This will trigger the same events and behavior as when the SpeechRecognition +Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition detects speech. Can accept either a string containing a single sentence or an array containing multiple sentences to be checked -in order until one of them matches a command (similar to the way SpeechRecognition Alternatives are parsed) +in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed) #### Examples: ````javascript @@ -350,5 +350,5 @@ var commands = { } ```` - + From 839e3b6dc5bae62f67ad8e28214135390964f443 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Fri, 22 Feb 2019 02:12:36 +0200 Subject: [PATCH 8/9] Build dist files --- dist/annyang.js | 28 ++++++++++++++-------------- dist/annyang.js.map | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dist/annyang.js b/dist/annyang.js index 1db2b23..ebfc13b 100644 --- a/dist/annyang.js +++ b/dist/annyang.js @@ -26,7 +26,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol 'use strict'; /** - * # Quick Tutorial, Intro and Demos + * # Quick Tutorial, Intro, and Demos * * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/). * @@ -349,7 +349,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol }, /** - * Resumes listening and restores command callback execution when a result matches. + * Resumes listening and restore command callback execution when a result matches. * If SpeechRecognition was aborted (stopped), start it. * * @method resume @@ -359,7 +359,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol }, /** - * Turn on output of debug messages to the console. Ugly, but super-handy! + * Turn on the output of debug messages to the console. Ugly, but super-handy! * * @param {boolean} [newState=true] - Turn on/off debug messages * @method debug @@ -424,7 +424,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol }, /** - * Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands. + * Remove existing commands. Called with a single phrase, an array of phrases, or methodically. Pass no params to remove all commands. * * #### Examples: * ````javascript @@ -470,31 +470,31 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol * * This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start. * - * * `error` - Fired when the browser's Speech Recogntion engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). + * * `error` - Fired when the browser's Speech Recognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined). * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `errorNetwork` - Fired when Speech Recognition fails because of a network error. * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition. * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition. * - * Callback function will be called with the error event as the first argument. + * The Callback function will be called with the error event as the first argument. * * * `end` - Fired when the browser's Speech Recognition engine stops. * * * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks. * - * Callback functions for this event will be called with an array of possible phrases the user said as the first argument. + * The Callback functions for this event will be called with an array of possible phrases the user said as the first argument. * * * `resultMatch` - Fired when annyang was able to match between what the user said and a registered command. * - * Callback functions for this event will be called with three arguments in the following order: + * The Callback functions for this event will be called with three arguments in the following order: * * * The phrase the user said that matched a command. * * The command that was matched. @@ -611,7 +611,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol * Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition * detects speech. * - * Can accept either a string containing a single sentence, or an array containing multiple sentences to be checked + * Can accept either a string containing a single sentence or an array containing multiple sentences to be checked * in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed) * * #### Examples: @@ -658,7 +658,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol * * annyang understands commands with `named variables`, `splats`, and `optional words`. * - * * Use `named variables` for one word arguments in your command. + * * 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. * @@ -670,7 +670,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol * // e.g. saying "Show me Batman and Robin" will call showFlickr('Batman and Robin'); * 'show me *tag': showFlickr, * - * // A named variable is a one word variable, that can fit anywhere in your command. + * // A named variable is a one-word variable, that can fit anywhere in your command. * // e.g. saying "calculate October stats" will call calculateStats('October'); * 'calculate :month stats': calculateStats, * diff --git a/dist/annyang.js.map b/dist/annyang.js.map index cf7eca7..528961a 100644 --- a/dist/annyang.js.map +++ b/dist/annyang.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/annyang.js"],"names":["root","factory","define","amd","annyang","module","exports","window","undefined","SpeechRecognition","webkitSpeechRecognition","mozSpeechRecognition","msSpeechRecognition","oSpeechRecognition","commandsList","recognition","callbacks","start","error","end","soundstart","result","resultMatch","resultNoMatch","errorNetwork","errorPermissionBlocked","errorPermissionDenied","autoRestart","lastStartedAt","autoRestartCount","debugState","debugStyle","pauseListening","isListening","optionalParam","optionalRegex","namedParam","splatParam","escapeRegExp","commandToRegExp","command","replace","match","optional","RegExp","invokeCallbacks","args","forEach","callback","apply","context","isInitialized","logMessage","text","extraParameters","indexOf","console","log","initIfNeeded","init","registerCommand","originalPhrase","push","parseResults","results","commandText","i","length","trim","j","l","currentCommand","exec","parameters","slice","commands","resetCommands","abort","maxAlternatives","continuous","location","protocol","lang","onstart","onsoundstart","onerror","event","Date","getTime","onend","timeSinceLastStart","setTimeout","paused","onresult","SpeechRecognitionResult","resultIndex","k","transcript","addCommands","options","e","message","pause","resume","debug","newState","setLanguage","language","cb","phrase","hasOwnProperty","regexp","source","removeCommands","commandsToRemove","Array","isArray","filter","addCallback","type","removeCallback","compareWithCallbackParameter","callbackType","getSpeechRecognizer","trigger","sentences"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA,CAAC,UAASA,IAAT,EAAeC,OAAf,EAAwB;AACvB;;AACA,MAAI,OAAOC,MAAP,KAAkB,UAAlB,IAAgCA,OAAOC,GAA3C,EAAgD;AAAE;AAChDD,WAAO,EAAP,EAAW,YAAY;AACrB,aAAQF,KAAKI,OAAL,GAAeH,QAAQD,IAAR,CAAvB;AACD,KAFD;AAGD,GAJD,MAIO,IAAI,QAAOK,MAAP,yCAAOA,MAAP,OAAkB,QAAlB,IAA8BA,OAAOC,OAAzC,EAAkD;AAAE;AACzDD,WAAOC,OAAP,GAAiBL,QAAQD,IAAR,CAAjB;AACD,GAFM,MAEA;AAAE;AACPA,SAAKI,OAAL,GAAeH,QAAQD,IAAR,CAAf;AACD;AACF,CAXD,EAWG,OAAOO,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,YAXH,EAWkD,UAASP,IAAT,EAAeQ,SAAf,EAA0B;AAC1E;;AAEA;;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;AACvC,UAAIyE,+BAA+B,SAA/BA,4BAA+B,CAASb,EAAT,EAAa;AAC9C,eAAOA,GAAG5D,QAAH,KAAgBA,QAAvB;AACD,OAFD;AAGA;AACA,WAAK,IAAI0E,YAAT,IAAyB1G,SAAzB,EAAoC;AAClC,YAAIA,UAAU8F,cAAV,CAAyBY,YAAzB,CAAJ,EAA4C;AAC1C;AACA,cAAIH,SAAS/G,SAAT,IAAsB+G,SAASG,YAAnC,EAAiD;AAC/C;AACA,gBAAI1E,aAAaxC,SAAjB,EAA4B;AAC1BQ,wBAAU0G,YAAV,IAA0B,EAA1B;AACD,aAFD,MAEO;AACL;AACA1G,wBAAU0G,YAAV,IAA0B1G,UAAU0G,YAAV,EAAwBL,MAAxB,CAA+BI,4BAA/B,CAA1B;AACD;AACF;AACF;AACF;AACF,KAlbO;;AAobR;;;;;;;AAOAxF,iBAAa,uBAAW;AACtB,aAAOA,gBAAe,CAACD,cAAvB;AACD,KA7bO;;AA+bR;;;;;;;AAOA2F,yBAAqB,+BAAW;AAC9B,aAAO5G,WAAP;AACD,KAxcO;;AA0cR;;;;;;;;;;;;;;;;;;;AAmBA6G,aAAS,iBAASC,SAAT,EAAoB;AAC3B,UAAI,CAACzH,QAAQ6B,WAAR,EAAL,EAA4B;AAC1B,YAAIH,UAAJ,EAAgB;AACd,cAAI,CAACG,YAAL,EAAkB;AAChBmB,uBAAW,yCAAX;AACD,WAFD,MAEO;AACLA,uBAAW,qCAAX;AACD;AACF;AACD;AACD;;AAED,UAAI,CAAC+D,MAAMC,OAAN,CAAcS,SAAd,CAAL,EAA+B;AAC7BA,oBAAY,CAACA,SAAD,CAAZ;AACD;;AAED9D,mBAAa8D,SAAb;AACD;AA9eO,GAAV;;AAifA,SAAOzH,OAAP;AACD,CA9oBD;;AAgpBA","file":"annyang.js","sourcesContent":["//! annyang\n//! version : 2.6.1\n//! author : Tal Ater @TalAter\n//! license : MIT\n//! https://www.TalAter.com/annyang/\n(function(root, factory) {\n 'use strict';\n if (typeof define === 'function' && define.amd) { // AMD + global\n define([], function () {\n return (root.annyang = factory(root));\n });\n } else if (typeof module === 'object' && module.exports) { // CommonJS\n module.exports = factory(root);\n } else { // Browser globals\n root.annyang = factory(root);\n }\n})(typeof window !== 'undefined' ? window : this, function(root, undefined) {\n 'use strict';\n\n /**\n * # Quick Tutorial, Intro and Demos\n *\n * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/).\n *\n * For a more in-depth look at annyang, read on.\n *\n * # API Reference\n */\n\n var annyang;\n\n // Get the SpeechRecognition object, while handling browser prefixes\n var SpeechRecognition = root.SpeechRecognition ||\n root.webkitSpeechRecognition ||\n root.mozSpeechRecognition ||\n root.msSpeechRecognition ||\n root.oSpeechRecognition;\n\n // Check browser support\n // This is done as early as possible, to make it as fast as possible for unsupported browsers\n if (!SpeechRecognition) {\n return null;\n }\n\n var commandsList = [];\n var recognition;\n var callbacks = {\n start: [],\n error: [],\n end: [],\n soundstart: [],\n result: [],\n resultMatch: [],\n resultNoMatch: [],\n errorNetwork: [],\n errorPermissionBlocked: [],\n errorPermissionDenied: [],\n };\n var autoRestart;\n var lastStartedAt = 0;\n var autoRestartCount = 0;\n var debugState = false;\n var debugStyle = 'font-weight: bold; color: #00f;';\n var pauseListening = false;\n var isListening = false;\n\n // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license.\n var optionalParam = /\\s*\\((.*?)\\)\\s*/g;\n var optionalRegex = /(\\(\\?:[^)]+\\))\\?/g;\n var namedParam = /(\\(\\?)?:\\w+/g;\n var splatParam = /\\*\\w+/g;\n var escapeRegExp = /[-{}[\\]+?.,\\\\^$|#]/g;\n var commandToRegExp = function(command) {\n command = command\n .replace(escapeRegExp, '\\\\$&')\n .replace(optionalParam, '(?:$1)?')\n .replace(namedParam, function(match, optional) {\n return optional ? match : '([^\\\\s]+)';\n })\n .replace(splatParam, '(.*?)')\n .replace(optionalRegex, '\\\\s*$1?\\\\s*');\n return new RegExp('^' + command + '$', 'i');\n };\n\n // This method receives an array of callbacks to iterate over, and invokes each of them\n var invokeCallbacks = function(callbacks, ...args) {\n callbacks.forEach(function(callback) {\n callback.callback.apply(callback.context, args);\n });\n };\n\n var isInitialized = function() {\n return recognition !== undefined;\n };\n\n // method for logging in developer console when debug mode is on\n var logMessage = function(text, extraParameters) {\n if (text.indexOf('%c') === -1 && !extraParameters) {\n console.log(text);\n } else {\n console.log(text, extraParameters || debugStyle);\n }\n };\n\n var initIfNeeded = function() {\n if (!isInitialized()) {\n annyang.init({}, false);\n }\n };\n\n var registerCommand = function(command, callback, originalPhrase) {\n commandsList.push({ command, callback, originalPhrase });\n if (debugState) {\n logMessage(\n 'Command successfully loaded: %c' + originalPhrase,\n debugStyle\n );\n }\n };\n\n var parseResults = function(results) {\n invokeCallbacks(callbacks.result, results);\n var commandText;\n // go over each of the 5 results and alternative results received (we have set maxAlternatives to 5 above)\n for (let i = 0; i < results.length; i++) {\n // the text recognized\n commandText = results[i].trim();\n if (debugState) {\n logMessage('Speech recognized: %c' + commandText, debugStyle);\n }\n\n // try and match recognized text to one of the commands on the list\n for (let j = 0, l = commandsList.length; j < l; j++) {\n var currentCommand = commandsList[j];\n var result = currentCommand.command.exec(commandText);\n if (result) {\n var parameters = result.slice(1);\n if (debugState) {\n logMessage(\n 'command matched: %c' + currentCommand.originalPhrase,\n debugStyle\n );\n if (parameters.length) {\n logMessage('with parameters', parameters);\n }\n }\n // execute the matched command\n currentCommand.callback.apply(this, parameters);\n invokeCallbacks(\n callbacks.resultMatch,\n commandText,\n currentCommand.originalPhrase,\n results\n );\n return;\n }\n }\n }\n invokeCallbacks(callbacks.resultNoMatch, results);\n };\n\n annyang = {\n /**\n * Initialize annyang with a list of commands to recognize.\n *\n * #### Examples:\n * ````javascript\n * var commands = {'hello :name': helloFunction};\n * var commands2 = {'hi': helloFunction};\n *\n * // initialize annyang, overwriting any previously added commands\n * annyang.init(commands, true);\n * // adds an additional command without removing the previous commands\n * annyang.init(commands2, false);\n * ````\n * 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.\n *\n * @param {Object} commands - Commands that annyang should listen to\n * @param {boolean} [resetCommands=true] - Remove all commands before initializing?\n * @method init\n * @deprecated\n * @see [Commands Object](#commands-object)\n */\n init: function(commands, resetCommands = true) {\n // Abort previous instances of recognition already running\n if (recognition && recognition.abort) {\n recognition.abort();\n }\n\n // initiate SpeechRecognition\n recognition = new SpeechRecognition();\n\n // Set the max number of alternative transcripts to try and match with a command\n recognition.maxAlternatives = 5;\n\n // In HTTPS, turn off continuous mode for faster results.\n // In HTTP, turn on continuous mode for much slower results, but no repeating security notices\n recognition.continuous = root.location.protocol === 'http:';\n\n // Sets the language to the default 'en-US'. This can be changed with annyang.setLanguage()\n recognition.lang = 'en-US';\n\n recognition.onstart = function() {\n isListening = true;\n invokeCallbacks(callbacks.start);\n };\n\n recognition.onsoundstart = function() {\n invokeCallbacks(callbacks.soundstart);\n };\n\n recognition.onerror = function(event) {\n invokeCallbacks(callbacks.error, event);\n switch (event.error) {\n case 'network':\n invokeCallbacks(callbacks.errorNetwork, event);\n break;\n case 'not-allowed':\n case 'service-not-allowed':\n // if permission to use the mic is denied, turn off auto-restart\n autoRestart = false;\n // determine if permission was denied by user or automatically.\n if (new Date().getTime() - lastStartedAt < 200) {\n invokeCallbacks(callbacks.errorPermissionBlocked, event);\n } else {\n invokeCallbacks(callbacks.errorPermissionDenied, event);\n }\n break;\n }\n };\n\n recognition.onend = function() {\n isListening = false;\n invokeCallbacks(callbacks.end);\n // annyang will auto restart if it is closed automatically and not by user action.\n if (autoRestart) {\n // play nicely with the browser, and never restart annyang automatically more than once per second\n var timeSinceLastStart = new Date().getTime() - lastStartedAt;\n autoRestartCount += 1;\n if (autoRestartCount % 10 === 0) {\n if (debugState) {\n logMessage(\n 'Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips.'\n );\n }\n }\n if (timeSinceLastStart < 1000) {\n setTimeout(function() {\n annyang.start({ paused: pauseListening });\n }, 1000 - timeSinceLastStart);\n } else {\n annyang.start({ paused: pauseListening });\n }\n }\n };\n\n recognition.onresult = function(event) {\n if (pauseListening) {\n if (debugState) {\n logMessage('Speech heard, but annyang is paused');\n }\n return false;\n }\n\n // Map the results to an array\n var SpeechRecognitionResult = event.results[event.resultIndex];\n var results = [];\n for (let k = 0; k < SpeechRecognitionResult.length; k++) {\n results[k] = SpeechRecognitionResult[k].transcript;\n }\n\n parseResults(results);\n };\n\n // build commands list\n if (resetCommands) {\n commandsList = [];\n }\n if (commands.length) {\n this.addCommands(commands);\n }\n },\n\n /**\n * Start listening.\n * It's a good idea to call this after adding some commands first, but not mandatory.\n *\n * Receives an optional options object which supports the following options:\n *\n * - `autoRestart` (boolean) Should annyang restart itself if it is closed indirectly, because of silence or window conflicts?\n * - `continuous` (boolean) Allow forcing continuous mode on or off. Annyang is pretty smart about this, so only set this if you know what you're doing.\n * - `paused` (boolean) Start annyang in paused mode.\n *\n * #### Examples:\n * ````javascript\n * // Start listening, don't restart automatically\n * annyang.start({ autoRestart: false });\n * // Start listening, don't restart automatically, stop recognition after first phrase recognized\n * annyang.start({ autoRestart: false, continuous: false });\n * ````\n * @param {Object} [options] - Optional options.\n * @method start\n */\n start: function(options) {\n initIfNeeded();\n options = options || {};\n if (options.paused !== undefined) {\n pauseListening = !!options.paused;\n } else {\n pauseListening = false;\n }\n if (options.autoRestart !== undefined) {\n autoRestart = !!options.autoRestart;\n } else {\n autoRestart = true;\n }\n if (options.continuous !== undefined) {\n recognition.continuous = !!options.continuous;\n }\n\n lastStartedAt = new Date().getTime();\n try {\n recognition.start();\n } catch (e) {\n if (debugState) {\n logMessage(e.message);\n }\n }\n },\n\n /**\n * Stop listening, and turn off mic.\n *\n * Alternatively, to only temporarily pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead.\n * @see [pause()](#pause)\n *\n * @method abort\n */\n abort: function() {\n autoRestart = false;\n autoRestartCount = 0;\n if (isInitialized()) {\n recognition.abort();\n }\n },\n\n /**\n * 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.\n *\n * Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead.\n * @see [abort()](#abort)\n *\n * @method pause\n */\n pause: function() {\n pauseListening = true;\n },\n\n /**\n * Resumes listening and restores command callback execution when a result matches.\n * If SpeechRecognition was aborted (stopped), start it.\n *\n * @method resume\n */\n resume: function() {\n annyang.start();\n },\n\n /**\n * Turn on output of debug messages to the console. Ugly, but super-handy!\n *\n * @param {boolean} [newState=true] - Turn on/off debug messages\n * @method debug\n */\n debug: function(newState = true) {\n debugState = !!newState;\n },\n\n /**\n * Set the language the user will speak in. If this method is not called, defaults to 'en-US'.\n *\n * @param {String} language - The language (locale)\n * @method setLanguage\n * @see [Languages](https://github.com/TalAter/annyang/blob/master/docs/FAQ.md#what-languages-are-supported)\n */\n setLanguage: function(language) {\n initIfNeeded();\n recognition.lang = language;\n },\n\n /**\n * Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands.\n *\n * #### Examples:\n * ````javascript\n * var commands = {'hello :name': helloFunction, 'howdy': helloFunction};\n * var commands2 = {'hi': helloFunction};\n *\n * annyang.addCommands(commands);\n * annyang.addCommands(commands2);\n * // annyang will now listen to all three commands\n * ````\n *\n * @param {Object} commands - Commands that annyang should listen to\n * @method addCommands\n * @see [Commands Object](#commands-object)\n */\n addCommands: function(commands) {\n var cb;\n\n initIfNeeded();\n\n for (let phrase in commands) {\n if (commands.hasOwnProperty(phrase)) {\n cb = root[commands[phrase]] || commands[phrase];\n if (typeof cb === 'function') {\n // convert command to regex then register the command\n registerCommand(commandToRegExp(phrase), cb, phrase);\n } else if (typeof cb === 'object' && cb.regexp instanceof RegExp) {\n // register the command\n registerCommand(\n new RegExp(cb.regexp.source, 'i'),\n cb.callback,\n phrase\n );\n } else {\n if (debugState) {\n logMessage('Can not register command: %c' + phrase, debugStyle);\n }\n continue;\n }\n }\n }\n },\n\n /**\n * Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands.\n *\n * #### Examples:\n * ````javascript\n * var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction};\n *\n * // Remove all existing commands\n * annyang.removeCommands();\n *\n * // Add some commands\n * annyang.addCommands(commands);\n *\n * // Don't respond to hello\n * annyang.removeCommands('hello');\n *\n * // Don't respond to howdy or hi\n * annyang.removeCommands(['howdy', 'hi']);\n * ````\n * @param {String|Array|Undefined} [commandsToRemove] - Commands to remove\n * @method removeCommands\n */\n removeCommands: function(commandsToRemove) {\n if (commandsToRemove === undefined) {\n commandsList = [];\n } else {\n commandsToRemove = Array.isArray(commandsToRemove) ? commandsToRemove : [commandsToRemove];\n commandsList = commandsList.filter(command => {\n for (let i = 0; i < commandsToRemove.length; i++) {\n if (commandsToRemove[i] === command.originalPhrase) {\n return false;\n }\n }\n return true;\n });\n }\n },\n\n /**\n * Add a callback function to be called in case one of the following events happens:\n *\n * * `start` - Fired as soon as the browser's Speech Recognition engine starts listening.\n *\n * * `soundstart` - Fired as soon as any sound (possibly speech) has been detected.\n *\n * This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start.\n *\n * * `error` - Fired when the browser's Speech Recogntion engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined).\n *\n * Callback function will be called with the error event as the first argument.\n *\n * * `errorNetwork` - Fired when Speech Recognition fails because of a network error.\n *\n * Callback function will be called with the error event as the first argument.\n *\n * * `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition.\n *\n * Callback function will be called with the error event as the first argument.\n *\n * * `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition.\n *\n * Callback function will be called with the error event as the first argument.\n *\n * * `end` - Fired when the browser's Speech Recognition engine stops.\n *\n * * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks.\n *\n * Callback functions for this event will be called with an array of possible phrases the user said as the first argument.\n *\n * * `resultMatch` - Fired when annyang was able to match between what the user said and a registered command.\n *\n * Callback functions for this event will be called with three arguments in the following order:\n *\n * * The phrase the user said that matched a command.\n * * The command that was matched.\n * * An array of possible alternative phrases the user might have said.\n *\n * * `resultNoMatch` - Fired when what the user said didn't match any of the registered commands.\n *\n * Callback functions for this event will be called with an array of possible phrases the user might have said as the first argument.\n *\n * #### Examples:\n * ````javascript\n * annyang.addCallback('error', function() {\n * $('.myErrorText').text('There was an error!');\n * });\n *\n * annyang.addCallback('resultMatch', function(userSaid, commandText, phrases) {\n * console.log(userSaid); // sample output: 'hello'\n * console.log(commandText); // sample output: 'hello (there)'\n * console.log(phrases); // sample output: ['hello', 'halo', 'yellow', 'polo', 'hello kitty']\n * });\n *\n * // pass local context to a global function called notConnected\n * annyang.addCallback('errorNetwork', notConnected, this);\n * ````\n * @param {String} type - Name of event that will trigger this callback\n * @param {Function} callback - The function to call when event is triggered\n * @param {Object} [context] - Optional context for the callback function\n * @method addCallback\n */\n addCallback: function(type, callback, context) {\n var cb = root[callback] || callback;\n if (typeof cb === 'function' && callbacks[type] !== undefined) {\n callbacks[type].push({ callback: cb, context: context || this });\n }\n },\n\n /**\n * Remove callbacks from events.\n *\n * - Pass an event name and a callback command to remove that callback command from that event type.\n * - Pass just an event name to remove all callback commands from that event type.\n * - Pass undefined as event name and a callback command to remove that callback command from all event types.\n * - Pass no params to remove all callback commands from all event types.\n *\n * #### Examples:\n * ````javascript\n * annyang.addCallback('start', myFunction1);\n * annyang.addCallback('start', myFunction2);\n * annyang.addCallback('end', myFunction1);\n * annyang.addCallback('end', myFunction2);\n *\n * // Remove all callbacks from all events:\n * annyang.removeCallback();\n *\n * // Remove all callbacks attached to end event:\n * annyang.removeCallback('end');\n *\n * // Remove myFunction2 from being called on start:\n * annyang.removeCallback('start', myFunction2);\n *\n * // Remove myFunction1 from being called on all events:\n * annyang.removeCallback(undefined, myFunction1);\n * ````\n *\n * @param type Name of event type to remove callback from\n * @param callback The callback function to remove\n * @returns undefined\n * @method removeCallback\n */\n removeCallback: function(type, callback) {\n var compareWithCallbackParameter = function(cb) {\n return cb.callback !== callback;\n };\n // Go over each callback type in callbacks store object\n for (let callbackType in callbacks) {\n if (callbacks.hasOwnProperty(callbackType)) {\n // if this is the type user asked to delete, or he asked to delete all, go ahead.\n if (type === undefined || type === callbackType) {\n // If user asked to delete all callbacks in this type or all types\n if (callback === undefined) {\n callbacks[callbackType] = [];\n } else {\n // Remove all matching callbacks\n callbacks[callbackType] = callbacks[callbackType].filter(compareWithCallbackParameter);\n }\n }\n }\n }\n },\n\n /**\n * Returns true if speech recognition is currently on.\n * Returns false if speech recognition is off or annyang is paused.\n *\n * @return boolean true = SpeechRecognition is on and annyang is listening\n * @method isListening\n */\n isListening: function() {\n return isListening && !pauseListening;\n },\n\n /**\n * Returns the instance of the browser's SpeechRecognition object used by annyang.\n * Useful in case you want direct access to the browser's Speech Recognition engine.\n *\n * @returns SpeechRecognition The browser's Speech Recognizer currently used by annyang\n * @method getSpeechRecognizer\n */\n getSpeechRecognizer: function() {\n return recognition;\n },\n\n /**\n * Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition\n * detects speech.\n *\n * Can accept either a string containing a single sentence, or an array containing multiple sentences to be checked\n * in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed)\n *\n * #### Examples:\n * ````javascript\n * annyang.trigger('Time for some thrilling heroics');\n * annyang.trigger(\n * ['Time for some thrilling heroics', 'Time for some thrilling aerobics']\n * );\n * ````\n *\n * @param string|array sentences A sentence as a string or an array of strings of possible sentences\n * @returns undefined\n * @method trigger\n */\n trigger: function(sentences) {\n if (!annyang.isListening()) {\n if (debugState) {\n if (!isListening) {\n logMessage('Cannot trigger while annyang is aborted');\n } else {\n logMessage('Speech heard, but annyang is paused');\n }\n }\n return;\n }\n\n if (!Array.isArray(sentences)) {\n sentences = [sentences];\n }\n\n parseResults(sentences);\n },\n };\n\n return annyang;\n});\n\n/**\n * # Good to Know\n *\n * ## Commands Object\n *\n * Both the [init()]() and addCommands() methods receive a `commands` object.\n *\n * annyang understands commands with `named variables`, `splats`, and `optional words`.\n *\n * * Use `named variables` for one word arguments in your command.\n * * Use `splats` to capture multi-word text at the end of your command (greedy).\n * * Use `optional words` or phrases to define a part of the command as optional.\n *\n * #### Examples:\n * ````html\n * \n * ````\n *\n * ### Using Regular Expressions in commands\n * For advanced commands, you can pass a regular expression object, instead of\n * a simple string command.\n *\n * This is done by passing an object containing two properties: `regexp`, and\n * `callback` instead of the function.\n *\n * #### Examples:\n * ````javascript\n * var calculateFunction = function(month) { console.log(month); }\n * var commands = {\n * // This example will accept any word as the \"month\"\n * 'calculate :month stats': calculateFunction,\n * // This example will only accept months which are at the start of a quarter\n * 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction}\n * }\n ````\n *\n */\n"]} \ No newline at end of file +{"version":3,"sources":["../src/annyang.js"],"names":["root","factory","define","amd","annyang","module","exports","window","undefined","SpeechRecognition","webkitSpeechRecognition","mozSpeechRecognition","msSpeechRecognition","oSpeechRecognition","commandsList","recognition","callbacks","start","error","end","soundstart","result","resultMatch","resultNoMatch","errorNetwork","errorPermissionBlocked","errorPermissionDenied","autoRestart","lastStartedAt","autoRestartCount","debugState","debugStyle","pauseListening","isListening","optionalParam","optionalRegex","namedParam","splatParam","escapeRegExp","commandToRegExp","command","replace","match","optional","RegExp","invokeCallbacks","args","forEach","callback","apply","context","isInitialized","logMessage","text","extraParameters","indexOf","console","log","initIfNeeded","init","registerCommand","originalPhrase","push","parseResults","results","commandText","i","length","trim","j","l","currentCommand","exec","parameters","slice","commands","resetCommands","abort","maxAlternatives","continuous","location","protocol","lang","onstart","onsoundstart","onerror","event","Date","getTime","onend","timeSinceLastStart","setTimeout","paused","onresult","SpeechRecognitionResult","resultIndex","k","transcript","addCommands","options","e","message","pause","resume","debug","newState","setLanguage","language","cb","phrase","hasOwnProperty","regexp","source","removeCommands","commandsToRemove","Array","isArray","filter","addCallback","type","removeCallback","compareWithCallbackParameter","callbackType","getSpeechRecognizer","trigger","sentences"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA,CAAC,UAASA,IAAT,EAAeC,OAAf,EAAwB;AACvB;;AACA,MAAI,OAAOC,MAAP,KAAkB,UAAlB,IAAgCA,OAAOC,GAA3C,EAAgD;AAAE;AAChDD,WAAO,EAAP,EAAW,YAAY;AACrB,aAAQF,KAAKI,OAAL,GAAeH,QAAQD,IAAR,CAAvB;AACD,KAFD;AAGD,GAJD,MAIO,IAAI,QAAOK,MAAP,yCAAOA,MAAP,OAAkB,QAAlB,IAA8BA,OAAOC,OAAzC,EAAkD;AAAE;AACzDD,WAAOC,OAAP,GAAiBL,QAAQD,IAAR,CAAjB;AACD,GAFM,MAEA;AAAE;AACPA,SAAKI,OAAL,GAAeH,QAAQD,IAAR,CAAf;AACD;AACF,CAXD,EAWG,OAAOO,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,YAXH,EAWkD,UAASP,IAAT,EAAeQ,SAAf,EAA0B;AAC1E;;AAEA;;;;;;;;;;AAUA,MAAIJ,OAAJ;;AAEA;AACA,MAAIK,oBAAoBT,KAAKS,iBAAL,IACAT,KAAKU,uBADL,IAEAV,KAAKW,oBAFL,IAGAX,KAAKY,mBAHL,IAIAZ,KAAKa,kBAJ7B;;AAMA;AACA;AACA,MAAI,CAACJ,iBAAL,EAAwB;AACtB,WAAO,IAAP;AACD;;AAED,MAAIK,eAAe,EAAnB;AACA,MAAIC,WAAJ;AACA,MAAIC,YAAY;AACdC,WAAO,EADO;AAEdC,WAAO,EAFO;AAGdC,SAAK,EAHS;AAIdC,gBAAY,EAJE;AAKdC,YAAQ,EALM;AAMdC,iBAAa,EANC;AAOdC,mBAAe,EAPD;AAQdC,kBAAc,EARA;AASdC,4BAAwB,EATV;AAUdC,2BAAuB;AAVT,GAAhB;AAYA,MAAIC,WAAJ;AACA,MAAIC,gBAAgB,CAApB;AACA,MAAIC,mBAAmB,CAAvB;AACA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AACD,cAAvB;AACD,KA7bO;;AA+bR;;;;;;;AAOA2F,yBAAqB,+BAAW;AAC9B,aAAO5G,WAAP;AACD,KAxcO;;AA0cR;;;;;;;;;;;;;;;;;;;AAmBA6G,aAAS,iBAASC,SAAT,EAAoB;AAC3B,UAAI,CAACzH,QAAQ6B,WAAR,EAAL,EAA4B;AAC1B,YAAIH,UAAJ,EAAgB;AACd,cAAI,CAACG,YAAL,EAAkB;AAChBmB,uBAAW,yCAAX;AACD,WAFD,MAEO;AACLA,uBAAW,qCAAX;AACD;AACF;AACD;AACD;;AAED,UAAI,CAAC+D,MAAMC,OAAN,CAAcS,SAAd,CAAL,EAA+B;AAC7BA,oBAAY,CAACA,SAAD,CAAZ;AACD;;AAED9D,mBAAa8D,SAAb;AACD;AA9eO,GAAV;;AAifA,SAAOzH,OAAP;AACD,CA9oBD;;AAgpBA","file":"annyang.js","sourcesContent":["//! annyang\n//! version : 2.6.1\n//! author : Tal Ater @TalAter\n//! license : MIT\n//! https://www.TalAter.com/annyang/\n(function(root, factory) {\n 'use strict';\n if (typeof define === 'function' && define.amd) { // AMD + global\n define([], function () {\n return (root.annyang = factory(root));\n });\n } else if (typeof module === 'object' && module.exports) { // CommonJS\n module.exports = factory(root);\n } else { // Browser globals\n root.annyang = factory(root);\n }\n})(typeof window !== 'undefined' ? window : this, function(root, undefined) {\n 'use strict';\n\n /**\n * # Quick Tutorial, Intro, and Demos\n *\n * The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/).\n *\n * For a more in-depth look at annyang, read on.\n *\n * # API Reference\n */\n\n var annyang;\n\n // Get the SpeechRecognition object, while handling browser prefixes\n var SpeechRecognition = root.SpeechRecognition ||\n root.webkitSpeechRecognition ||\n root.mozSpeechRecognition ||\n root.msSpeechRecognition ||\n root.oSpeechRecognition;\n\n // Check browser support\n // This is done as early as possible, to make it as fast as possible for unsupported browsers\n if (!SpeechRecognition) {\n return null;\n }\n\n var commandsList = [];\n var recognition;\n var callbacks = {\n start: [],\n error: [],\n end: [],\n soundstart: [],\n result: [],\n resultMatch: [],\n resultNoMatch: [],\n errorNetwork: [],\n errorPermissionBlocked: [],\n errorPermissionDenied: [],\n };\n var autoRestart;\n var lastStartedAt = 0;\n var autoRestartCount = 0;\n var debugState = false;\n var debugStyle = 'font-weight: bold; color: #00f;';\n var pauseListening = false;\n var isListening = false;\n\n // The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license.\n var optionalParam = /\\s*\\((.*?)\\)\\s*/g;\n var optionalRegex = /(\\(\\?:[^)]+\\))\\?/g;\n var namedParam = /(\\(\\?)?:\\w+/g;\n var splatParam = /\\*\\w+/g;\n var escapeRegExp = /[-{}[\\]+?.,\\\\^$|#]/g;\n var commandToRegExp = function(command) {\n command = command\n .replace(escapeRegExp, '\\\\$&')\n .replace(optionalParam, '(?:$1)?')\n .replace(namedParam, function(match, optional) {\n return optional ? match : '([^\\\\s]+)';\n })\n .replace(splatParam, '(.*?)')\n .replace(optionalRegex, '\\\\s*$1?\\\\s*');\n return new RegExp('^' + command + '$', 'i');\n };\n\n // This method receives an array of callbacks to iterate over, and invokes each of them\n var invokeCallbacks = function(callbacks, ...args) {\n callbacks.forEach(function(callback) {\n callback.callback.apply(callback.context, args);\n });\n };\n\n var isInitialized = function() {\n return recognition !== undefined;\n };\n\n // method for logging in developer console when debug mode is on\n var logMessage = function(text, extraParameters) {\n if (text.indexOf('%c') === -1 && !extraParameters) {\n console.log(text);\n } else {\n console.log(text, extraParameters || debugStyle);\n }\n };\n\n var initIfNeeded = function() {\n if (!isInitialized()) {\n annyang.init({}, false);\n }\n };\n\n var registerCommand = function(command, callback, originalPhrase) {\n commandsList.push({ command, callback, originalPhrase });\n if (debugState) {\n logMessage(\n 'Command successfully loaded: %c' + originalPhrase,\n debugStyle\n );\n }\n };\n\n var parseResults = function(results) {\n invokeCallbacks(callbacks.result, results);\n var commandText;\n // go over each of the 5 results and alternative results received (we have set maxAlternatives to 5 above)\n for (let i = 0; i < results.length; i++) {\n // the text recognized\n commandText = results[i].trim();\n if (debugState) {\n logMessage('Speech recognized: %c' + commandText, debugStyle);\n }\n\n // try and match recognized text to one of the commands on the list\n for (let j = 0, l = commandsList.length; j < l; j++) {\n var currentCommand = commandsList[j];\n var result = currentCommand.command.exec(commandText);\n if (result) {\n var parameters = result.slice(1);\n if (debugState) {\n logMessage(\n 'command matched: %c' + currentCommand.originalPhrase,\n debugStyle\n );\n if (parameters.length) {\n logMessage('with parameters', parameters);\n }\n }\n // execute the matched command\n currentCommand.callback.apply(this, parameters);\n invokeCallbacks(\n callbacks.resultMatch,\n commandText,\n currentCommand.originalPhrase,\n results\n );\n return;\n }\n }\n }\n invokeCallbacks(callbacks.resultNoMatch, results);\n };\n\n annyang = {\n /**\n * Initialize annyang with a list of commands to recognize.\n *\n * #### Examples:\n * ````javascript\n * var commands = {'hello :name': helloFunction};\n * var commands2 = {'hi': helloFunction};\n *\n * // initialize annyang, overwriting any previously added commands\n * annyang.init(commands, true);\n * // adds an additional command without removing the previous commands\n * annyang.init(commands2, false);\n * ````\n * 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.\n *\n * @param {Object} commands - Commands that annyang should listen to\n * @param {boolean} [resetCommands=true] - Remove all commands before initializing?\n * @method init\n * @deprecated\n * @see [Commands Object](#commands-object)\n */\n init: function(commands, resetCommands = true) {\n // Abort previous instances of recognition already running\n if (recognition && recognition.abort) {\n recognition.abort();\n }\n\n // initiate SpeechRecognition\n recognition = new SpeechRecognition();\n\n // Set the max number of alternative transcripts to try and match with a command\n recognition.maxAlternatives = 5;\n\n // In HTTPS, turn off continuous mode for faster results.\n // In HTTP, turn on continuous mode for much slower results, but no repeating security notices\n recognition.continuous = root.location.protocol === 'http:';\n\n // Sets the language to the default 'en-US'. This can be changed with annyang.setLanguage()\n recognition.lang = 'en-US';\n\n recognition.onstart = function() {\n isListening = true;\n invokeCallbacks(callbacks.start);\n };\n\n recognition.onsoundstart = function() {\n invokeCallbacks(callbacks.soundstart);\n };\n\n recognition.onerror = function(event) {\n invokeCallbacks(callbacks.error, event);\n switch (event.error) {\n case 'network':\n invokeCallbacks(callbacks.errorNetwork, event);\n break;\n case 'not-allowed':\n case 'service-not-allowed':\n // if permission to use the mic is denied, turn off auto-restart\n autoRestart = false;\n // determine if permission was denied by user or automatically.\n if (new Date().getTime() - lastStartedAt < 200) {\n invokeCallbacks(callbacks.errorPermissionBlocked, event);\n } else {\n invokeCallbacks(callbacks.errorPermissionDenied, event);\n }\n break;\n }\n };\n\n recognition.onend = function() {\n isListening = false;\n invokeCallbacks(callbacks.end);\n // annyang will auto restart if it is closed automatically and not by user action.\n if (autoRestart) {\n // play nicely with the browser, and never restart annyang automatically more than once per second\n var timeSinceLastStart = new Date().getTime() - lastStartedAt;\n autoRestartCount += 1;\n if (autoRestartCount % 10 === 0) {\n if (debugState) {\n logMessage(\n 'Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips.'\n );\n }\n }\n if (timeSinceLastStart < 1000) {\n setTimeout(function() {\n annyang.start({ paused: pauseListening });\n }, 1000 - timeSinceLastStart);\n } else {\n annyang.start({ paused: pauseListening });\n }\n }\n };\n\n recognition.onresult = function(event) {\n if (pauseListening) {\n if (debugState) {\n logMessage('Speech heard, but annyang is paused');\n }\n return false;\n }\n\n // Map the results to an array\n var SpeechRecognitionResult = event.results[event.resultIndex];\n var results = [];\n for (let k = 0; k < SpeechRecognitionResult.length; k++) {\n results[k] = SpeechRecognitionResult[k].transcript;\n }\n\n parseResults(results);\n };\n\n // build commands list\n if (resetCommands) {\n commandsList = [];\n }\n if (commands.length) {\n this.addCommands(commands);\n }\n },\n\n /**\n * Start listening.\n * It's a good idea to call this after adding some commands first, but not mandatory.\n *\n * Receives an optional options object which supports the following options:\n *\n * - `autoRestart` (boolean) Should annyang restart itself if it is closed indirectly, because of silence or window conflicts?\n * - `continuous` (boolean) Allow forcing continuous mode on or off. Annyang is pretty smart about this, so only set this if you know what you're doing.\n * - `paused` (boolean) Start annyang in paused mode.\n *\n * #### Examples:\n * ````javascript\n * // Start listening, don't restart automatically\n * annyang.start({ autoRestart: false });\n * // Start listening, don't restart automatically, stop recognition after first phrase recognized\n * annyang.start({ autoRestart: false, continuous: false });\n * ````\n * @param {Object} [options] - Optional options.\n * @method start\n */\n start: function(options) {\n initIfNeeded();\n options = options || {};\n if (options.paused !== undefined) {\n pauseListening = !!options.paused;\n } else {\n pauseListening = false;\n }\n if (options.autoRestart !== undefined) {\n autoRestart = !!options.autoRestart;\n } else {\n autoRestart = true;\n }\n if (options.continuous !== undefined) {\n recognition.continuous = !!options.continuous;\n }\n\n lastStartedAt = new Date().getTime();\n try {\n recognition.start();\n } catch (e) {\n if (debugState) {\n logMessage(e.message);\n }\n }\n },\n\n /**\n * Stop listening, and turn off mic.\n *\n * Alternatively, to only temporarily pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead.\n * @see [pause()](#pause)\n *\n * @method abort\n */\n abort: function() {\n autoRestart = false;\n autoRestartCount = 0;\n if (isInitialized()) {\n recognition.abort();\n }\n },\n\n /**\n * 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.\n *\n * Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead.\n * @see [abort()](#abort)\n *\n * @method pause\n */\n pause: function() {\n pauseListening = true;\n },\n\n /**\n * Resumes listening and restore command callback execution when a result matches.\n * If SpeechRecognition was aborted (stopped), start it.\n *\n * @method resume\n */\n resume: function() {\n annyang.start();\n },\n\n /**\n * Turn on the output of debug messages to the console. Ugly, but super-handy!\n *\n * @param {boolean} [newState=true] - Turn on/off debug messages\n * @method debug\n */\n debug: function(newState = true) {\n debugState = !!newState;\n },\n\n /**\n * Set the language the user will speak in. If this method is not called, defaults to 'en-US'.\n *\n * @param {String} language - The language (locale)\n * @method setLanguage\n * @see [Languages](https://github.com/TalAter/annyang/blob/master/docs/FAQ.md#what-languages-are-supported)\n */\n setLanguage: function(language) {\n initIfNeeded();\n recognition.lang = language;\n },\n\n /**\n * Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands.\n *\n * #### Examples:\n * ````javascript\n * var commands = {'hello :name': helloFunction, 'howdy': helloFunction};\n * var commands2 = {'hi': helloFunction};\n *\n * annyang.addCommands(commands);\n * annyang.addCommands(commands2);\n * // annyang will now listen to all three commands\n * ````\n *\n * @param {Object} commands - Commands that annyang should listen to\n * @method addCommands\n * @see [Commands Object](#commands-object)\n */\n addCommands: function(commands) {\n var cb;\n\n initIfNeeded();\n\n for (let phrase in commands) {\n if (commands.hasOwnProperty(phrase)) {\n cb = root[commands[phrase]] || commands[phrase];\n if (typeof cb === 'function') {\n // convert command to regex then register the command\n registerCommand(commandToRegExp(phrase), cb, phrase);\n } else if (typeof cb === 'object' && cb.regexp instanceof RegExp) {\n // register the command\n registerCommand(\n new RegExp(cb.regexp.source, 'i'),\n cb.callback,\n phrase\n );\n } else {\n if (debugState) {\n logMessage('Can not register command: %c' + phrase, debugStyle);\n }\n continue;\n }\n }\n }\n },\n\n /**\n * Remove existing commands. Called with a single phrase, an array of phrases, or methodically. Pass no params to remove all commands.\n *\n * #### Examples:\n * ````javascript\n * var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction};\n *\n * // Remove all existing commands\n * annyang.removeCommands();\n *\n * // Add some commands\n * annyang.addCommands(commands);\n *\n * // Don't respond to hello\n * annyang.removeCommands('hello');\n *\n * // Don't respond to howdy or hi\n * annyang.removeCommands(['howdy', 'hi']);\n * ````\n * @param {String|Array|Undefined} [commandsToRemove] - Commands to remove\n * @method removeCommands\n */\n removeCommands: function(commandsToRemove) {\n if (commandsToRemove === undefined) {\n commandsList = [];\n } else {\n commandsToRemove = Array.isArray(commandsToRemove) ? commandsToRemove : [commandsToRemove];\n commandsList = commandsList.filter(command => {\n for (let i = 0; i < commandsToRemove.length; i++) {\n if (commandsToRemove[i] === command.originalPhrase) {\n return false;\n }\n }\n return true;\n });\n }\n },\n\n /**\n * Add a callback function to be called in case one of the following events happens:\n *\n * * `start` - Fired as soon as the browser's Speech Recognition engine starts listening.\n *\n * * `soundstart` - Fired as soon as any sound (possibly speech) has been detected.\n *\n * This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start.\n *\n * * `error` - Fired when the browser's Speech Recognition engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined).\n *\n * The Callback function will be called with the error event as the first argument.\n *\n * * `errorNetwork` - Fired when Speech Recognition fails because of a network error.\n *\n * The Callback function will be called with the error event as the first argument.\n *\n * * `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition.\n *\n * The Callback function will be called with the error event as the first argument.\n *\n * * `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition.\n *\n * The Callback function will be called with the error event as the first argument.\n *\n * * `end` - Fired when the browser's Speech Recognition engine stops.\n *\n * * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks.\n *\n * The Callback functions for this event will be called with an array of possible phrases the user said as the first argument.\n *\n * * `resultMatch` - Fired when annyang was able to match between what the user said and a registered command.\n *\n * The Callback functions for this event will be called with three arguments in the following order:\n *\n * * The phrase the user said that matched a command.\n * * The command that was matched.\n * * An array of possible alternative phrases the user might have said.\n *\n * * `resultNoMatch` - Fired when what the user said didn't match any of the registered commands.\n *\n * Callback functions for this event will be called with an array of possible phrases the user might have said as the first argument.\n *\n * #### Examples:\n * ````javascript\n * annyang.addCallback('error', function() {\n * $('.myErrorText').text('There was an error!');\n * });\n *\n * annyang.addCallback('resultMatch', function(userSaid, commandText, phrases) {\n * console.log(userSaid); // sample output: 'hello'\n * console.log(commandText); // sample output: 'hello (there)'\n * console.log(phrases); // sample output: ['hello', 'halo', 'yellow', 'polo', 'hello kitty']\n * });\n *\n * // pass local context to a global function called notConnected\n * annyang.addCallback('errorNetwork', notConnected, this);\n * ````\n * @param {String} type - Name of event that will trigger this callback\n * @param {Function} callback - The function to call when event is triggered\n * @param {Object} [context] - Optional context for the callback function\n * @method addCallback\n */\n addCallback: function(type, callback, context) {\n var cb = root[callback] || callback;\n if (typeof cb === 'function' && callbacks[type] !== undefined) {\n callbacks[type].push({ callback: cb, context: context || this });\n }\n },\n\n /**\n * Remove callbacks from events.\n *\n * - Pass an event name and a callback command to remove that callback command from that event type.\n * - Pass just an event name to remove all callback commands from that event type.\n * - Pass undefined as event name and a callback command to remove that callback command from all event types.\n * - Pass no params to remove all callback commands from all event types.\n *\n * #### Examples:\n * ````javascript\n * annyang.addCallback('start', myFunction1);\n * annyang.addCallback('start', myFunction2);\n * annyang.addCallback('end', myFunction1);\n * annyang.addCallback('end', myFunction2);\n *\n * // Remove all callbacks from all events:\n * annyang.removeCallback();\n *\n * // Remove all callbacks attached to end event:\n * annyang.removeCallback('end');\n *\n * // Remove myFunction2 from being called on start:\n * annyang.removeCallback('start', myFunction2);\n *\n * // Remove myFunction1 from being called on all events:\n * annyang.removeCallback(undefined, myFunction1);\n * ````\n *\n * @param type Name of event type to remove callback from\n * @param callback The callback function to remove\n * @returns undefined\n * @method removeCallback\n */\n removeCallback: function(type, callback) {\n var compareWithCallbackParameter = function(cb) {\n return cb.callback !== callback;\n };\n // Go over each callback type in callbacks store object\n for (let callbackType in callbacks) {\n if (callbacks.hasOwnProperty(callbackType)) {\n // if this is the type user asked to delete, or he asked to delete all, go ahead.\n if (type === undefined || type === callbackType) {\n // If user asked to delete all callbacks in this type or all types\n if (callback === undefined) {\n callbacks[callbackType] = [];\n } else {\n // Remove all matching callbacks\n callbacks[callbackType] = callbacks[callbackType].filter(compareWithCallbackParameter);\n }\n }\n }\n }\n },\n\n /**\n * Returns true if speech recognition is currently on.\n * Returns false if speech recognition is off or annyang is paused.\n *\n * @return boolean true = SpeechRecognition is on and annyang is listening\n * @method isListening\n */\n isListening: function() {\n return isListening && !pauseListening;\n },\n\n /**\n * Returns the instance of the browser's SpeechRecognition object used by annyang.\n * Useful in case you want direct access to the browser's Speech Recognition engine.\n *\n * @returns SpeechRecognition The browser's Speech Recognizer currently used by annyang\n * @method getSpeechRecognizer\n */\n getSpeechRecognizer: function() {\n return recognition;\n },\n\n /**\n * Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition\n * detects speech.\n *\n * Can accept either a string containing a single sentence or an array containing multiple sentences to be checked\n * in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed)\n *\n * #### Examples:\n * ````javascript\n * annyang.trigger('Time for some thrilling heroics');\n * annyang.trigger(\n * ['Time for some thrilling heroics', 'Time for some thrilling aerobics']\n * );\n * ````\n *\n * @param string|array sentences A sentence as a string or an array of strings of possible sentences\n * @returns undefined\n * @method trigger\n */\n trigger: function(sentences) {\n if (!annyang.isListening()) {\n if (debugState) {\n if (!isListening) {\n logMessage('Cannot trigger while annyang is aborted');\n } else {\n logMessage('Speech heard, but annyang is paused');\n }\n }\n return;\n }\n\n if (!Array.isArray(sentences)) {\n sentences = [sentences];\n }\n\n parseResults(sentences);\n },\n };\n\n return annyang;\n});\n\n/**\n * # Good to Know\n *\n * ## Commands Object\n *\n * Both the [init()]() and addCommands() methods receive a `commands` object.\n *\n * annyang understands commands with `named variables`, `splats`, and `optional words`.\n *\n * * Use `named variables` for one-word arguments in your command.\n * * Use `splats` to capture multi-word text at the end of your command (greedy).\n * * Use `optional words` or phrases to define a part of the command as optional.\n *\n * #### Examples:\n * ````html\n * \n * ````\n *\n * ### Using Regular Expressions in commands\n * For advanced commands, you can pass a regular expression object, instead of\n * a simple string command.\n *\n * This is done by passing an object containing two properties: `regexp`, and\n * `callback` instead of the function.\n *\n * #### Examples:\n * ````javascript\n * var calculateFunction = function(month) { console.log(month); }\n * var commands = {\n * // This example will accept any word as the \"month\"\n * 'calculate :month stats': calculateFunction,\n * // This example will only accept months which are at the start of a quarter\n * 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction}\n * }\n ````\n *\n */\n"]} \ No newline at end of file From d0a113f0a7589a04568520642dc64b1c258291e9 Mon Sep 17 00:00:00 2001 From: Tal Ater Date: Fri, 22 Feb 2019 02:12:50 +0200 Subject: [PATCH 9/9] Fix directory separators in README --- docs/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 6b56661..240dbd3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ - + # Quick Tutorial, Intro, and Demos @@ -350,5 +350,5 @@ var commands = { } ```` - +