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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "content/browser/speech/audio_buffer.h" | 13 #include "content/browser/speech/audio_buffer.h" |
14 #include "content/public/common/speech_recognition_error.h" | 14 #include "content/public/common/speech_recognition_error.h" |
15 #include "content/public/common/speech_recognition_result.h" | 15 #include "content/public/common/speech_recognition_result.h" |
16 #include "google_apis/google_api_keys.h" | 16 #include "google_apis/google_api_keys.h" |
17 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
18 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 19 #include "net/url_request/http_user_agent_settings.h" |
19 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
20 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
21 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
22 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 namespace { | 26 namespace { |
26 | 27 |
27 const char* const kDefaultSpeechRecognitionUrl = | 28 const char* const kDefaultSpeechRecognitionUrl = |
28 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&"; | 29 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&"; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 if (lang_param.empty() && url_context_.get()) { | 168 if (lang_param.empty() && url_context_.get()) { |
168 // If no language is provided then we use the first from the accepted | 169 // If no language is provided then we use the first from the accepted |
169 // language list. If this list is empty then it defaults to "en-US". | 170 // language list. If this list is empty then it defaults to "en-US". |
170 // Example of the contents of this list: "es,en-GB;q=0.8", "" | 171 // Example of the contents of this list: "es,en-GB;q=0.8", "" |
171 net::URLRequestContext* request_context = | 172 net::URLRequestContext* request_context = |
172 url_context_->GetURLRequestContext(); | 173 url_context_->GetURLRequestContext(); |
173 DCHECK(request_context); | 174 DCHECK(request_context); |
174 // TODO(pauljensen): GoogleOneShotRemoteEngine should be constructed with | 175 // TODO(pauljensen): GoogleOneShotRemoteEngine should be constructed with |
175 // a reference to the HttpUserAgentSettings rather than accessing the | 176 // a reference to the HttpUserAgentSettings rather than accessing the |
176 // accept language through the URLRequestContext. | 177 // accept language through the URLRequestContext. |
177 std::string accepted_language_list = request_context->GetAcceptLanguage(); | 178 if (request_context->http_user_agent_settings()) { |
178 size_t separator = accepted_language_list.find_first_of(",;"); | 179 std::string accepted_language_list = |
179 lang_param = accepted_language_list.substr(0, separator); | 180 request_context->http_user_agent_settings()->GetAcceptLanguage(); |
| 181 size_t separator = accepted_language_list.find_first_of(",;"); |
| 182 lang_param = accepted_language_list.substr(0, separator); |
| 183 } |
180 } | 184 } |
181 | 185 |
182 if (lang_param.empty()) | 186 if (lang_param.empty()) |
183 lang_param = "en-US"; | 187 lang_param = "en-US"; |
184 | 188 |
185 std::vector<std::string> parts; | 189 std::vector<std::string> parts; |
186 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true)); | 190 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true)); |
187 | 191 |
188 if (!config_.grammars.empty()) { | 192 if (!config_.grammars.empty()) { |
189 DCHECK_EQ(config_.grammars.size(), 1U); | 193 DCHECK_EQ(config_.grammars.size(), 1U); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 | 290 |
287 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { | 291 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { |
288 return url_fetcher_ != NULL; | 292 return url_fetcher_ != NULL; |
289 } | 293 } |
290 | 294 |
291 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { | 295 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { |
292 return kAudioPacketIntervalMs; | 296 return kAudioPacketIntervalMs; |
293 } | 297 } |
294 | 298 |
295 } // namespace content | 299 } // namespace content |
OLD | NEW |