diff options
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/speech/speech_recognition_request.cc | 2 | ||||
-rw-r--r-- | content/browser/speech/speech_recognizer.cc | 3 | ||||
-rw-r--r-- | content/browser/speech/speech_recognizer.h | 4 | ||||
-rw-r--r-- | content/browser/speech/speech_recognizer_unittest.cc | 16 |
4 files changed, 23 insertions, 2 deletions
diff --git a/content/browser/speech/speech_recognition_request.cc b/content/browser/speech/speech_recognition_request.cc index 7d66aa7..19d8204 100644 --- a/content/browser/speech/speech_recognition_request.cc +++ b/content/browser/speech/speech_recognition_request.cc @@ -27,7 +27,7 @@ const char* const kConfidenceString = "confidence"; // TODO(satish): Remove this hardcoded value once the page is allowed to // set this via an attribute. -const int kMaxResults = 5; +const int kMaxResults = 6; bool ParseServerResponse(const std::string& response_body, speech_input::SpeechInputResultArray* result) { diff --git a/content/browser/speech/speech_recognizer.cc b/content/browser/speech/speech_recognizer.cc index 1807db0..7a4ebd1 100644 --- a/content/browser/speech/speech_recognizer.cc +++ b/content/browser/speech/speech_recognizer.cc @@ -219,7 +219,8 @@ void SpeechRecognizer::HandleOnData(string* data) { if (request_ == NULL) { // This was the first audio packet recorded, so start a request to the - // server to send the data. + // server to send the data and inform the delegate. + delegate_->DidStartReceivingAudio(caller_id_); request_.reset(new SpeechRecognitionRequest( Profile::GetDefaultRequestContext(), this)); request_->Start(language_, grammar_, hardware_info_, origin_url_, diff --git a/content/browser/speech/speech_recognizer.h b/content/browser/speech/speech_recognizer.h index 1afdecb..a87831e 100644 --- a/content/browser/speech/speech_recognizer.h +++ b/content/browser/speech/speech_recognizer.h @@ -41,6 +41,10 @@ class SpeechRecognizer bool error, const SpeechInputResultArray& result) = 0; + // Invoked when the first audio packet was received from the audio capture + // device. + virtual void DidStartReceivingAudio(int caller_id) = 0; + // Invoked when audio recording stops, either due to the end pointer // detecting silence in user input or if |StopRecording| was called. The // delegate has to wait until |DidCompleteRecognition| is invoked before diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc index 738eaf9..7239582 100644 --- a/content/browser/speech/speech_recognizer_unittest.cc +++ b/content/browser/speech/speech_recognizer_unittest.cc @@ -30,6 +30,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, recording_complete_(false), recognition_complete_(false), result_received_(false), + audio_received_(false), error_(SpeechRecognizer::RECOGNIZER_NO_ERROR), volume_(-1.0f) { int audio_packet_length_bytes = @@ -58,6 +59,10 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, virtual void DidCompleteEnvironmentEstimation(int caller_id) { } + virtual void DidStartReceivingAudio(int caller_id) { + audio_received_ = true; + } + virtual void OnRecognizerError(int caller_id, SpeechRecognizer::ErrorCode error) { error_ = error; @@ -101,6 +106,7 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, bool recording_complete_; bool recognition_complete_; bool result_received_; + bool audio_received_; SpeechRecognizer::ErrorCode error_; TestURLFetcherFactory url_fetcher_factory_; TestAudioInputControllerFactory audio_input_controller_factory_; @@ -116,6 +122,7 @@ TEST_F(SpeechRecognizerTest, StopNoData) { EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); + EXPECT_FALSE(audio_received_); EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); } @@ -127,6 +134,7 @@ TEST_F(SpeechRecognizerTest, CancelNoData) { EXPECT_TRUE(recording_complete_); EXPECT_TRUE(recognition_complete_); EXPECT_FALSE(result_received_); + EXPECT_FALSE(audio_received_); EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); } @@ -153,6 +161,7 @@ TEST_F(SpeechRecognizerTest, StopWithData) { } recognizer_->StopRecording(); + EXPECT_TRUE(audio_received_); EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); @@ -183,6 +192,7 @@ TEST_F(SpeechRecognizerTest, CancelWithData) { MessageLoop::current()->RunAllPending(); recognizer_->CancelRecognition(); ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); + EXPECT_TRUE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); @@ -203,6 +213,7 @@ TEST_F(SpeechRecognizerTest, ConnectionError) { ASSERT_TRUE(fetcher); recognizer_->StopRecording(); + EXPECT_TRUE(audio_received_); EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); @@ -233,6 +244,7 @@ TEST_F(SpeechRecognizerTest, ServerError) { ASSERT_TRUE(fetcher); recognizer_->StopRecording(); + EXPECT_TRUE(audio_received_); EXPECT_TRUE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); @@ -257,6 +269,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) { ASSERT_TRUE(controller); controller->event_handler()->OnError(controller, 0); MessageLoop::current()->RunAllPending(); + EXPECT_FALSE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); @@ -275,6 +288,7 @@ TEST_F(SpeechRecognizerTest, AudioControllerErrorWithData) { controller->event_handler()->OnError(controller, 0); MessageLoop::current()->RunAllPending(); ASSERT_TRUE(url_fetcher_factory_.GetFetcherByID(0)); + EXPECT_TRUE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); @@ -299,6 +313,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackIssued) { audio_packet_.size()); } MessageLoop::current()->RunAllPending(); + EXPECT_TRUE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); EXPECT_FALSE(result_received_); @@ -334,6 +349,7 @@ TEST_F(SpeechRecognizerTest, NoSpeechCallbackNotIssued) { MessageLoop::current()->RunAllPending(); EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_); + EXPECT_TRUE(audio_received_); EXPECT_FALSE(recording_complete_); EXPECT_FALSE(recognition_complete_); recognizer_->CancelRecognition(); |