annyang_rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGExMzcxZDZhYzJlNmYxZjM0YmVhNDRiYjIxNjY0NzkwNmEzZWE1MA==
4
+ YTAwMzQ2Nzg5ODM2NzI5ODhkMTE0ZDZmN2JlY2ExMzBhYTkyNzExZg==
5
5
  data.tar.gz: !binary |-
6
- MGRhN2Y5ZWNiMGExZmU1ZDk3MTQzODFhYjIzMzUyODlkNTI1MDMwNA==
6
+ ZDFjNWVmYTJkODcxODY1NjU0MWE0NWEzMzNjZDFkNDdhMDhjMjkxNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDZlZjIwMTkyNjI5NTMwODIxOWM5Y2IzMDE3Njk5ZTZjZWQ5Y2JmMGYxNWY4
10
- MWViZWMxYjBmNmE1ZDdlNTc5ZGI4ODUyMDVjODE5NmM4OTdhNzYzZTNhNzVl
11
- YjM2MjE5YWY3MGViZTY3Zjk2MjZkY2E0MmQxOTQ2OGUwNDFlMjg=
9
+ ZWJjYjFmMDEyMjFjMWJmMzBlODlkOTlkNTM2MTY0MmE1MTg4Zjc0ZTdmYTBm
10
+ ZjhjZDU4ZGI0MzBmYjZiNDUzZDQzNjJkMjA2NzlkNTlmMWY1YjE5MTBlYWY2
11
+ MGRiOGYzN2EzMDMwYTg2ZGY3OWRkZjk0OTFhZWRkNjU1MTdjNWY=
12
12
  data.tar.gz: !binary |-
13
- ODBjOWYyMDhiYzVkNmI5N2E5NzAzMTYyNjc4OWYyMTg4ZDdlNzA1ODAyNDcz
14
- ZmJjYTY3Zjg1MGIzNjBiMjA3ODc2YTM2MmQ0OGMyYjVlYzQwZWRiYWRmMjA5
15
- MTcyOWM1NTYyNDdjZDg0NTMyOWM1MjQ3YmQ3Zjg4ZmQzN2FmNjU=
13
+ Y2EzZDBjZGExYTIzYzljNGYxOTdjNzNkMDc0NWRiMzYwZjIwYzY4NTdmZGFh
14
+ MDljYzViOTNjNTRmODZlY2E3Mzg2MDcwODlmNWI5MTk2NDU0MTQyZTRmYzA4
15
+ MThlZTI0YzY3ZjA0OTViMGQ2MDJjMWU4M2NkZDE5NTYzMGE5M2Q=
@@ -1,9 +1,9 @@
1
1
  //! annyang
2
- //! version : 1.0.0
2
+ //! version : 1.1.0
3
3
  //! author : Tal Ater @TalAter
4
4
  //! license : MIT
5
5
  //! https://www.TalAter.com/annyang/
6
- (function () {
6
+ (function (undefined) {
7
7
  "use strict";
8
8
 
9
9
  // Save a reference to the global object (window in the browser)
@@ -20,12 +20,11 @@
20
20
  // This is done as early as possible, to make it as fast as possible for unsupported browsers
21
21
  if (!SpeechRecognition) {
22
22
  root.annyang = null;
23
- return null;
23
+ return undefined;
24
24
  }
25
25
 
26
- var commandsList;
26
+ var commandsList = [];
27
27
  var recognition;
28
- var lang = 'en-US';
29
28
  var callbacks = { start: [], error: [], end: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] };
30
29
  var autoRestart;
31
30
  var lastStartedAt = 0;
@@ -56,11 +55,28 @@
56
55
  });
57
56
  };
58
57
 
58
+ var initIfNeeded = function() {
59
+ if (!isInitialized()) {
60
+ root.annyang.init({}, false);
61
+ }
62
+ };
63
+
64
+ var isInitialized = function() {
65
+ return recognition !== undefined;
66
+ };
67
+
59
68
  root.annyang = {
60
69
  // Initialize annyang with a list of commands to recognize.
61
70
  // e.g. annyang.init({'hello :name': helloFunction})
62
71
  // annyang understands commands with named variables, splats, and optional words.
63
- init: function(commands) {
72
+ init: function(commands, resetCommands) {
73
+
74
+ // resetCommands defaults to true
75
+ if (resetCommands === undefined) {
76
+ resetCommands = true;
77
+ } else {
78
+ resetCommands = !!resetCommands;
79
+ }
64
80
 
65
81
  // Abort previous instances of recognition already running
66
82
  if (recognition && recognition.abort) {
@@ -74,7 +90,7 @@
74
90
  recognition.maxAlternatives = 5;
75
91
  recognition.continuous = true;
76
92
  // Sets the language to the default 'en-US'. This can be changed with annyang.setLanguage()
77
- recognition.lang = lang;
93
+ recognition.lang = 'en-US';
78
94
 
79
95
  recognition.onstart = function() { invokeCallbacks(callbacks.start); };
80
96
 
@@ -147,8 +163,12 @@
147
163
  };
148
164
 
149
165
  // build commands list
150
- commandsList = [];
151
- this.addCommands(commands);
166
+ if (resetCommands) {
167
+ commandsList = [];
168
+ }
169
+ if (commands.length) {
170
+ this.addCommands(commands);
171
+ }
152
172
  },
153
173
 
154
174
  // Start listening (asking for permission first, if needed).
@@ -156,8 +176,9 @@
156
176
  // Receives an optional options object:
157
177
  // { autoRestart: true }
158
178
  start: function(options) {
179
+ initIfNeeded();
159
180
  options = options || {};
160
- if (options.autoRestart !== void 0) {
181
+ if (options.autoRestart !== undefined) {
161
182
  autoRestart = !!options.autoRestart;
162
183
  } else {
163
184
  autoRestart = true;
@@ -169,7 +190,9 @@
169
190
  // abort the listening session (aka stop)
170
191
  abort: function() {
171
192
  autoRestart = false;
172
- recognition.abort();
193
+ if (isInitialized) {
194
+ recognition.abort();
195
+ }
173
196
  },
174
197
 
175
198
  // Turn on output of debug messages to the console. Ugly, but super-handy!
@@ -184,16 +207,17 @@
184
207
  // Set the language the user will speak in. If not called, defaults to 'en-US'.
185
208
  // e.g. 'fr-FR' (French-France), 'es-CR' (Español-Costa Rica)
186
209
  setLanguage: function(language) {
187
- lang = language;
188
- if (recognition && recognition.abort) {
189
- recognition.lang = language;
190
- }
210
+ initIfNeeded();
211
+ recognition.lang = language;
191
212
  },
192
213
 
193
214
  // Add additional commands that annyang will respond to. Similar in syntax to annyang.init()
194
215
  addCommands: function(commands) {
195
216
  var cb,
196
217
  command;
218
+
219
+ initIfNeeded();
220
+
197
221
  for (var phrase in commands) {
198
222
  if (commands.hasOwnProperty(phrase)) {
199
223
  cb = root[commands[phrase]] || commands[phrase];
@@ -228,7 +252,7 @@
228
252
  // start, error, end, result, resultMatch, resultNoMatch, errorNetwork, errorPermissionBlocked, errorPermissionDenied
229
253
  // Can also optionally receive a context for the callback function as the third argument
230
254
  addCallback: function(type, callback, context) {
231
- if (callbacks[type] === void 0) {
255
+ if (callbacks[type] === undefined) {
232
256
  return;
233
257
  }
234
258
  var cb = root[callback] || callback;
@@ -1,3 +1,3 @@
1
1
  module AnnyangRails
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annyang_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Israeli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-04 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler