Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Unified Diff: chrome/browser/resources/app_list/speech_manager.js

Issue 149753002: Enables the 'hotword not listening' icon in the search box. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix breaks Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/app_list/start_page.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/app_list/start_page.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698