| Index: chrome/browser/resources/app_list/speech_manager.js
|
| diff --git a/chrome/browser/resources/app_list/speech_manager.js b/chrome/browser/resources/app_list/speech_manager.js
|
| index 90f099e4e5b32ab3917f31160c0673d5ca02f274..dba7c950b71d777e85002b96228ab1b7b1b3703e 100644
|
| --- a/chrome/browser/resources/app_list/speech_manager.js
|
| +++ b/chrome/browser/resources/app_list/speech_manager.js
|
| @@ -22,6 +22,7 @@ cr.define('speech', function() {
|
| READY: 'READY',
|
| HOTWORD_RECOGNIZING: 'HOTWORD_RECOGNIZING',
|
| RECOGNIZING: 'RECOGNIZING',
|
| + IN_SPEECH: 'IN_SPEECH',
|
| STOPPING: 'STOPPING'
|
| };
|
|
|
| @@ -39,6 +40,7 @@ cr.define('speech', function() {
|
| this.audioManager_.getSampleRate(),
|
| 'chrome://app-list/okgoogle_hotword.config');
|
| }
|
| + this.shown_ = false;
|
| this.speechRecognitionManager_ = new speech.SpeechRecognitionManager(this);
|
| this.setState_(SpeechState.READY);
|
| }
|
| @@ -51,6 +53,7 @@ cr.define('speech', function() {
|
| */
|
| SpeechManager.prototype.setState_ = function(newState) {
|
| this.state = newState;
|
| + chrome.send('setSpeechRecognitionState', [this.state]);
|
| };
|
|
|
| /**
|
| @@ -79,7 +82,13 @@ cr.define('speech', function() {
|
| this.pluginManager_ = pluginManager;
|
| this.audioManager_.addEventListener(
|
| 'audio', pluginManager.sendAudioData.bind(pluginManager));
|
| - this.setState_(SpeechState.READY);
|
| + if (this.shown_) {
|
| + this.pluginManager_.startRecognizer();
|
| + this.audioManager_.start();
|
| + this.setState_(SpeechState.HOTWORD_RECOGNIZING);
|
| + } else {
|
| + this.setState_(SpeechState.READY);
|
| + }
|
| };
|
|
|
| /**
|
| @@ -113,7 +122,6 @@ cr.define('speech', function() {
|
| */
|
| SpeechManager.prototype.onSpeechRecognitionStarted = function() {
|
| this.setState_(SpeechState.RECOGNIZING);
|
| - chrome.send('setSpeechRecognitionState', ['on']);
|
| };
|
|
|
| /**
|
| @@ -136,15 +144,15 @@ cr.define('speech', function() {
|
| */
|
| SpeechManager.prototype.onSpeechStarted = function() {
|
| if (this.state == SpeechState.RECOGNIZING)
|
| - chrome.send('setSpeechRecognitionState', ['in-speech']);
|
| + this.setState_(SpeechState.IN_SPEECH);
|
| };
|
|
|
| /**
|
| * Called when a speech has ended.
|
| */
|
| SpeechManager.prototype.onSpeechEnded = function() {
|
| - if (this.state == SpeechState.RECOGNIZING)
|
| - chrome.send('setSpeechRecognitionState', ['on']);
|
| + if (this.state == SpeechState.IN_SPEECH)
|
| + this.setState_(SpeechState.RECOGNIZING);
|
| };
|
|
|
| /**
|
| @@ -158,9 +166,10 @@ cr.define('speech', function() {
|
| };
|
|
|
| /**
|
| - * Starts the speech recognition session.
|
| + * Called when the app-list bubble is shown.
|
| */
|
| - SpeechManager.prototype.start = function() {
|
| + SpeechManager.prototype.onShown = function() {
|
| + this.shown_ = true;
|
| if (!this.pluginManager_)
|
| return;
|
|
|
| @@ -175,15 +184,17 @@ cr.define('speech', function() {
|
| };
|
|
|
| /**
|
| - * Stops the speech recognition session.
|
| + * Called when the app-list bubble is hidden.
|
| */
|
| - SpeechManager.prototype.stop = function() {
|
| + SpeechManager.prototype.onHidden = function() {
|
| + this.shown_ = false;
|
| if (this.pluginManager_)
|
| this.pluginManager_.stopRecognizer();
|
|
|
| // SpeechRecognition is asynchronous.
|
| this.audioManager_.stop();
|
| - if (this.state == SpeechState.RECOGNIZING) {
|
| + if (this.state == SpeechState.RECOGNIZING ||
|
| + this.state == SpeechState.IN_SPEECH) {
|
| this.setState_(SpeechState.STOPPING);
|
| this.speechRecognitionManager_.stop();
|
| } else {
|
| @@ -195,7 +206,8 @@ cr.define('speech', function() {
|
| * Toggles the current state of speech recognition.
|
| */
|
| SpeechManager.prototype.toggleSpeechRecognition = function() {
|
| - if (this.state == SpeechState.RECOGNIZING) {
|
| + if (this.state == SpeechState.RECOGNIZING ||
|
| + this.state == SpeechState.IN_SPEECH) {
|
| this.audioManager_.stop();
|
| this.speechRecognitionManager_.stop();
|
| } else {
|
|
|