Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 cr.define('hotword', function() { | 5 cr.define('hotword', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Class to manage hotwording state. Starts/stops the hotword detector based | 9 * Class to manage hotwording state. Starts/stops the hotword detector based |
| 10 * on user settings, session requests, and any other factors that play into | 10 * on user settings, session requests, and any other factors that play into |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 * @private {?hotword.constants.SessionSource} | 36 * @private {?hotword.constants.SessionSource} |
| 37 */ | 37 */ |
| 38 this.sessionSource_ = null; | 38 this.sessionSource_ = null; |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Callback to run when the hotword detector has successfully started. | 41 * Callback to run when the hotword detector has successfully started. |
| 42 * @private {!function()} | 42 * @private {!function()} |
| 43 */ | 43 */ |
| 44 this.sessionStartedCb_ = null; | 44 this.sessionStartedCb_ = null; |
| 45 | 45 |
| 46 /** | |
| 47 * Hotword trigger audio notification... a.k.a The Chime (tm). | |
| 48 * @private {!Audio} | |
| 49 */ | |
| 50 this.chime_ = document.createElement('audio'); | |
| 51 | |
| 46 // Get the initial status. | 52 // Get the initial status. |
| 47 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); | 53 chrome.hotwordPrivate.getStatus(this.handleStatus_.bind(this)); |
| 54 | |
| 55 // Setup the chime and insert into the page. | |
| 56 this.chime_.src = chrome.extension.getURL( | |
| 57 hotword.constants.SHARED_MODULE_ROOT + '/audio/chime.wav'); | |
| 58 document.body.appendChild(this.chime_); | |
|
Dan Beam
2014/09/23 03:43:13
what happens if this fails to load?
Anand Mistry (off Chromium)
2014/09/24 01:35:02
There'll be a warning on the console for this exte
| |
| 48 } | 59 } |
| 49 | 60 |
| 50 /** | 61 /** |
| 51 * @enum {number} | 62 * @enum {number} |
| 52 * @private | 63 * @private |
| 53 */ | 64 */ |
| 54 StateManager.State_ = { | 65 StateManager.State_ = { |
| 55 STOPPED: 0, | 66 STOPPED: 0, |
| 56 STARTING: 1, | 67 STARTING: 1, |
| 57 RUNNING: 2, | 68 RUNNING: 2, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 | 231 |
| 221 /** | 232 /** |
| 222 * Handle hotword triggering. | 233 * Handle hotword triggering. |
| 223 * @private | 234 * @private |
| 224 */ | 235 */ |
| 225 onTrigger_: function() { | 236 onTrigger_: function() { |
| 226 assert(this.pluginManager_); | 237 assert(this.pluginManager_); |
| 227 // Detector implicitly stops when the hotword is detected. | 238 // Detector implicitly stops when the hotword is detected. |
| 228 this.state_ = State_.STOPPED; | 239 this.state_ = State_.STOPPED; |
| 229 | 240 |
| 241 // Play the chime. | |
| 242 this.chime_.play(); | |
|
Dan Beam
2014/09/23 03:43:13
can this handle being called before the sound stop
Anand Mistry (off Chromium)
2014/09/24 01:35:02
The sound is shorter than 1 second. I don't think
| |
| 243 | |
| 230 chrome.hotwordPrivate.notifyHotwordRecognition('search', function() {}); | 244 chrome.hotwordPrivate.notifyHotwordRecognition('search', function() {}); |
| 231 | 245 |
| 232 // Implicitly clear the session. A session needs to be started in order to | 246 // Implicitly clear the session. A session needs to be started in order to |
| 233 // restart the detector. | 247 // restart the detector. |
| 234 this.sessionSource_ = null; | 248 this.sessionSource_ = null; |
| 235 this.sessionStartedCb_ = null; | 249 this.sessionStartedCb_ = null; |
| 236 }, | 250 }, |
| 237 | 251 |
| 238 /** | 252 /** |
| 239 * Start a hotwording session. | 253 * Start a hotwording session. |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 257 this.sessionSource_ = null; | 271 this.sessionSource_ = null; |
| 258 this.sessionStartedCb_ = null; | 272 this.sessionStartedCb_ = null; |
| 259 this.updateStateFromStatus_(); | 273 this.updateStateFromStatus_(); |
| 260 } | 274 } |
| 261 }; | 275 }; |
| 262 | 276 |
| 263 return { | 277 return { |
| 264 StateManager: StateManager | 278 StateManager: StateManager |
| 265 }; | 279 }; |
| 266 }); | 280 }); |
| OLD | NEW |