summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/generated_resources.grd4
-rw-r--r--chrome/browser/speech/speech_input_manager.cc38
-rw-r--r--content/browser/speech/speech_recognizer.cc5
-rw-r--r--content/browser/speech/speech_recognizer.h1
-rw-r--r--content/browser/speech/speech_recognizer_unittest.cc63
5 files changed, 90 insertions, 21 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index ff8a6ff..ebafb03 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -11499,14 +11499,14 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_SPEECH_INPUT_BUBBLE_WORKING" desc="Message shown to the user while waiting for speech recognition results to arrive.">
Working
</message>
- <message name="IDS_SPEECH_INPUT_ERROR" desc="Message shown when audio recording failed with an error during speech recognition.">
+ <message name="IDS_SPEECH_INPUT_MIC_ERROR" desc="Message shown when audio recording failed with an error during speech recognition.">
There was a problem with your microphone.
</message>
<message name="IDS_SPEECH_INPUT_NO_MIC" desc="Message shown when speech recognizer could not find a suitable microphone or other audio input device.">
No microphone found.
</message>
<message name="IDS_SPEECH_INPUT_NO_SPEECH" desc="Message shown when speech recognizer detected no speech in the recorded audio.">
- We didn't hear you.
+ No speech heard.
</message>
<message name="IDS_SPEECH_INPUT_NO_RESULTS" desc="Message shown when speech recognizer returned zero results.">
Speech not recognized.
diff --git a/chrome/browser/speech/speech_input_manager.cc b/chrome/browser/speech/speech_input_manager.cc
index 5f65e02..09836d4 100644
--- a/chrome/browser/speech/speech_input_manager.cc
+++ b/chrome/browser/speech/speech_input_manager.cc
@@ -306,23 +306,31 @@ void SpeechInputManagerImpl::OnRecognizerError(
requests_[caller_id].is_active = false;
- int message_id;
- switch (error) {
- case SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE:
- message_id = IDS_SPEECH_INPUT_ERROR;
- break;
- case SpeechRecognizer::RECOGNIZER_ERROR_NO_SPEECH:
- message_id = IDS_SPEECH_INPUT_NO_SPEECH;
- break;
- case SpeechRecognizer::RECOGNIZER_ERROR_NO_RESULTS:
- message_id = IDS_SPEECH_INPUT_NO_RESULTS;
- break;
- default:
- NOTREACHED() << "unknown error " << error;
+ struct ErrorMessageMapEntry {
+ SpeechRecognizer::ErrorCode error;
+ int message_id;
+ };
+ ErrorMessageMapEntry error_message_map[] = {
+ {
+ SpeechRecognizer::RECOGNIZER_ERROR_CAPTURE, IDS_SPEECH_INPUT_MIC_ERROR
+ }, {
+ SpeechRecognizer::RECOGNIZER_ERROR_NO_SPEECH, IDS_SPEECH_INPUT_NO_SPEECH
+ }, {
+ SpeechRecognizer::RECOGNIZER_ERROR_NO_RESULTS, IDS_SPEECH_INPUT_NO_RESULTS
+ }, {
+ SpeechRecognizer::RECOGNIZER_ERROR_NETWORK, IDS_SPEECH_INPUT_NET_ERROR
+ }
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(error_message_map); ++i) {
+ if (error_message_map[i].error == error) {
+ bubble_controller_->SetBubbleMessage(
+ caller_id,
+ l10n_util::GetStringUTF16(error_message_map[i].message_id));
return;
+ }
}
- bubble_controller_->SetBubbleMessage(caller_id,
- l10n_util::GetStringUTF16(message_id));
+
+ NOTREACHED() << "unknown error " << error;
}
void SpeechInputManagerImpl::DidCompleteEnvironmentEstimation(int caller_id) {
diff --git a/content/browser/speech/speech_recognizer.cc b/content/browser/speech/speech_recognizer.cc
index 3b7b89e..3b9201a 100644
--- a/content/browser/speech/speech_recognizer.cc
+++ b/content/browser/speech/speech_recognizer.cc
@@ -278,8 +278,9 @@ void SpeechRecognizer::HandleOnData(string* data) {
void SpeechRecognizer::SetRecognitionResult(
bool error, const SpeechInputResultArray& result) {
- if (result.empty()) {
- InformErrorAndCancelRecognition(RECOGNIZER_ERROR_NO_RESULTS);
+ if (error || result.empty()) {
+ InformErrorAndCancelRecognition(error ? RECOGNIZER_ERROR_NETWORK :
+ RECOGNIZER_ERROR_NO_RESULTS);
return;
}
diff --git a/content/browser/speech/speech_recognizer.h b/content/browser/speech/speech_recognizer.h
index d8c6d9a..faf4ace 100644
--- a/content/browser/speech/speech_recognizer.h
+++ b/content/browser/speech/speech_recognizer.h
@@ -30,6 +30,7 @@ class SpeechRecognizer
RECOGNIZER_ERROR_CAPTURE,
RECOGNIZER_ERROR_NO_SPEECH,
RECOGNIZER_ERROR_NO_RESULTS,
+ RECOGNIZER_ERROR_NETWORK,
};
// Implemented by the caller to receive recognition events.
diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc
index c7c7e91..f3c9cee 100644
--- a/content/browser/speech/speech_recognizer_unittest.cc
+++ b/content/browser/speech/speech_recognizer_unittest.cc
@@ -8,6 +8,7 @@
#include "content/browser/browser_thread.h"
#include "content/browser/speech/speech_recognizer.h"
#include "media/audio/test_audio_input_controller_factory.h"
+#include "net/base/net_errors.h"
#include "net/url_request/url_request_status.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -136,8 +137,6 @@ TEST_F(SpeechRecognizerTest, StopWithData) {
TestAudioInputController* controller =
audio_input_controller_factory_.controller();
ASSERT_TRUE(controller);
- controller = audio_input_controller_factory_.controller();
- ASSERT_TRUE(controller);
// Try sending 5 chunks of mock audio data and verify that each of them
// resulted immediately in a packet sent out via the network. This verifies
@@ -190,6 +189,66 @@ TEST_F(SpeechRecognizerTest, CancelWithData) {
EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_);
}
+TEST_F(SpeechRecognizerTest, ConnectionError) {
+ // Start recording, give some data and then stop. Issue the network callback
+ // with a connection error and verify that the recognizer bubbles the error up
+ EXPECT_TRUE(recognizer_->StartRecording());
+ TestAudioInputController* controller =
+ audio_input_controller_factory_.controller();
+ ASSERT_TRUE(controller);
+ controller->event_handler()->OnData(controller, &audio_packet_[0],
+ audio_packet_.size());
+ MessageLoop::current()->RunAllPending();
+ TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
+ ASSERT_TRUE(fetcher);
+
+ recognizer_->StopRecording();
+ EXPECT_TRUE(recording_complete_);
+ EXPECT_FALSE(recognition_complete_);
+ EXPECT_FALSE(result_received_);
+ EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_);
+
+ // Issue the network callback to complete the process.
+ net::URLRequestStatus status;
+ status.set_status(net::URLRequestStatus::FAILED);
+ status.set_os_error(net::ERR_CONNECTION_REFUSED);
+ fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(),
+ status, 0, ResponseCookies(), "");
+ EXPECT_FALSE(recognition_complete_);
+ EXPECT_FALSE(result_received_);
+ EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NETWORK, error_);
+}
+
+TEST_F(SpeechRecognizerTest, ServerError) {
+ // Start recording, give some data and then stop. Issue the network callback
+ // with a 500 error and verify that the recognizer bubbles the error up
+ EXPECT_TRUE(recognizer_->StartRecording());
+ TestAudioInputController* controller =
+ audio_input_controller_factory_.controller();
+ ASSERT_TRUE(controller);
+ controller->event_handler()->OnData(controller, &audio_packet_[0],
+ audio_packet_.size());
+ MessageLoop::current()->RunAllPending();
+ TestURLFetcher* fetcher = url_fetcher_factory_.GetFetcherByID(0);
+ ASSERT_TRUE(fetcher);
+
+ recognizer_->StopRecording();
+ EXPECT_TRUE(recording_complete_);
+ EXPECT_FALSE(recognition_complete_);
+ EXPECT_FALSE(result_received_);
+ EXPECT_EQ(SpeechRecognizer::RECOGNIZER_NO_ERROR, error_);
+
+ // Issue the network callback to complete the process.
+ net::URLRequestStatus status;
+ status.set_status(net::URLRequestStatus::SUCCESS);
+ fetcher->delegate()->OnURLFetchComplete(fetcher, fetcher->original_url(),
+ status, 500, ResponseCookies(),
+ "Internal Server Error");
+ EXPECT_FALSE(recognition_complete_);
+ EXPECT_FALSE(result_received_);
+ EXPECT_EQ(SpeechRecognizer::RECOGNIZER_ERROR_NETWORK, error_);
+}
+
TEST_F(SpeechRecognizerTest, AudioControllerErrorNoData) {
// Check if things tear down properly if AudioInputController threw an error.
EXPECT_TRUE(recognizer_->StartRecording());