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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 DCHECK(!url_fetcher_.get()); | 165 DCHECK(!url_fetcher_.get()); |
165 std::string lang_param = config_.language; | 166 std::string lang_param = config_.language; |
166 | 167 |
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 |
no longer working on chromium
2013/12/30 12:35:15
remove this TODO if your CL has addressed it.
Lei Zhang
2014/01/08 22:44:25
nay
| |
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 std::string accepted_language_list; |
179 if (request_context->http_user_agent_settings()) { | |
180 accepted_language_list = | |
181 request_context->http_user_agent_settings()->GetAcceptLanguage(); | |
182 } | |
178 size_t separator = accepted_language_list.find_first_of(",;"); | 183 size_t separator = accepted_language_list.find_first_of(",;"); |
179 lang_param = accepted_language_list.substr(0, separator); | 184 lang_param = accepted_language_list.substr(0, separator); |
no longer working on chromium
2013/12/30 12:35:15
move these two lines into the if case, and also mo
no longer working on chromium
2013/12/30 12:35:15
how about checking if (separator != std::string::n
Lei Zhang
2014/01/08 22:44:25
Done.
Lei Zhang
2014/01/08 22:44:25
I see this deviates from google_streaming_remote_e
| |
180 } | 185 } |
181 | 186 |
182 if (lang_param.empty()) | 187 if (lang_param.empty()) |
183 lang_param = "en-US"; | 188 lang_param = "en-US"; |
184 | 189 |
185 std::vector<std::string> parts; | 190 std::vector<std::string> parts; |
186 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true)); | 191 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true)); |
187 | 192 |
188 if (!config_.grammars.empty()) { | 193 if (!config_.grammars.empty()) { |
189 DCHECK_EQ(config_.grammars.size(), 1U); | 194 DCHECK_EQ(config_.grammars.size(), 1U); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 | 291 |
287 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { | 292 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { |
288 return url_fetcher_ != NULL; | 293 return url_fetcher_ != NULL; |
289 } | 294 } |
290 | 295 |
291 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { | 296 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { |
292 return kAudioPacketIntervalMs; | 297 return kAudioPacketIntervalMs; |
293 } | 298 } |
294 | 299 |
295 } // namespace content | 300 } // namespace content |
OLD | NEW |