| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 chrome.send('search', [result]); | 93 chrome.send('search', [result]); |
| 94 this.speechRecognitionManager_.stop(); | 94 this.speechRecognitionManager_.stop(); |
| 95 } | 95 } |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 /** | 98 /** |
| 99 * Called when the speech recognition has started. | 99 * Called when the speech recognition has started. |
| 100 */ | 100 */ |
| 101 SpeechManager.prototype.onSpeechRecognitionStarted = function() { | 101 SpeechManager.prototype.onSpeechRecognitionStarted = function() { |
| 102 this.setState_(SpeechState.RECOGNIZING); | 102 this.setState_(SpeechState.RECOGNIZING); |
| 103 chrome.send('setSpeechRecognitionState', [true]); |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 /** | 106 /** |
| 106 * Called when the speech recognition has ended. | 107 * Called when the speech recognition has ended. |
| 107 */ | 108 */ |
| 108 SpeechManager.prototype.onSpeechRecognitionEnded = function() { | 109 SpeechManager.prototype.onSpeechRecognitionEnded = function() { |
| 109 // Restarts the hotword recognition. | 110 // Restarts the hotword recognition. |
| 110 this.audioManager_.start(); | 111 this.audioManager_.start(); |
| 112 chrome.send('setSpeechRecognitionState', [false]); |
| 111 }; | 113 }; |
| 112 | 114 |
| 113 /** | 115 /** |
| 114 * Called when an error happened during the speech recognition. | 116 * Called when an error happened during the speech recognition. |
| 115 * | 117 * |
| 116 * @param {Error} e The error object. | 118 * @param {Error} e The error object. |
| 117 */ | 119 */ |
| 118 SpeechManager.prototype.onSpeechRecognitionError = function(e) { | 120 SpeechManager.prototype.onSpeechRecognitionError = function(e) { |
| 119 this.setState_(SpeechState.UNINITIALIZED); | 121 this.setState_(SpeechState.UNINITIALIZED); |
| 120 }; | 122 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 141 */ | 143 */ |
| 142 SpeechManager.prototype.stop = function() { | 144 SpeechManager.prototype.stop = function() { |
| 143 if (this.state == SpeechState.UNINITIALIZED) | 145 if (this.state == SpeechState.UNINITIALIZED) |
| 144 return; | 146 return; |
| 145 | 147 |
| 146 this.audioManager_.stop(); | 148 this.audioManager_.stop(); |
| 147 this.speechRecognitionManager_.stop(); | 149 this.speechRecognitionManager_.stop(); |
| 148 this.setState_(SpeechState.READY); | 150 this.setState_(SpeechState.READY); |
| 149 }; | 151 }; |
| 150 | 152 |
| 153 /** |
| 154 * Toggles the current state of speech recognition. |
| 155 */ |
| 156 SpeechManager.prototype.toggleSpeechRecognition = function() { |
| 157 if (this.state == SpeechState.RECOGNIZING) { |
| 158 this.speechRecognitionManager_.stop(); |
| 159 } else { |
| 160 this.audioManager_.stop(); |
| 161 this.speechRecognitionManager_.start(); |
| 162 } |
| 163 }; |
| 164 |
| 151 return { | 165 return { |
| 152 SpeechManager: SpeechManager | 166 SpeechManager: SpeechManager |
| 153 }; | 167 }; |
| 154 }); | 168 }); |
| OLD | NEW |