| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/speech/google_one_shot_remote_engine.h" | 5 #include "content/browser/speech/google_one_shot_remote_engine.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 LOG(WARNING) << "ParseServerResponse: JSONReader failed : " << error_msg; | 55 LOG(WARNING) << "ParseServerResponse: JSONReader failed : " << error_msg; |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 | 58 |
| 59 if (!response_value->IsType(Value::TYPE_DICTIONARY)) { | 59 if (!response_value->IsType(Value::TYPE_DICTIONARY)) { |
| 60 VLOG(1) << "ParseServerResponse: Unexpected response type " | 60 VLOG(1) << "ParseServerResponse: Unexpected response type " |
| 61 << response_value->GetType(); | 61 << response_value->GetType(); |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 const DictionaryValue* response_object = | 64 const DictionaryValue* response_object = |
| 65 static_cast<DictionaryValue*>(response_value.get()); | 65 static_cast<const DictionaryValue*>(response_value.get()); |
| 66 | 66 |
| 67 // Get the status. | 67 // Get the status. |
| 68 int status; | 68 int status; |
| 69 if (!response_object->GetInteger(kStatusString, &status)) { | 69 if (!response_object->GetInteger(kStatusString, &status)) { |
| 70 VLOG(1) << "ParseServerResponse: " << kStatusString | 70 VLOG(1) << "ParseServerResponse: " << kStatusString |
| 71 << " is not a valid integer value."; | 71 << " is not a valid integer value."; |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Process the status. | 75 // Process the status. |
| 76 switch (status) { | 76 switch (status) { |
| 77 case kWebServiceStatusNoError: | 77 case kWebServiceStatusNoError: |
| 78 break; | 78 break; |
| 79 case kWebServiceStatusNoSpeech: | 79 case kWebServiceStatusNoSpeech: |
| 80 error->code = content::SPEECH_RECOGNITION_ERROR_NO_SPEECH; | 80 error->code = content::SPEECH_RECOGNITION_ERROR_NO_SPEECH; |
| 81 return false; | 81 return false; |
| 82 case kWebServiceStatusNoMatch: | 82 case kWebServiceStatusNoMatch: |
| 83 error->code = content::SPEECH_RECOGNITION_ERROR_NO_MATCH; | 83 error->code = content::SPEECH_RECOGNITION_ERROR_NO_MATCH; |
| 84 return false; | 84 return false; |
| 85 default: | 85 default: |
| 86 error->code = content::SPEECH_RECOGNITION_ERROR_NETWORK; | 86 error->code = content::SPEECH_RECOGNITION_ERROR_NETWORK; |
| 87 // Other status codes should not be returned by the server. | 87 // Other status codes should not be returned by the server. |
| 88 VLOG(1) << "ParseServerResponse: unexpected status code " << status; | 88 VLOG(1) << "ParseServerResponse: unexpected status code " << status; |
| 89 return false; | 89 return false; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Get the hypotheses. | 92 // Get the hypotheses. |
| 93 Value* hypotheses_value = NULL; | 93 const Value* hypotheses_value = NULL; |
| 94 if (!response_object->Get(kHypothesesString, &hypotheses_value)) { | 94 if (!response_object->Get(kHypothesesString, &hypotheses_value)) { |
| 95 VLOG(1) << "ParseServerResponse: Missing hypotheses attribute."; | 95 VLOG(1) << "ParseServerResponse: Missing hypotheses attribute."; |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 DCHECK(hypotheses_value); | 99 DCHECK(hypotheses_value); |
| 100 if (!hypotheses_value->IsType(Value::TYPE_LIST)) { | 100 if (!hypotheses_value->IsType(Value::TYPE_LIST)) { |
| 101 VLOG(1) << "ParseServerResponse: Unexpected hypotheses type " | 101 VLOG(1) << "ParseServerResponse: Unexpected hypotheses type " |
| 102 << hypotheses_value->GetType(); | 102 << hypotheses_value->GetType(); |
| 103 return false; | 103 return false; |
| 104 } | 104 } |
| 105 | 105 |
| 106 const ListValue* hypotheses_list = static_cast<ListValue*>(hypotheses_value); | 106 const ListValue* hypotheses_list = |
| 107 static_cast<const ListValue*>(hypotheses_value); |
| 107 | 108 |
| 108 // For now we support only single shot recognition, so we are giving only a | 109 // For now we support only single shot recognition, so we are giving only a |
| 109 // final result, consisting of one fragment (with one or more hypotheses). | 110 // final result, consisting of one fragment (with one or more hypotheses). |
| 110 size_t index = 0; | 111 size_t index = 0; |
| 111 for (; index < hypotheses_list->GetSize(); ++index) { | 112 for (; index < hypotheses_list->GetSize(); ++index) { |
| 112 Value* hypothesis = NULL; | 113 Value* hypothesis = NULL; |
| 113 if (!hypotheses_list->Get(index, &hypothesis)) { | 114 if (!hypotheses_list->Get(index, &hypothesis)) { |
| 114 LOG(WARNING) << "ParseServerResponse: Unable to read hypothesis value."; | 115 LOG(WARNING) << "ParseServerResponse: Unable to read hypothesis value."; |
| 115 break; | 116 break; |
| 116 } | 117 } |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { | 284 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { |
| 284 return url_fetcher_ != NULL; | 285 return url_fetcher_ != NULL; |
| 285 } | 286 } |
| 286 | 287 |
| 287 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { | 288 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { |
| 288 return kAudioPacketIntervalMs; | 289 return kAudioPacketIntervalMs; |
| 289 } | 290 } |
| 290 | 291 |
| 291 } // namespace speech | 292 } // namespace speech |
| OLD | NEW |