annyang 2.6.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +56 -32
  3. package/dist/annyang.cjs +361 -0
  4. package/dist/annyang.cjs.map +1 -0
  5. package/dist/annyang.d.cts +288 -0
  6. package/dist/annyang.d.ts +288 -0
  7. package/dist/annyang.iife.min.js +1 -0
  8. package/dist/annyang.js +303 -670
  9. package/dist/annyang.js.map +1 -1
  10. package/package.json +55 -31
  11. package/.editorconfig +0 -13
  12. package/.eslintrc.json +0 -34
  13. package/.gitattributes +0 -1
  14. package/.github/ISSUE_TEMPLATE.md +0 -32
  15. package/.github/PULL_REQUEST_TEMPLATE.md +0 -29
  16. package/.jshintrc +0 -31
  17. package/.travis.yml +0 -20
  18. package/CONTRIBUTING.md +0 -75
  19. package/Gruntfile.js +0 -144
  20. package/bower.json +0 -25
  21. package/demo/css/main.css +0 -152
  22. package/demo/css/main.min.css +0 -1
  23. package/demo/images/flickr.png +0 -0
  24. package/demo/images/footer_background.jpg +0 -0
  25. package/demo/images/icon_js.png +0 -0
  26. package/demo/images/icon_speech.png +0 -0
  27. package/demo/images/icon_user.png +0 -0
  28. package/demo/images/mini_icon_say.png +0 -0
  29. package/demo/images/palette.png +0 -0
  30. package/demo/images/tpscover.jpg +0 -0
  31. package/demo/index.html +0 -225
  32. package/demo/vendor/css/default.css +0 -135
  33. package/demo/vendor/css/github.css +0 -127
  34. package/demo/vendor/css/tomorrow.css +0 -49
  35. package/demo/vendor/html/github-btn.html +0 -243
  36. package/demo/vendor/js/highlight.pack.js +0 -1
  37. package/dist/annyang.min.js +0 -12
  38. package/docs/FAQ.md +0 -223
  39. package/docs/README.md +0 -336
  40. package/require.js +0 -36
  41. package/sites/README.md +0 -6
  42. package/sites/facebook.js +0 -123
  43. package/sites/facebook.min.js +0 -17
  44. package/sites/geektime.js +0 -108
  45. package/sites/geektime.min.js +0 -17
  46. package/src/annyang.js +0 -680
  47. package/test/SpecRunner.html +0 -41
  48. package/test/init_corti.js +0 -1
  49. package/test/spec/.jshintrc +0 -40
  50. package/test/spec/BasicSpec.js +0 -1616
  51. package/test/spec/IssuesSpec.js +0 -41
  52. package/test/vendor/corti.js +0 -202
  53. package/yarn.lock +0 -4190
package/docs/FAQ.md DELETED
@@ -1,223 +0,0 @@
1
- # Frequently Asked Questions
2
-
3
- - [What languages are supported?](#what-languages-are-supported)
4
- - [Why does the browser repeatedly ask for permission to use the microphone?](#why-does-the-browser-repeatedly-ask-for-permission-to-use-the-microphone)
5
- - [What can I do to make speech recognition results return faster?](#what-can-i-do-to-make-speech-recognition-results-return-faster)
6
- - [How can I contribute to annyang's development?](#how-can-i-contribute-to-annyangs-development)
7
- - [Why does Speech Recognition repeatedly starts and stops?](#why-does-speech-recognition-repeatedly-starts-and-stops)
8
- - [Can annyang work offline?](#can-annyang-work-offline)
9
- - [Which browsers are supported?](#which-browsers-are-supported)
10
- - [Can annyang be used to capture the full text spoken by the user?](#can-annyang-be-used-to-capture-the-full-text-spoken-by-the-user)
11
- - [Can I detect when the user starts and stops speaking?](#can-i-detect-when-the-user-starts-and-stops-speaking)
12
- - [Can annyang be used in Chromium or Electron?](#can-annyang-be-used-in-chromium-or-electron)
13
- - [Can annyang be used in Cordova?](#can-annyang-be-used-in-cordova)
14
-
15
- ## What languages are supported?
16
-
17
- Language support is up to each browser. While there isn't an official list of supported languages in Chrome, here is a list based on [anecdotal evidence](http://stackoverflow.com/a/14302134/338039).
18
-
19
- * Afrikaans `af`
20
- * Basque `eu`
21
- * Bulgarian `bg`
22
- * Catalan `ca`
23
- * Arabic (Egypt) `ar-EG`
24
- * Arabic (Jordan) `ar-JO`
25
- * Arabic (Kuwait) `ar-KW`
26
- * Arabic (Lebanon) `ar-LB`
27
- * Arabic (Qatar) `ar-QA`
28
- * Arabic (UAE) `ar-AE`
29
- * Arabic (Morocco) `ar-MA`
30
- * Arabic (Iraq) `ar-IQ`
31
- * Arabic (Algeria) `ar-DZ`
32
- * Arabic (Bahrain) `ar-BH`
33
- * Arabic (Lybia) `ar-LY`
34
- * Arabic (Oman) `ar-OM`
35
- * Arabic (Saudi Arabia) `ar-SA`
36
- * Arabic (Tunisia) `ar-TN`
37
- * Arabic (Yemen) `ar-YE`
38
- * Czech `cs`
39
- * Dutch `nl-NL`
40
- * English (Australia) `en-AU`
41
- * English (Canada) `en-CA`
42
- * English (India) `en-IN`
43
- * English (New Zealand) `en-NZ`
44
- * English (South Africa) `en-ZA`
45
- * English(UK) `en-GB`
46
- * English(US) `en-US`
47
- * Finnish `fi`
48
- * French `fr-FR`
49
- * Galician `gl`
50
- * German `de-DE`
51
- * Greek `el-GR`
52
- * Hebrew `he`
53
- * Hungarian `hu`
54
- * Icelandic `is`
55
- * Italian `it-IT`
56
- * Indonesian `id`
57
- * Japanese `ja`
58
- * Korean `ko`
59
- * Latin `la`
60
- * Mandarin Chinese `zh-CN`
61
- * Traditional Taiwan `zh-TW`
62
- * Simplified China zh-CN `?`
63
- * Simplified Hong Kong `zh-HK`
64
- * Yue Chinese (Traditional Hong Kong) `zh-yue`
65
- * Malaysian `ms-MY`
66
- * Norwegian `no-NO`
67
- * Polish `pl`
68
- * Pig Latin `xx-piglatin`
69
- * Portuguese `pt-PT`
70
- * Portuguese (Brasil) `pt-BR`
71
- * Romanian `ro-RO`
72
- * Russian `ru`
73
- * Serbian `sr-SP`
74
- * Slovak `sk`
75
- * Spanish (Argentina) `es-AR`
76
- * Spanish (Bolivia) `es-BO`
77
- * Spanish (Chile) `es-CL`
78
- * Spanish (Colombia) `es-CO`
79
- * Spanish (Costa Rica) `es-CR`
80
- * Spanish (Dominican Republic) `es-DO`
81
- * Spanish (Ecuador) `es-EC`
82
- * Spanish (El Salvador) `es-SV`
83
- * Spanish (Guatemala) `es-GT`
84
- * Spanish (Honduras) `es-HN`
85
- * Spanish (Mexico) `es-MX`
86
- * Spanish (Nicaragua) `es-NI`
87
- * Spanish (Panama) `es-PA`
88
- * Spanish (Paraguay) `es-PY`
89
- * Spanish (Peru) `es-PE`
90
- * Spanish (Puerto Rico) `es-PR`
91
- * Spanish (Spain) `es-ES`
92
- * Spanish (US) `es-US`
93
- * Spanish (Uruguay) `es-UY`
94
- * Spanish (Venezuela) `es-VE`
95
- * Swedish `sv-SE`
96
- * Turkish `tr`
97
- * Zulu `zu`
98
-
99
- ## Why does the browser repeatedly ask for permission to use the microphone?
100
-
101
- ![](http://i.imgur.com/Z3zooUC.png)
102
-
103
- Chrome's speech recognition behaves differently based on the protocol used:
104
-
105
- - `https://` Asks for permission once and remembers the choice.
106
-
107
- - `http://` Asks for permission repeatedly **on every page load**. Results are also returned significantly slower in HTTP.
108
-
109
- For a great user experience, don't compromise on anything less than HTTPS (available free with CloudFlare and Let's Encrypt).
110
-
111
- ## What can I do to make speech recognition results return faster?
112
-
113
- First, remember that because the actual speech-to-text processing is done in the cloud, a faster connection can mean faster results.
114
-
115
- Second, when the speech recognition is in continuous mode, results are returned slower (the browser waits after you finish talking to see if there's anything else you'd like to add).
116
-
117
- Turning continuous mode off tends to make the browser return recognized results much faster.
118
-
119
- To start annyang in non-continuous mode, you can pass `continuous: false` in the options object that `annyang.start()` accepts. You will most likely want to also turn on `autoRestart` if you do that. You can read more about both options in the [annyang API Docs](https://github.com/TalAter/annyang/blob/master/docs/README.md#startoptions)
120
-
121
- For example:
122
-
123
- ````javascript
124
- annyang.start({ autoRestart: true, continuous: false });
125
- ````
126
-
127
- Note that these settings are already the default if you are using HTTPS. If you are using HTTP, continuous mode will be turned on by default (resulting in slower recognition) to prevent [repeated security notices](#why-does-the-browser-repeatedly-ask-for-permission-to-use-the-microphone).
128
-
129
- ## How can I contribute to annyang's development?
130
-
131
- There are three main ways for you to help. Check out the [CONTRIBUTING](https://github.com/TalAter/annyang/blob/master/CONTRIBUTING.md) guide for more details.
132
-
133
- ## Why does Speech Recognition repeatedly starts and stops?
134
-
135
- The most common reason for this is because you have opened more than one tab or window that uses Speech Recognition in your browser at the same time (e.g. if you open annyang's homepage in one tab, and the Speech Recognition app you are developing in another).
136
-
137
- When a browser detects that one tab has started Speech Recognition, it aborts all other Speech Recognition processes in other tabs. annyang detects when it is aborted by an external process and restarts itself. If you have two windows aborting each other, and restarting themselves you may experience Speech Recognition starting and stopping over and over again.
138
-
139
- Another possible reason for this might be that you are offline.
140
-
141
- ## Can annyang work offline?
142
-
143
- No. annyang relies on the browser's own speech recognition engine. In Chrome, this engine performs the recognition in the cloud.
144
-
145
- ## Which browsers are supported?
146
-
147
- annyang works with all browsers that implement the Speech Recognition interface of the Web Speech API (such as Google Chrome, and Samsung Internet).
148
-
149
- We believe in progressive enhancement and so if the user's browser does not support speech recognition, annyang will fail quietly and the annyang variable will equal null.
150
-
151
- To check if the user's browser supports speech recognition, simply check if annyang is equal to null.
152
-
153
- ```javascript
154
- if (!annyang) {
155
- console.log("Speech Recognition is not supported");
156
- }
157
- ```
158
-
159
- You can find out the current state of browser support on [caniuse.com](http://caniuse.com/#feat=speech-recognition).
160
-
161
- ## Can annyang be used to capture the full text spoken by the user?
162
-
163
- Yes. You can listen to the `result` event which is triggered whenever speech is recognized. This event will fire with a list of possible phrases the user may have said, regardless of whether any of them matched an annyang command or not. You can even do this without registering any commands:
164
-
165
- ````javascript
166
- annyang.addCallback('result', function(phrases) {
167
- console.log("I think the user said: ", phrases[0]);
168
- console.log("But then again, it could be any of the following: ", phrases);
169
- });
170
- ````
171
-
172
- Alternatively, you may choose to only capture what the user said when it matches an annyang command (`resultMatch`), or when it does not match a command (`resultNoMatch`).
173
-
174
- ````javascript
175
- annyang.addCallback('resultMatch', function(userSaid, commandText, phrases) {
176
- console.log(userSaid); // sample output: 'hello'
177
- console.log(commandText); // sample output: 'hello (there)'
178
- console.log(phrases); // sample output: ['hello', 'halo', 'yellow', 'polo', 'hello kitty']
179
- });
180
-
181
- annyang.addCallback('resultNoMatch', function(phrases) {
182
- console.log("I think the user said: ", phrases[0]);
183
- console.log("But then again, it could be any of the following: ", phrases);
184
- });
185
- ````
186
-
187
- ## Can I detect when the user starts and stops speaking?
188
-
189
- Yes. Sometimes.
190
-
191
- You can detect when a sound is first detected by the microphone with the `soundstart` event. Unfortunately, due to a [bug in Chrome](https://bugs.chromium.org/p/chromium/issues/detail?id=572697&thanks=572697&ts=1451323087), this event will only fire once in every speech recognition session. If you are in non-continuous mode and annyang is restarting after every sentence recognized (the default in HTTPS), this will not be a problem. Because speech recognition will abort and restart, soundstart will fire again correctly.
192
-
193
- The following code will detect when a user starts and stops speaking.
194
-
195
- ````javascript
196
- annyang.addCallback('soundstart', function() {
197
- console.log('sound detected');
198
- });
199
-
200
- annyang.addCallback('result', function() {
201
- console.log('sound stopped');
202
- });
203
-
204
- ````
205
-
206
- *Note*: The `soundstart` event is only available in annyang v2.6.0 and up.
207
-
208
- ## Can annyang be used in Chromium or Electron?
209
-
210
- 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.
211
-
212
- ## Can annyang be used in Cordova?
213
-
214
- 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:
215
-
216
- ```
217
- cordova plugin add cordova-plugin-crosswalk-webview
218
- cordova plugin add cordova-plugin-media
219
- ```
220
- **Known issues:**
221
- - This has only been verified to work on Android.
222
- - This will not work on a device without a SpeechRecognizer ([like the Kindle Fire](https://forums.developer.amazon.com/questions/13597/does-speech-recognition-work-in-kindle-fire-hd-tab.html)) unless you sideload the [Google Now Launcher](https://play.google.com/store/apps/details?id=com.google.android.launcher).
223
- - Your app will ding with the native speech recognition sound, you have no control over this. See [#194](https://github.com/TalAter/annyang/issues/194).
package/docs/README.md DELETED
@@ -1,336 +0,0 @@
1
-
2
-
3
- <!-- Start src/annyang.js -->
4
-
5
- # Quick Tutorial, Intro and Demos
6
-
7
- The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/).
8
-
9
- For a more in-depth look at annyang, read on.
10
-
11
- # API Reference
12
-
13
- ## init(commands, [resetCommands=true])
14
-
15
- Initialize annyang with a list of commands to recognize.
16
-
17
- #### Examples:
18
- ````javascript
19
- var commands = {'hello :name': helloFunction};
20
- var commands2 = {'hi': helloFunction};
21
-
22
- // initialize annyang, overwriting any previously added commands
23
- annyang.init(commands, true);
24
- // adds an additional command without removing the previous commands
25
- annyang.init(commands2, false);
26
- ````
27
- 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.
28
-
29
- **Deprecated**
30
-
31
- See: [Commands Object](#commands-object)
32
-
33
- ### Params:
34
-
35
- * **Object** *commands* - Commands that annyang should listen to
36
- * **boolean** *[resetCommands=true]* - Remove all commands before initializing?
37
-
38
- ## start([options])
39
-
40
- Start listening.
41
- It's a good idea to call this after adding some commands first, but not mandatory.
42
-
43
- Receives an optional options object which supports the following options:
44
-
45
- - `autoRestart` (boolean, default: true) Should annyang restart itself if it is closed indirectly, because of silence or window conflicts?
46
- - `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.
47
- - `paused` (boolean, default: true) Start annyang in paused mode.
48
-
49
- #### Examples:
50
- ````javascript
51
- // Start listening, don't restart automatically
52
- annyang.start({ autoRestart: false });
53
- // Start listening, don't restart automatically, stop recognition after first phrase recognized
54
- annyang.start({ autoRestart: false, continuous: false });
55
- ````
56
-
57
- ### Params:
58
-
59
- * **Object** *[options]* - Optional options.
60
-
61
- ## abort()
62
-
63
- Stop listening, and turn off mic.
64
-
65
- Alternatively, to only temporarily pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead.
66
-
67
- See: [pause()](#pause)
68
-
69
- ## pause()
70
-
71
- 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.
72
-
73
- Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead.
74
-
75
- See: [abort()](#abort)
76
-
77
- ## resume()
78
-
79
- Resumes listening and restores command callback execution when a result matches.
80
- If SpeechRecognition was aborted (stopped), start it.
81
-
82
- ## debug([newState=true])
83
-
84
- Turn on output of debug messages to the console. Ugly, but super-handy!
85
-
86
- ### Params:
87
-
88
- * **boolean** *[newState=true]* - Turn on/off debug messages
89
-
90
- ## setLanguage(language)
91
-
92
- Set the language the user will speak in. If this method is not called, defaults to 'en-US'.
93
-
94
- See: [Languages](https://github.com/TalAter/annyang/blob/master/docs/FAQ.md#what-languages-are-supported)
95
-
96
- ### Params:
97
-
98
- * **String** *language* - The language (locale)
99
-
100
- ## addCommands(commands)
101
-
102
- Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands.
103
-
104
- #### Examples:
105
- ````javascript
106
- var commands = {'hello :name': helloFunction, 'howdy': helloFunction};
107
- var commands2 = {'hi': helloFunction};
108
-
109
- annyang.addCommands(commands);
110
- annyang.addCommands(commands2);
111
- // annyang will now listen to all three commands
112
- ````
113
-
114
- See: [Commands Object](#commands-object)
115
-
116
- ### Params:
117
-
118
- * **Object** *commands* - Commands that annyang should listen to
119
-
120
- ## removeCommands([commandsToRemove])
121
-
122
- Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands.
123
-
124
- #### Examples:
125
- ````javascript
126
- var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction};
127
-
128
- // Remove all existing commands
129
- annyang.removeCommands();
130
-
131
- // Add some commands
132
- annyang.addCommands(commands);
133
-
134
- // Don't respond to hello
135
- annyang.removeCommands('hello');
136
-
137
- // Don't respond to howdy or hi
138
- annyang.removeCommands(['howdy', 'hi']);
139
- ````
140
-
141
- ### Params:
142
-
143
- * **String|Array|Undefined** *[commandsToRemove]* - Commands to remove
144
-
145
- ## addCallback(type, callback, [context])
146
-
147
- Add a callback function to be called in case one of the following events happens:
148
-
149
- * `start` - Fired as soon as the browser's Speech Recognition engine starts listening
150
- * `soundstart` - Fired as soon as any sound (possibly speech) has been detected.
151
- This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start
152
- * `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)
153
- Callback function will be called with the error event as the first argument
154
- * `errorNetwork` - Fired when Speech Recognition fails because of a network error
155
- Callback function will be called with the error event as the first argument
156
- * `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition.
157
- Callback function will be called with the error event as the first argument
158
- * `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition.
159
- Callback function will be called with the error event as the first argument
160
- * `end` - Fired when the browser's Speech Recognition engine stops
161
- * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks.
162
- Callback functions for to this event will be called with an array of possible phrases the user said as the first argument
163
- * `resultMatch` - Fired when annyang was able to match between what the user said and a registered command
164
- Callback functions for this event will be called with three arguments in the following order:
165
- * The phrase the user said that matched a command
166
- * The command that was matched
167
- * An array of possible alternative phrases the user might have said
168
- * `resultNoMatch` - Fired when what the user said didn't match any of the registered commands.
169
- Callback functions for this event will be called with an array of possible phrases the user might've said as the first argument
170
-
171
- #### Examples:
172
- ````javascript
173
- annyang.addCallback('error', function() {
174
- $('.myErrorText').text('There was an error!');
175
- });
176
-
177
- annyang.addCallback('resultMatch', function(userSaid, commandText, phrases) {
178
- console.log(userSaid); // sample output: 'hello'
179
- console.log(commandText); // sample output: 'hello (there)'
180
- console.log(phrases); // sample output: ['hello', 'halo', 'yellow', 'polo', 'hello kitty']
181
- });
182
-
183
- // pass local context to a global function called notConnected
184
- annyang.addCallback('errorNetwork', notConnected, this);
185
- ````
186
-
187
- ### Params:
188
-
189
- * **String** *type* - Name of event that will trigger this callback
190
- * **Function** *callback* - The function to call when event is triggered
191
- * **Object** *[context]* - Optional context for the callback function
192
-
193
- ## removeCallback(type, callback)
194
-
195
- Remove callbacks from events.
196
-
197
- - Pass an event name and a callback command to remove that callback command from that event type.
198
- - Pass just an event name to remove all callback commands from that event type.
199
- - Pass undefined as event name and a callback command to remove that callback command from all event types.
200
- - Pass no params to remove all callback commands from all event types.
201
-
202
- #### Examples:
203
- ````javascript
204
- annyang.addCallback('start', myFunction1);
205
- annyang.addCallback('start', myFunction2);
206
- annyang.addCallback('end', myFunction1);
207
- annyang.addCallback('end', myFunction2);
208
-
209
- // Remove all callbacks from all events:
210
- annyang.removeCallback();
211
-
212
- // Remove all callbacks attached to end event:
213
- annyang.removeCallback('end');
214
-
215
- // Remove myFunction2 from being called on start:
216
- annyang.removeCallback('start', myFunction2);
217
-
218
- // Remove myFunction1 from being called on all events:
219
- annyang.removeCallback(undefined, myFunction1);
220
- ````
221
-
222
- ### Params:
223
-
224
- * *type* Name of event type to remove callback from
225
- * *callback* The callback function to remove
226
-
227
- ### Return:
228
-
229
- * undefined
230
-
231
- ## isListening()
232
-
233
- Returns true if speech recognition is currently on.
234
- Returns false if speech recognition is off or annyang is paused.
235
-
236
- ### Return:
237
-
238
- * boolean true = SpeechRecognition is on and annyang is listening
239
-
240
- ## getSpeechRecognizer()
241
-
242
- Returns the instance of the browser's SpeechRecognition object used by annyang.
243
- Useful in case you want direct access to the browser's Speech Recognition engine.
244
-
245
- ### Return:
246
-
247
- * SpeechRecognition The browser's Speech Recognizer currently used by annyang
248
-
249
- ## trigger(string|array)
250
-
251
- Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition
252
- detects speech.
253
-
254
- Can accept either a string containing a single sentence, or an array containing multiple sentences to be checked
255
- in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed)
256
-
257
- #### Examples:
258
- ````javascript
259
- annyang.trigger('Time for some thrilling heroics');
260
- annyang.trigger(
261
- ['Time for some thrilling heroics', 'Time for some thrilling aerobics']
262
- );
263
- ````
264
-
265
- ### Params:
266
-
267
- * *string|array* sentences A sentence as a string or an array of strings of possible sentences
268
-
269
- ### Return:
270
-
271
- * undefined
272
-
273
- # Good to Know
274
-
275
- ## Commands Object
276
-
277
- Both the [init()]() and addCommands() methods receive a `commands` object.
278
-
279
- annyang understands commands with `named variables`, `splats`, and `optional words`.
280
-
281
- * Use `named variables` for one word arguments in your command.
282
- * Use `splats` to capture multi-word text at the end of your command (greedy).
283
- * Use `optional words` or phrases to define a part of the command as optional.
284
-
285
- #### Examples:
286
- ````html
287
- <script>
288
- var commands = {
289
- // annyang will capture anything after a splat (*) and pass it to the function.
290
- // e.g. saying "Show me Batman and Robin" will call showFlickr('Batman and Robin');
291
- 'show me *tag': showFlickr,
292
-
293
- // A named variable is a one word variable, that can fit anywhere in your command.
294
- // e.g. saying "calculate October stats" will call calculateStats('October');
295
- 'calculate :month stats': calculateStats,
296
-
297
- // By defining a part of the following command as optional, annyang will respond
298
- // to both: "say hello to my little friend" as well as "say hello friend"
299
- 'say hello (to my little) friend': greeting
300
- };
301
-
302
- var showFlickr = function(tag) {
303
- var url = 'http://api.flickr.com/services/rest/?tags='+tag;
304
- $.getJSON(url);
305
- }
306
-
307
- var calculateStats = function(month) {
308
- $('#stats').text('Statistics for '+month);
309
- }
310
-
311
- var greeting = function() {
312
- $('#greeting').text('Hello!');
313
- }
314
- </script>
315
- ````
316
-
317
- ### Using Regular Expressions in commands
318
- For advanced commands, you can pass a regular expression object, instead of
319
- a simple string command.
320
-
321
- This is done by passing an object containing two properties: `regexp`, and
322
- `callback` instead of the function.
323
-
324
- #### Examples:
325
- ````javascript
326
- var calculateFunction = function(month) { console.log(month); }
327
- var commands = {
328
- // This example will accept any word as the "month"
329
- 'calculate :month stats': calculateFunction,
330
- // This example will only accept months which are at the start of a quarter
331
- 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction}
332
- }
333
- ````
334
-
335
- <!-- End src/annyang.js -->
336
-
package/require.js DELETED
@@ -1,36 +0,0 @@
1
- /*
2
- RequireJS 2.1.9 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
3
- Available via the MIT or new BSD license.
4
- see: http://github.com/jrburke/requirejs for details
5
- */
6
- var requirejs,require,define;
7
- (function(Z){function H(b){return"[object Function]"===L.call(b)}function I(b){return"[object Array]"===L.call(b)}function y(b,c){if(b){var e;for(e=0;e<b.length&&(!b[e]||!c(b[e],e,b));e+=1);}}function M(b,c){if(b){var e;for(e=b.length-1;-1<e&&(!b[e]||!c(b[e],e,b));e-=1);}}function t(b,c){return ga.call(b,c)}function l(b,c){return t(b,c)&&b[c]}function F(b,c){for(var e in b)if(t(b,e)&&c(b[e],e))break}function Q(b,c,e,h){c&&F(c,function(c,j){if(e||!t(b,j))h&&"string"!==typeof c?(b[j]||(b[j]={}),Q(b[j],
8
- c,e,h)):b[j]=c});return b}function u(b,c){return function(){return c.apply(b,arguments)}}function aa(b){throw b;}function ba(b){if(!b)return b;var c=Z;y(b.split("."),function(b){c=c[b]});return c}function A(b,c,e,h){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=h;e&&(c.originalError=e);return c}function ha(b){function c(a,f,b){var d,m,c,g,e,h,j,i=f&&f.split("/");d=i;var n=k.map,p=n&&n["*"];if(a&&"."===a.charAt(0))if(f){d=l(k.pkgs,f)?i=[f]:i.slice(0,i.length-
9
- 1);f=a=d.concat(a.split("/"));for(d=0;f[d];d+=1)if(m=f[d],"."===m)f.splice(d,1),d-=1;else if(".."===m)if(1===d&&(".."===f[2]||".."===f[0]))break;else 0<d&&(f.splice(d-1,2),d-=2);d=l(k.pkgs,f=a[0]);a=a.join("/");d&&a===f+"/"+d.main&&(a=f)}else 0===a.indexOf("./")&&(a=a.substring(2));if(b&&n&&(i||p)){f=a.split("/");for(d=f.length;0<d;d-=1){c=f.slice(0,d).join("/");if(i)for(m=i.length;0<m;m-=1)if(b=l(n,i.slice(0,m).join("/")))if(b=l(b,c)){g=b;e=d;break}if(g)break;!h&&(p&&l(p,c))&&(h=l(p,c),j=d)}!g&&
10
- h&&(g=h,e=j);g&&(f.splice(0,e,g),a=f.join("/"))}return a}function e(a){z&&y(document.getElementsByTagName("script"),function(f){if(f.getAttribute("data-requiremodule")===a&&f.getAttribute("data-requirecontext")===i.contextName)return f.parentNode.removeChild(f),!0})}function h(a){var f=l(k.paths,a);if(f&&I(f)&&1<f.length)return f.shift(),i.require.undef(a),i.require([a]),!0}function $(a){var f,b=a?a.indexOf("!"):-1;-1<b&&(f=a.substring(0,b),a=a.substring(b+1,a.length));return[f,a]}function n(a,f,
11
- b,d){var m,B,g=null,e=f?f.name:null,h=a,j=!0,k="";a||(j=!1,a="_@r"+(L+=1));a=$(a);g=a[0];a=a[1];g&&(g=c(g,e,d),B=l(r,g));a&&(g?k=B&&B.normalize?B.normalize(a,function(a){return c(a,e,d)}):c(a,e,d):(k=c(a,e,d),a=$(k),g=a[0],k=a[1],b=!0,m=i.nameToUrl(k)));b=g&&!B&&!b?"_unnormalized"+(M+=1):"";return{prefix:g,name:k,parentMap:f,unnormalized:!!b,url:m,originalName:h,isDefine:j,id:(g?g+"!"+k:k)+b}}function q(a){var f=a.id,b=l(p,f);b||(b=p[f]=new i.Module(a));return b}function s(a,f,b){var d=a.id,m=l(p,
12
- d);if(t(r,d)&&(!m||m.defineEmitComplete))"defined"===f&&b(r[d]);else if(m=q(a),m.error&&"error"===f)b(m.error);else m.on(f,b)}function v(a,f){var b=a.requireModules,d=!1;if(f)f(a);else if(y(b,function(f){if(f=l(p,f))f.error=a,f.events.error&&(d=!0,f.emit("error",a))}),!d)j.onError(a)}function w(){R.length&&(ia.apply(G,[G.length-1,0].concat(R)),R=[])}function x(a){delete p[a];delete T[a]}function E(a,f,b){var d=a.map.id;a.error?a.emit("error",a.error):(f[d]=!0,y(a.depMaps,function(d,c){var g=d.id,
13
- e=l(p,g);e&&(!a.depMatched[c]&&!b[g])&&(l(f,g)?(a.defineDep(c,r[g]),a.check()):E(e,f,b))}),b[d]=!0)}function C(){var a,f,b,d,m=(b=1E3*k.waitSeconds)&&i.startTime+b<(new Date).getTime(),c=[],g=[],j=!1,l=!0;if(!U){U=!0;F(T,function(b){a=b.map;f=a.id;if(b.enabled&&(a.isDefine||g.push(b),!b.error))if(!b.inited&&m)h(f)?j=d=!0:(c.push(f),e(f));else if(!b.inited&&(b.fetched&&a.isDefine)&&(j=!0,!a.prefix))return l=!1});if(m&&c.length)return b=A("timeout","Load timeout for modules: "+c,null,c),b.contextName=
14
- i.contextName,v(b);l&&y(g,function(a){E(a,{},{})});if((!m||d)&&j)if((z||da)&&!V)V=setTimeout(function(){V=0;C()},50);U=!1}}function D(a){t(r,a[0])||q(n(a[0],null,!0)).init(a[1],a[2])}function J(a){var a=a.currentTarget||a.srcElement,b=i.onScriptLoad;a.detachEvent&&!W?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=i.onScriptError;(!a.detachEvent||W)&&a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}function K(){var a;for(w();G.length;){a=
15
- G.shift();if(null===a[0])return v(A("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));D(a)}}var U,X,i,N,V,k={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},shim:{},config:{}},p={},T={},Y={},G=[],r={},S={},L=1,M=1;N={require:function(a){return a.require?a.require:a.require=i.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?a.exports:a.exports=r[a.map.id]={}},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){var b=
16
- l(k.pkgs,a.map.id);return(b?l(k.config,a.map.id+"/"+b.main):l(k.config,a.map.id))||{}},exports:r[a.map.id]}}};X=function(a){this.events=l(Y,a.id)||{};this.map=a;this.shim=l(k.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};X.prototype={init:function(a,b,c,d){d=d||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=u(this,function(a){this.emit("error",a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=!0;
17
- this.ignore=d.ignore;d.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,this.depCount-=1,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;i.startTime=(new Date).getTime();var a=this.map;if(this.shim)i.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],u(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?this.callPlugin():this.load()}},load:function(){var a=
18
- this.map.url;S[a]||(S[a]=!0,i.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var d=this.exports,m=this.factory;if(this.inited)if(this.error)this.emit("error",this.error);else{if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(H(m)){if(this.events.error&&this.map.isDefine||j.onError!==aa)try{d=i.execCb(c,m,b,d)}catch(e){a=e}else d=i.execCb(c,m,b,d);this.map.isDefine&&((b=this.module)&&void 0!==b.exports&&b.exports!==
19
- this.exports?d=b.exports:void 0===d&&this.usingExports&&(d=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",v(this.error=a)}else d=m;this.exports=d;if(this.map.isDefine&&!this.ignore&&(r[c]=d,j.onResourceLoad))j.onResourceLoad(i,this.map,this.depMaps);x(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=
20
- !0)}}else this.fetch()}},callPlugin:function(){var a=this.map,b=a.id,e=n(a.prefix);this.depMaps.push(e);s(e,"defined",u(this,function(d){var m,e;e=this.map.name;var g=this.map.parentMap?this.map.parentMap.name:null,h=i.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(d.normalize&&(e=d.normalize(e,function(a){return c(a,g,!0)})||""),d=n(a.prefix+"!"+e,this.map.parentMap),s(d,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),
21
- e=l(p,d.id)){this.depMaps.push(d);if(this.events.error)e.on("error",u(this,function(a){this.emit("error",a)}));e.enable()}}else m=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),m.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];F(p,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&x(a.map.id)});v(a)}),m.fromText=u(this,function(d,c){var e=a.name,g=n(e),B=O;c&&(d=c);B&&(O=!1);q(g);t(k.config,b)&&(k.config[e]=k.config[b]);try{j.exec(d)}catch(ca){return v(A("fromtexteval",
22
- "fromText eval for "+b+" failed: "+ca,ca,[b]))}B&&(O=!0);this.depMaps.push(g);i.completeLoad(e);h([e],m)}),d.load(a.name,h,m,k)}));i.enable(e,this);this.pluginMaps[e.id]=e},enable:function(){T[this.map.id]=this;this.enabling=this.enabled=!0;y(this.depMaps,u(this,function(a,b){var c,d;if("string"===typeof a){a=n(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=l(N,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;s(a,"defined",u(this,function(a){this.defineDep(b,
23
- a);this.check()}));this.errback&&s(a,"error",u(this,this.errback))}c=a.id;d=p[c];!t(N,c)&&(d&&!d.enabled)&&i.enable(a,this)}));F(this.pluginMaps,u(this,function(a){var b=l(p,a.id);b&&!b.enabled&&i.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){y(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};i={config:k,contextName:b,registry:p,defined:r,urlFetched:S,defQueue:G,Module:X,makeModuleMap:n,
24
- nextTick:j.nextTick,onError:v,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=k.pkgs,c=k.shim,d={paths:!0,config:!0,map:!0};F(a,function(a,b){d[b]?"map"===b?(k.map||(k.map={}),Q(k[b],a,!0,!0)):Q(k[b],a,!0):k[b]=a});a.shim&&(F(a.shim,function(a,b){I(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn=i.makeShimExports(a);c[b]=a}),k.shim=c);a.packages&&(y(a.packages,function(a){a="string"===typeof a?{name:a}:a;b[a.name]={name:a.name,
25
- location:a.location||a.name,main:(a.main||"main").replace(ja,"").replace(ea,"")}}),k.pkgs=b);F(p,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=n(b))});if(a.deps||a.callback)i.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(Z,arguments));return b||a.exports&&ba(a.exports)}},makeRequire:function(a,f){function h(d,c,e){var g,k;f.enableBuildCallback&&(c&&H(c))&&(c.__requireJsBuild=!0);if("string"===typeof d){if(H(c))return v(A("requireargs",
26
- "Invalid require call"),e);if(a&&t(N,d))return N[d](p[a.id]);if(j.get)return j.get(i,d,a,h);g=n(d,a,!1,!0);g=g.id;return!t(r,g)?v(A("notloaded",'Module name "'+g+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):r[g]}K();i.nextTick(function(){K();k=q(n(null,a));k.skipMap=f.skipMap;k.init(d,c,e,{enabled:!0});C()});return h}f=f||{};Q(h,{isBrowser:z,toUrl:function(b){var f,e=b.lastIndexOf("."),g=b.split("/")[0];if(-1!==e&&(!("."===g||".."===g)||1<e))f=b.substring(e,b.length),b=
27
- b.substring(0,e);return i.nameToUrl(c(b,a&&a.id,!0),f,!0)},defined:function(b){return t(r,n(b,a,!1,!0).id)},specified:function(b){b=n(b,a,!1,!0).id;return t(r,b)||t(p,b)}});a||(h.undef=function(b){w();var c=n(b,a,!0),f=l(p,b);e(b);delete r[b];delete S[c.url];delete Y[b];f&&(f.events.defined&&(Y[b]=f.events),x(b))});return h},enable:function(a){l(p,a.id)&&q(a).enable()},completeLoad:function(a){var b,c,d=l(k.shim,a)||{},e=d.exports;for(w();G.length;){c=G.shift();if(null===c[0]){c[0]=a;if(b)break;b=
28
- !0}else c[0]===a&&(b=!0);D(c)}c=l(p,a);if(!b&&!t(r,a)&&c&&!c.inited){if(k.enforceDefine&&(!e||!ba(e)))return h(a)?void 0:v(A("nodefine","No define call for "+a,null,[a]));D([a,d.deps||[],d.exportsFn])}C()},nameToUrl:function(a,b,c){var d,e,h,g,i,n;if(j.jsExtRegExp.test(a))g=a+(b||"");else{d=k.paths;e=k.pkgs;g=a.split("/");for(i=g.length;0<i;i-=1)if(n=g.slice(0,i).join("/"),h=l(e,n),n=l(d,n)){I(n)&&(n=n[0]);g.splice(0,i,n);break}else if(h){a=a===h.name?h.location+"/"+h.main:h.location;g.splice(0,i,
29
- a);break}g=g.join("/");g+=b||(/^data\:|\?/.test(g)||c?"":".js");g=("/"===g.charAt(0)||g.match(/^[\w\+\.\-]+:/)?"":k.baseUrl)+g}return k.urlArgs?g+((-1===g.indexOf("?")?"?":"&")+k.urlArgs):g},load:function(a,b){j.load(i,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||ka.test((a.currentTarget||a.srcElement).readyState))P=null,a=J(a),i.completeLoad(a.id)},onScriptError:function(a){var b=J(a);if(!h(b.id))return v(A("scripterror","Script error for: "+b.id,
30
- a,[b.id]))}};i.require=i.makeRequire();return i}var j,w,x,C,J,D,P,K,q,fa,la=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,ma=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,ea=/\.js$/,ja=/^\.\//;w=Object.prototype;var L=w.toString,ga=w.hasOwnProperty,ia=Array.prototype.splice,z=!!("undefined"!==typeof window&&"undefined"!==typeof navigator&&window.document),da=!z&&"undefined"!==typeof importScripts,ka=z&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,W="undefined"!==typeof opera&&
31
- "[object Opera]"===opera.toString(),E={},s={},R=[],O=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(H(requirejs))return;s=requirejs;requirejs=void 0}"undefined"!==typeof require&&!H(require)&&(s=require,require=void 0);j=requirejs=function(b,c,e,h){var q,n="_";!I(b)&&"string"!==typeof b&&(q=b,I(c)?(b=c,c=e,e=h):b=[]);q&&q.context&&(n=q.context);(h=l(E,n))||(h=E[n]=j.s.newContext(n));q&&h.configure(q);return h.require(b,c,e)};j.config=function(b){return j(b)};j.nextTick="undefined"!==
32
- typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=j);j.version="2.1.9";j.jsExtRegExp=/^\/|:|\?|\.js$/;j.isBrowser=z;w=j.s={contexts:E,newContext:ha};j({});y(["toUrl","undef","defined","specified"],function(b){j[b]=function(){var c=E._;return c.require[b].apply(c,arguments)}});if(z&&(x=w.head=document.getElementsByTagName("head")[0],C=document.getElementsByTagName("base")[0]))x=w.head=C.parentNode;j.onError=aa;j.createNode=function(b){var c=b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml",
33
- "html:script"):document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};j.load=function(b,c,e){var h=b&&b.config||{};if(z)return h=j.createNode(h,c,e),h.setAttribute("data-requirecontext",b.contextName),h.setAttribute("data-requiremodule",c),h.attachEvent&&!(h.attachEvent.toString&&0>h.attachEvent.toString().indexOf("[native code"))&&!W?(O=!0,h.attachEvent("onreadystatechange",b.onScriptLoad)):(h.addEventListener("load",b.onScriptLoad,!1),h.addEventListener("error",
34
- b.onScriptError,!1)),h.src=e,K=h,C?x.insertBefore(h,C):x.appendChild(h),K=null,h;if(da)try{importScripts(e),b.completeLoad(c)}catch(l){b.onError(A("importscripts","importScripts failed for "+c+" at "+e,l,[c]))}};z&&!s.skipDataMain&&M(document.getElementsByTagName("script"),function(b){x||(x=b.parentNode);if(J=b.getAttribute("data-main"))return q=J,s.baseUrl||(D=q.split("/"),q=D.pop(),fa=D.length?D.join("/")+"/":"./",s.baseUrl=fa),q=q.replace(ea,""),j.jsExtRegExp.test(q)&&(q=J),s.deps=s.deps?s.deps.concat(q):
35
- [q],!0});define=function(b,c,e){var h,j;"string"!==typeof b&&(e=c,c=b,b=null);I(c)||(e=c,c=null);!c&&H(e)&&(c=[],e.length&&(e.toString().replace(la,"").replace(ma,function(b,e){c.push(e)}),c=(1===e.length?["require"]:["require","exports","module"]).concat(c)));if(O){if(!(h=K))P&&"interactive"===P.readyState||M(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return P=b}),h=P;h&&(b||(b=h.getAttribute("data-requiremodule")),j=E[h.getAttribute("data-requirecontext")])}(j?
36
- j.defQueue:R).push([b,c,e])};define.amd={jQuery:!0};j.exec=function(b){return eval(b)};j(s)}})(this);
package/sites/README.md DELETED
@@ -1,6 +0,0 @@
1
- annyang samples
2
- ===============
3
-
4
- Sample script files to control popular sites with voice commands. Intended as inspiration.
5
-
6
- To try it, run the site's minified source code in the web developer console.