| 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" |
| 11 #include "base/string_util.h" | 11 #include "base/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 "net/base/escape.h" | 17 #include "net/base/escape.h" |
| 17 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 18 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| 19 #include "net/url_request/url_request_context.h" | 20 #include "net/url_request/url_request_context.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
| 21 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| 22 | 23 |
| 23 using content::SpeechRecognitionError; | 24 using content::SpeechRecognitionError; |
| 24 using content::SpeechRecognitionHypothesis; | 25 using content::SpeechRecognitionHypothesis; |
| 25 using content::SpeechRecognitionResult; | 26 using content::SpeechRecognitionResult; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 parts.push_back("lm=" + net::EscapeQueryParamValue(config_.grammars[0].url, | 193 parts.push_back("lm=" + net::EscapeQueryParamValue(config_.grammars[0].url, |
| 193 true)); | 194 true)); |
| 194 } | 195 } |
| 195 | 196 |
| 196 if (!config_.hardware_info.empty()) | 197 if (!config_.hardware_info.empty()) |
| 197 parts.push_back("xhw=" + net::EscapeQueryParamValue(config_.hardware_info, | 198 parts.push_back("xhw=" + net::EscapeQueryParamValue(config_.hardware_info, |
| 198 true)); | 199 true)); |
| 199 parts.push_back("maxresults=" + base::UintToString(config_.max_hypotheses)); | 200 parts.push_back("maxresults=" + base::UintToString(config_.max_hypotheses)); |
| 200 parts.push_back(config_.filter_profanities ? "pfilter=2" : "pfilter=0"); | 201 parts.push_back(config_.filter_profanities ? "pfilter=2" : "pfilter=0"); |
| 201 | 202 |
| 203 std::string api_key = google_apis::GetAPIKey(); |
| 204 parts.push_back("key=" + net::EscapeQueryParamValue(api_key, true)); |
| 205 |
| 202 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); | 206 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); |
| 203 | 207 |
| 204 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, | 208 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, |
| 205 config_.audio_sample_rate, | 209 config_.audio_sample_rate, |
| 206 config_.audio_num_bits_per_sample)); | 210 config_.audio_num_bits_per_sample)); |
| 207 DCHECK(encoder_.get()); | 211 DCHECK(encoder_.get()); |
| 208 url_fetcher_.reset(net::URLFetcher::Create(url_fetcher_id_for_tests, | 212 url_fetcher_.reset(net::URLFetcher::Create(url_fetcher_id_for_tests, |
| 209 url, | 213 url, |
| 210 net::URLFetcher::POST, | 214 net::URLFetcher::POST, |
| 211 this)); | 215 this)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 287 |
| 284 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { | 288 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { |
| 285 return url_fetcher_ != NULL; | 289 return url_fetcher_ != NULL; |
| 286 } | 290 } |
| 287 | 291 |
| 288 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { | 292 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { |
| 289 return kAudioPacketIntervalMs; | 293 return kAudioPacketIntervalMs; |
| 290 } | 294 } |
| 291 | 295 |
| 292 } // namespace speech | 296 } // namespace speech |
| OLD | NEW |