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

Unified Diff: content/browser/speech/speech_recognition_request.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_recognition_request.cc
diff --git a/content/browser/speech/speech_recognition_request.cc b/content/browser/speech/speech_recognition_request.cc
index 31b7f1ff45312a9d37cea9ae2e19e90f589faac7..cd822b06462ff44ae94685a233a3186fc6eb1795 100644
--- a/content/browser/speech/speech_recognition_request.cc
+++ b/content/browser/speech/speech_recognition_request.cc
@@ -20,6 +20,7 @@ namespace {
const char* const kDefaultSpeechRecognitionUrl =
"https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&";
+const char* const kStatusString = "status";
const char* const kHypothesesString = "hypotheses";
const char* const kUtteranceString = "utterance";
const char* const kConfidenceString = "confidence";
@@ -29,7 +30,7 @@ const char* const kConfidenceString = "confidence";
const int kMaxResults = 6;
bool ParseServerResponse(const std::string& response_body,
- speech_input::SpeechInputResultArray* result) {
+ speech_input::SpeechInputResult* result) {
if (response_body.empty()) {
LOG(WARNING) << "ParseServerResponse: Response was empty.";
return false;
@@ -53,18 +54,54 @@ bool ParseServerResponse(const std::string& response_body,
const DictionaryValue* response_object =
static_cast<DictionaryValue*>(response_value.get());
- // Get the hypotheses
+ // Get the status.
+ if (!response_object->HasKey(kStatusString)) {
+ VLOG(1) << "ParseServerResponse: cannot find " << kStatusString
+ << " in the response object.";
+ return false;
+ }
+
+ Value* status_value = NULL;
+ response_object->GetWithoutPathExpansion(kStatusString, &status_value);
Satish 2011/10/04 20:36:33 since the 'path' here is the first parameter and i
Leandro Graciá Gil 2011/10/05 22:09:00 I think you're getting it the other way around. Ge
+ DCHECK(status_value);
+
+ if (!status_value->IsType(Value::TYPE_INTEGER)) {
+ VLOG(1) << "ParseServerResponse: Unexpected response status type "
+ << status_value->GetType();
Satish 2011/10/04 20:36:33 return false here?
Leandro Graciá Gil 2011/10/05 22:09:00 Done.
+ }
+
+ int status;
+ DCHECK(status_value->GetAsInteger(&status));
+
+ // Process the status.
+ switch (status) {
+ case speech_input::kStatusSuccess:
+ case speech_input::kStatusNoSpeech:
+ case speech_input::kStatusNoMatch:
+ break;
+
+ default:
+ // Other status codes should not be returned by the server.
+ VLOG(1) << "ParseServerResponse: unexpected status code " << status;
+ return false;
+ }
+
+ result->status = static_cast<speech_input::SpeechInputResultStatus>(status);
+
+ // Get the hypotheses.
Value* hypotheses_value = NULL;
if (!response_object->Get(kHypothesesString, &hypotheses_value)) {
VLOG(1) << "ParseServerResponse: Missing hypotheses attribute.";
return false;
}
+
DCHECK(hypotheses_value);
if (!hypotheses_value->IsType(Value::TYPE_LIST)) {
VLOG(1) << "ParseServerResponse: Unexpected hypotheses type "
<< hypotheses_value->GetType();
return false;
}
+
const ListValue* hypotheses_list = static_cast<ListValue*>(hypotheses_value);
size_t index = 0;
@@ -93,12 +130,13 @@ bool ParseServerResponse(const std::string& response_body,
double confidence = 0.0;
hypothesis_value->GetDouble(kConfidenceString, &confidence);
- result->push_back(speech_input::SpeechInputResultItem(utterance,
- confidence));
+ result->hypotheses.push_back(speech_input::SpeechInputResultItem(
+ utterance, confidence));
}
if (index < hypotheses_list->GetSize()) {
- result->clear();
+ result->hypotheses.clear();
+ result->status = speech_input::kStatusAborted;
Satish 2011/10/04 20:36:33 is kStatusAborted the right error code? seems like
Leandro Graciá Gil 2011/10/05 22:09:00 Changed to network error since it seems the closes
return false;
}
@@ -185,7 +223,7 @@ void SpeechRecognitionRequest::OnURLFetchComplete(const URLFetcher* source) {
bool error =
!source->status().is_success() || source->response_code() != 200;
- SpeechInputResultArray result;
+ SpeechInputResult result;
if (!error)
error = !ParseServerResponse(source->GetResponseStringRef(), &result);
url_fetcher_.reset();

Powered by Google App Engine
This is Rietveld 408576698