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

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: mac bot fix. 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
« no previous file with comments | « content/browser/speech/speech_recognizer.h ('k') | content/browser/speech/speech_recognizer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f81128c3c94867530616c3f1bbf9e4560e224226 100644
--- a/content/browser/speech/speech_recognizer.cc
+++ b/content/browser/speech/speech_recognizer.cc
@@ -145,6 +145,7 @@ void SpeechRecognizer::StopRecording() {
audio_controller_->Close();
audio_controller_ = NULL; // Releases the ref ptr.
+ delegate_->DidStopReceivingSpeech(caller_id_);
delegate_->DidCompleteRecording(caller_id_);
// UploadAudioChunk requires a non-empty final buffer. So we encode a packet
@@ -186,7 +187,7 @@ void SpeechRecognizer::HandleOnError(int error_code) {
if (!audio_controller_.get())
return;
- InformErrorAndCancelRecognition(RECOGNIZER_ERROR_CAPTURE);
+ InformErrorAndCancelRecognition(kErrorAudio);
}
void SpeechRecognizer::OnData(AudioInputController* controller,
@@ -210,6 +211,8 @@ void SpeechRecognizer::HandleOnData(string* data) {
return;
}
+ bool speech_was_heard_before_packet = endpointer_.DidStartReceivingSpeech();
+
const short* samples = reinterpret_cast<const short*>(data->data());
DCHECK((data->length() % sizeof(short)) == 0);
int num_samples = data->length() / sizeof(short);
@@ -246,12 +249,16 @@ void SpeechRecognizer::HandleOnData(string* data) {
}
// Check if we have waited too long without hearing any speech.
- if (!endpointer_.DidStartReceivingSpeech() &&
+ bool speech_was_heard_after_packet = endpointer_.DidStartReceivingSpeech();
+ if (!speech_was_heard_after_packet &&
num_samples_recorded_ >= kNoSpeechTimeoutSec * kAudioSampleRate) {
- InformErrorAndCancelRecognition(RECOGNIZER_ERROR_NO_SPEECH);
+ InformErrorAndCancelRecognition(kErrorNoSpeech);
return;
}
+ if (!speech_was_heard_before_packet && speech_was_heard_after_packet)
+ delegate_->DidStartReceivingSpeech(caller_id_);
+
// Calculate the input volume to display in the UI, smoothing towards the
// new level.
float level = (rms - kAudioMeterMinDb) /
@@ -271,30 +278,26 @@ void SpeechRecognizer::HandleOnData(string* data) {
delegate_->SetInputVolume(caller_id_, did_clip ? 1.0f : audio_level_,
noise_level);
- if (endpointer_.speech_input_complete()) {
+ if (endpointer_.speech_input_complete())
StopRecording();
- }
-
- // TODO(satish): Once we have streaming POST, start sending the data received
- // here as POST chunks.
}
void SpeechRecognizer::SetRecognitionResult(
- bool error, const SpeechInputResultArray& result) {
- if (error || result.empty()) {
- InformErrorAndCancelRecognition(error ? RECOGNIZER_ERROR_NETWORK :
- RECOGNIZER_ERROR_NO_RESULTS);
+ const SpeechInputResult& result) {
+ if (result.error != kErrorNone) {
+ InformErrorAndCancelRecognition(result.error);
return;
}
- delegate_->SetRecognitionResult(caller_id_, error, result);
-
// Guard against the delegate freeing us until we finish our job.
scoped_refptr<SpeechRecognizer> me(this);
+ delegate_->SetRecognitionResult(caller_id_, result);
delegate_->DidCompleteRecognition(caller_id_);
}
-void SpeechRecognizer::InformErrorAndCancelRecognition(ErrorCode error) {
+void SpeechRecognizer::InformErrorAndCancelRecognition(
+ SpeechInputError error) {
+ DCHECK_NE(error, kErrorNone);
CancelRecognition();
// Guard against the delegate freeing us until we finish our job.
« no previous file with comments | « content/browser/speech/speech_recognizer.h ('k') | content/browser/speech/speech_recognizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698