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

Unified Diff: content/browser/speech/speech_recognizer.cc

Issue 8137005: Applying changes to the existing speech input code to support the extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixing unit tests. Created 9 years, 2 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
Index: content/browser/speech/speech_recognizer.cc
diff --git a/content/browser/speech/speech_recognizer.cc b/content/browser/speech/speech_recognizer.cc
index 295f156c7efba488efa9a8457bce92a4a94b20e2..db61a1bc1b0b73e1e2a7ca8a1639500e267416b0 100644
--- a/content/browser/speech/speech_recognizer.cc
+++ b/content/browser/speech/speech_recognizer.cc
@@ -169,6 +169,18 @@ void SpeechRecognizer::StopRecording() {
}
// Invoked in the audio thread.
+void SpeechRecognizer::OnRecording(AudioInputController* controller) {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &SpeechRecognizer::HandleOnRecording));
+}
+
+void SpeechRecognizer::HandleOnRecording() {
+ // Guard against the delegate freeing us until we finish our job.
+ scoped_refptr<SpeechRecognizer> me(this);
+ delegate_->OnRecording(caller_id_);
+}
+
+// Invoked in the audio thread.
void SpeechRecognizer::OnError(AudioInputController* controller,
int error_code) {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
@@ -210,6 +222,8 @@ void SpeechRecognizer::HandleOnData(string* data) {
return;
}
+ bool speech_started = endpointer_.DidStartReceivingSpeech();
Satish 2011/10/04 20:36:33 suggest renaming to speech_was_heard to indicate t
Leandro Graciá Gil 2011/10/05 22:09:00 Done.
+
const short* samples = reinterpret_cast<const short*>(data->data());
DCHECK((data->length() % sizeof(short)) == 0);
int num_samples = data->length() / sizeof(short);
@@ -252,6 +266,9 @@ void SpeechRecognizer::HandleOnData(string* data) {
return;
}
+ if (!speech_started && endpointer_.DidStartReceivingSpeech())
+ delegate_->DidSpeechInputStart(caller_id_);
+
// Calculate the input volume to display in the UI, smoothing towards the
// new level.
float level = (rms - kAudioMeterMinDb) /
@@ -273,6 +290,7 @@ void SpeechRecognizer::HandleOnData(string* data) {
if (endpointer_.speech_input_complete()) {
StopRecording();
+ delegate_->DidSpeechInputStop(caller_id_);
Satish 2011/10/04 20:36:33 instead of invoking this here do it inside StopRec
Leandro Graciá Gil 2011/10/05 22:09:00 Done.
}
// TODO(satish): Once we have streaming POST, start sending the data received
@@ -280,17 +298,50 @@ void SpeechRecognizer::HandleOnData(string* data) {
}
void SpeechRecognizer::SetRecognitionResult(
- bool error, const SpeechInputResultArray& result) {
- if (error || result.empty()) {
- InformErrorAndCancelRecognition(error ? RECOGNIZER_ERROR_NETWORK :
- RECOGNIZER_ERROR_NO_RESULTS);
+ bool error, const SpeechInputResult& result) {
+ if (error) {
+ // Request failed or received an invalid response that couldn't be parsed.
+ InformErrorAndCancelRecognition(RECOGNIZER_ERROR_NETWORK);
return;
}
- delegate_->SetRecognitionResult(caller_id_, error, result);
+ switch (result.status) {
+ case kStatusSuccess:
+ break;
+
+ case kStatusAborted:
+ InformErrorAndCancelRecognition(RECOGNIZER_ERROR_INTERNAL);
+ return;
+
+ case kStatusBadGrammar:
+ InformErrorAndCancelRecognition(RECOGNIZER_ERROR_INVALID_PARAMS);
+ return;
+
+ case kStatusAudio:
+ InformErrorAndCancelRecognition(RECOGNIZER_ERROR_CAPTURE);
+ return;
+
+ case kStatusNetwork:
+ InformErrorAndCancelRecognition(RECOGNIZER_ERROR_NETWORK);
+ return;
+
+ case kStatusNoSpeech:
+ InformErrorAndCancelRecognition(RECOGNIZER_ERROR_NO_SPEECH);
+ return;
+
+ case kStatusNoMatch:
+ InformErrorAndCancelRecognition(RECOGNIZER_ERROR_NO_RESULTS);
+ return;
+
+ default:
+ NOTREACHED();
+ }
+
+ StopRecording();
Satish 2011/10/04 20:36:33 why is this call required here? wouldn't recogniti
Leandro Graciá Gil 2011/10/05 22:09:00 Done.
// Guard against the delegate freeing us until we finish our job.
scoped_refptr<SpeechRecognizer> me(this);
+ delegate_->SetRecognitionResult(caller_id_, error, result);
delegate_->DidCompleteRecognition(caller_id_);
}

Powered by Google App Engine
This is Rietveld 408576698