Commit 00a89246 authored by mukai@chromium.org's avatar mukai@chromium.org

Fixes hotword nacl handler to support the new behavior.

- 'stopped' won't appear during initialization, the check doesn't
  work well.
- 'audio' means recognizer has started. This is mostly harmless but
  better to stop when it's not used.
- the recognition pattern has changed to 'hotword: '

BUG=356873
R=xiyuan@chromium.org
TEST=manually

Review URL: https://codereview.chromium.org/215573002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260440 0039d316-1c4b-4281-b951-d872f2087c98
parent 14e06410
...@@ -16,9 +16,8 @@ cr.define('speech', function() { ...@@ -16,9 +16,8 @@ cr.define('speech', function() {
var PluginState = { var PluginState = {
UNINITIALIZED: 0, UNINITIALIZED: 0,
LOADED: 1, LOADED: 1,
SAMPLING_RATE_READY: 2, READY: 2,
READY: 3, RECOGNIZING: 3
RECOGNIZING: 4
}; };
/** /**
...@@ -35,7 +34,7 @@ cr.define('speech', function() { ...@@ -35,7 +34,7 @@ cr.define('speech', function() {
/** /**
* The regexp pattern of the hotword recognition result. * The regexp pattern of the hotword recognition result.
*/ */
var recognitionPattern = /^HotwordFiredEvent:/; var recognitionPattern = /^(HotwordFiredEvent:|hotword)/;
/** /**
* @constructor * @constructor
...@@ -67,17 +66,13 @@ cr.define('speech', function() { ...@@ -67,17 +66,13 @@ cr.define('speech', function() {
* @private * @private
*/ */
PluginManager.prototype.onMessage_ = function(messageEvent) { PluginManager.prototype.onMessage_ = function(messageEvent) {
if (this.state == PluginState.LOADED) {
if (messageEvent.data == 'stopped')
this.state = PluginState.SAMPLING_RATE_READY;
return;
}
if (messageEvent.data == 'audio') { if (messageEvent.data == 'audio') {
if (this.state < PluginState.READY) var wasNotReady = this.state < PluginState.READY;
this.onReady_(this);
this.state = PluginState.RECOGNIZING; this.state = PluginState.RECOGNIZING;
} else if (messageEvent.data == 'stopped') { if (wasNotReady)
this.onReady_(this);
} else if (messageEvent.data == 'stopped' &&
this.state == PluginState.RECOGNIZING) {
this.state = PluginState.READY; this.state = PluginState.READY;
} else if (recognitionPattern.exec(messageEvent.data)) { } else if (recognitionPattern.exec(messageEvent.data)) {
this.onRecognized_(); this.onRecognized_();
......
...@@ -82,6 +82,7 @@ cr.define('speech', function() { ...@@ -82,6 +82,7 @@ cr.define('speech', function() {
this.audioManager_.start(); this.audioManager_.start();
this.setState_(SpeechState.HOTWORD_RECOGNIZING); this.setState_(SpeechState.HOTWORD_RECOGNIZING);
} else { } else {
this.pluginManager_.stopRecognizer();
this.setState_(SpeechState.READY); this.setState_(SpeechState.READY);
} }
chrome.send('setHotwordRecognizerState', [true]); chrome.send('setHotwordRecognizerState', [true]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment