| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @fileoverview The class to Manage both offline / online speech recognition. | 6 * @fileoverview The class to Manage both offline / online speech recognition. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 <include src="plugin_manager.js"/> | 9 <include src="plugin_manager.js"/> |
| 10 <include src="audio_manager.js"/> | 10 <include src="audio_manager.js"/> |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 * Called when the speech recognition has ended. | 120 * Called when the speech recognition has ended. |
| 121 */ | 121 */ |
| 122 SpeechManager.prototype.onSpeechRecognitionEnded = function() { | 122 SpeechManager.prototype.onSpeechRecognitionEnded = function() { |
| 123 // Restarts the hotword recognition. | 123 // Restarts the hotword recognition. |
| 124 if (this.state != SpeechState.STOPPING && this.pluginManager_) { | 124 if (this.state != SpeechState.STOPPING && this.pluginManager_) { |
| 125 this.pluginManager_.startRecognizer(); | 125 this.pluginManager_.startRecognizer(); |
| 126 this.audioManager_.start(); | 126 this.audioManager_.start(); |
| 127 this.setState_(SpeechState.HOTWORD_RECOGNIZING); | 127 this.setState_(SpeechState.HOTWORD_RECOGNIZING); |
| 128 } else { | 128 } else { |
| 129 this.audioManager_.stop(); | 129 this.audioManager_.stop(); |
| 130 this.setState_(SpeechState.READY); |
| 130 } | 131 } |
| 131 chrome.send('setSpeechRecognitionState', ['off']); | |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * Called when a speech has started. | 135 * Called when a speech has started. |
| 136 */ | 136 */ |
| 137 SpeechManager.prototype.onSpeechStarted = function() { | 137 SpeechManager.prototype.onSpeechStarted = function() { |
| 138 if (this.state == SpeechState.RECOGNIZING) | 138 if (this.state == SpeechState.RECOGNIZING) |
| 139 this.setState_(SpeechState.IN_SPEECH); | 139 this.setState_(SpeechState.IN_SPEECH); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 /** | 142 /** |
| 143 * Called when a speech has ended. | 143 * Called when a speech has ended. |
| 144 */ | 144 */ |
| 145 SpeechManager.prototype.onSpeechEnded = function() { | 145 SpeechManager.prototype.onSpeechEnded = function() { |
| 146 if (this.state == SpeechState.IN_SPEECH) | 146 if (this.state == SpeechState.IN_SPEECH) |
| 147 this.setState_(SpeechState.RECOGNIZING); | 147 this.setState_(SpeechState.RECOGNIZING); |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 /** | 150 /** |
| 151 * Called when an error happened during the speech recognition. | 151 * Called when an error happened during the speech recognition. |
| 152 * | 152 * |
| 153 * @param {SpeechRecognitionError} e The error object. | 153 * @param {SpeechRecognitionError} e The error object. |
| 154 */ | 154 */ |
| 155 SpeechManager.prototype.onSpeechRecognitionError = function(e) { | 155 SpeechManager.prototype.onSpeechRecognitionError = function(e) { |
| 156 if (this.state != SpeechState.STOPPING) | 156 if (this.state != SpeechState.STOPPING) |
| 157 this.setState_(SpeechState.READY); | 157 this.setState_(SpeechState.READY); |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 /** | 160 /** |
| 161 * Initialize the hotword plugin manager, or do nothing if already | 161 * Changes the availability of the hotword plugin. |
| 162 * initialization is on. | 162 * |
| 163 * @param {boolean} enabled Whether enabled or not. |
| 163 */ | 164 */ |
| 164 SpeechManager.prototype.maybeInitializePlugin = function() { | 165 SpeechManager.prototype.setHotwordEnabled = function(enabled) { |
| 165 if ($('recognizer')) | 166 var recognizer = $('recognizer'); |
| 166 return; | 167 if (enabled) { |
| 168 if (recognizer) |
| 169 return; |
| 167 | 170 |
| 168 var pluginManager = new speech.PluginManager( | 171 var pluginManager = new speech.PluginManager( |
| 169 this.onHotwordRecognizerReady_.bind(this), | 172 this.onHotwordRecognizerReady_.bind(this), |
| 170 this.onHotwordRecognized_.bind(this)); | 173 this.onHotwordRecognized_.bind(this)); |
| 171 pluginManager.scheduleInitialize( | 174 pluginManager.scheduleInitialize( |
| 172 this.audioManager_.getSampleRate(), | 175 this.audioManager_.getSampleRate(), |
| 173 'chrome://app-list/okgoogle_hotword.config'); | 176 'chrome://app-list/okgoogle_hotword.config'); |
| 177 } else { |
| 178 if (!recognizer) |
| 179 return; |
| 180 document.body.removeChild(recognizer); |
| 181 this.pluginManager_ = null; |
| 182 if (this.state == SpeechState.HOTWORD_RECOGNIZING) |
| 183 this.setState(SpeechState.READY); |
| 184 } |
| 174 }; | 185 }; |
| 175 | 186 |
| 176 /** | 187 /** |
| 177 * Called when the app-list bubble is shown. | 188 * Called when the app-list bubble is shown. |
| 178 */ | 189 */ |
| 179 SpeechManager.prototype.onShown = function() { | 190 SpeechManager.prototype.onShown = function() { |
| 180 this.shown_ = true; | 191 this.shown_ = true; |
| 181 if (!this.pluginManager_) | 192 if (!this.pluginManager_) |
| 182 return; | 193 return; |
| 183 | 194 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 if (this.audioManager_.state == speech.AudioState.STOPPED) | 235 if (this.audioManager_.state == speech.AudioState.STOPPED) |
| 225 this.audioManager_.start(); | 236 this.audioManager_.start(); |
| 226 this.speechRecognitionManager_.start(); | 237 this.speechRecognitionManager_.start(); |
| 227 } | 238 } |
| 228 }; | 239 }; |
| 229 | 240 |
| 230 return { | 241 return { |
| 231 SpeechManager: SpeechManager | 242 SpeechManager: SpeechManager |
| 232 }; | 243 }; |
| 233 }); | 244 }); |
| OLD | NEW |