| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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 used to manage the state of the NaCl recognizer plugin. Handles all | 9  * Class used to manage the state of the NaCl recognizer plugin. Handles all | 
| 10  * control of the NaCl plugin, including creation, start, stop, trigger, and | 10  * control of the NaCl plugin, including creation, start, stop, trigger, and | 
| 11  * shutdown. | 11  * shutdown. | 
| 12  * | 12  * | 
| 13  * @param {boolean} loggingEnabled Whether audio logging is enabled. | 13  * @param {boolean} loggingEnabled Whether audio logging is enabled. | 
|  | 14  * @param {boolean} hotwordStream Whether the audio input stream is from a | 
|  | 15  *     hotword stream. | 
| 14  * @constructor | 16  * @constructor | 
| 15  * @extends {cr.EventTarget} | 17  * @extends {cr.EventTarget} | 
| 16  */ | 18  */ | 
| 17 function NaClManager(loggingEnabled) { | 19 function NaClManager(loggingEnabled, hotwordStream) { | 
| 18   /** | 20   /** | 
| 19    * Current state of this manager. | 21    * Current state of this manager. | 
| 20    * @private {hotword.NaClManager.ManagerState_} | 22    * @private {hotword.NaClManager.ManagerState_} | 
| 21    */ | 23    */ | 
| 22   this.recognizerState_ = ManagerState_.UNINITIALIZED; | 24   this.recognizerState_ = ManagerState_.UNINITIALIZED; | 
| 23 | 25 | 
| 24   /** | 26   /** | 
| 25    * The window.timeout ID associated with a pending message. | 27    * The window.timeout ID associated with a pending message. | 
| 26    * @private {?number} | 28    * @private {?number} | 
| 27    */ | 29    */ | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 63    */ | 65    */ | 
| 64   this.startMode_ = hotword.constants.RecognizerStartMode.NORMAL; | 66   this.startMode_ = hotword.constants.RecognizerStartMode.NORMAL; | 
| 65 | 67 | 
| 66   /** | 68   /** | 
| 67    * Whether audio logging is enabled. | 69    * Whether audio logging is enabled. | 
| 68    * @private {boolean} | 70    * @private {boolean} | 
| 69    */ | 71    */ | 
| 70   this.loggingEnabled_ = loggingEnabled; | 72   this.loggingEnabled_ = loggingEnabled; | 
| 71 | 73 | 
| 72   /** | 74   /** | 
|  | 75    * Whether the audio input stream is from a hotword stream. | 
|  | 76    * @private {boolean} | 
|  | 77    */ | 
|  | 78   this.hotwordStream_ = hotwordStream; | 
|  | 79 | 
|  | 80   /** | 
| 73    * Audio log of X seconds before hotword triggered. | 81    * Audio log of X seconds before hotword triggered. | 
| 74    * @private {?Object} | 82    * @private {?Object} | 
| 75    */ | 83    */ | 
| 76   this.preambleLog_ = null; | 84   this.preambleLog_ = null; | 
| 77 }; | 85 }; | 
| 78 | 86 | 
| 79 /** | 87 /** | 
| 80  * States this manager can be in. Since messages to/from the plugin are | 88  * States this manager can be in. Since messages to/from the plugin are | 
| 81  * asynchronous (and potentially queued), it's not possible to know what state | 89  * asynchronous (and potentially queued), it's not possible to know what state | 
| 82  * the plugin is in. However, track a state machine for NaClManager based on | 90  * the plugin is in. However, track a state machine for NaClManager based on | 
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 425   this.waitForMessage_(hotword.constants.TimeoutMs.LONG, | 433   this.waitForMessage_(hotword.constants.TimeoutMs.LONG, | 
| 426                        hotword.constants.NaClPlugin.MODEL_LOADED); | 434                        hotword.constants.NaClPlugin.MODEL_LOADED); | 
| 427 | 435 | 
| 428   // Configure logging in the plugin. This can be configured any time before | 436   // Configure logging in the plugin. This can be configured any time before | 
| 429   // starting the recognizer, and now is as good a time as any. | 437   // starting the recognizer, and now is as good a time as any. | 
| 430   if (this.loggingEnabled_) { | 438   if (this.loggingEnabled_) { | 
| 431     this.sendDataToPlugin_( | 439     this.sendDataToPlugin_( | 
| 432         hotword.constants.NaClPlugin.LOG + ':' + | 440         hotword.constants.NaClPlugin.LOG + ':' + | 
| 433         hotword.constants.AUDIO_LOG_SECONDS); | 441         hotword.constants.AUDIO_LOG_SECONDS); | 
| 434   } | 442   } | 
|  | 443 | 
|  | 444   // If the audio stream is from a hotword stream, tell the plugin. | 
|  | 445   if (this.hotwordStream_) { | 
|  | 446     this.sendDataToPlugin_( | 
|  | 447         hotword.constants.NaClPlugin.DSP + ':' + | 
|  | 448         hotword.constants.HOTWORD_STREAM_TIMEOUT_SECONDS); | 
|  | 449   } | 
| 435 }; | 450 }; | 
| 436 | 451 | 
| 437 /** | 452 /** | 
| 438  * Handle a MODEL_LOADED message from the plugin. | 453  * Handle a MODEL_LOADED message from the plugin. | 
| 439  * The plugin sends this message after successfully loading the language model. | 454  * The plugin sends this message after successfully loading the language model. | 
| 440  * @private | 455  * @private | 
| 441  */ | 456  */ | 
| 442 NaClManager.prototype.handleModelLoaded_ = function() { | 457 NaClManager.prototype.handleModelLoaded_ = function() { | 
| 443   if (this.recognizerState_ != ManagerState_.LOADING) { | 458   if (this.recognizerState_ != ManagerState_.LOADING) { | 
| 444     return; | 459     return; | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 572         break; | 587         break; | 
| 573     } | 588     } | 
| 574   } | 589   } | 
| 575 }; | 590 }; | 
| 576 | 591 | 
| 577 return { | 592 return { | 
| 578   NaClManager: NaClManager | 593   NaClManager: NaClManager | 
| 579 }; | 594 }; | 
| 580 | 595 | 
| 581 }); | 596 }); | 
| OLD | NEW | 
|---|