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

Side by Side Diff: content/browser/speech/google_streaming_remote_engine.cc

Issue 189603005: Remove the --speech-service-key command line flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove GetAPIKey method Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | content/public/common/content_switches.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_streaming_remote_engine.h" 5 #include "content/browser/speech/google_streaming_remote_engine.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/rand_util.h" 10 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "content/browser/speech/audio_buffer.h" 15 #include "content/browser/speech/audio_buffer.h"
17 #include "content/browser/speech/proto/google_streaming_api.pb.h" 16 #include "content/browser/speech/proto/google_streaming_api.pb.h"
18 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
19 #include "content/public/common/speech_recognition_error.h" 18 #include "content/public/common/speech_recognition_error.h"
20 #include "content/public/common/speech_recognition_result.h" 19 #include "content/public/common/speech_recognition_result.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 const proto::SpeechRecognitionAlternative& alt = 61 const proto::SpeechRecognitionAlternative& alt =
63 res.alternative(j); 62 res.alternative(j);
64 if (alt.has_confidence()) 63 if (alt.has_confidence())
65 DVLOG(1) << " CONFIDENCE:\t" << alt.confidence(); 64 DVLOG(1) << " CONFIDENCE:\t" << alt.confidence();
66 if (alt.has_transcript()) 65 if (alt.has_transcript())
67 DVLOG(1) << " TRANSCRIPT:\t" << alt.transcript(); 66 DVLOG(1) << " TRANSCRIPT:\t" << alt.transcript();
68 } 67 }
69 } 68 }
70 } 69 }
71 70
72 std::string GetAPIKey() {
73 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
74 if (command_line.HasSwitch(switches::kSpeechRecognitionWebserviceKey)) {
75 DVLOG(1) << "GetAPIKey() used key from command-line.";
76 return command_line.GetSwitchValueASCII(
77 switches::kSpeechRecognitionWebserviceKey);
78 }
79
80 std::string api_key = google_apis::GetAPIKey();
81 if (api_key.empty())
82 DVLOG(1) << "GetAPIKey() returned empty string!";
83
84 return api_key;
85 }
86
87 } // namespace 71 } // namespace
88 72
89 const int GoogleStreamingRemoteEngine::kAudioPacketIntervalMs = 100; 73 const int GoogleStreamingRemoteEngine::kAudioPacketIntervalMs = 100;
90 const int GoogleStreamingRemoteEngine::kUpstreamUrlFetcherIdForTesting = 0; 74 const int GoogleStreamingRemoteEngine::kUpstreamUrlFetcherIdForTesting = 0;
91 const int GoogleStreamingRemoteEngine::kDownstreamUrlFetcherIdForTesting = 1; 75 const int GoogleStreamingRemoteEngine::kDownstreamUrlFetcherIdForTesting = 1;
92 const int GoogleStreamingRemoteEngine::kWebserviceStatusNoError = 0; 76 const int GoogleStreamingRemoteEngine::kWebserviceStatusNoError = 0;
93 const int GoogleStreamingRemoteEngine::kWebserviceStatusErrorNoMatch = 5; 77 const int GoogleStreamingRemoteEngine::kWebserviceStatusErrorNoMatch = 5;
94 78
95 GoogleStreamingRemoteEngine::GoogleStreamingRemoteEngine( 79 GoogleStreamingRemoteEngine::GoogleStreamingRemoteEngine(
96 net::URLRequestContextGetter* context) 80 net::URLRequestContextGetter* context)
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 294
311 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, 295 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec,
312 config_.audio_sample_rate, 296 config_.audio_sample_rate,
313 config_.audio_num_bits_per_sample)); 297 config_.audio_num_bits_per_sample));
314 DCHECK(encoder_.get()); 298 DCHECK(encoder_.get());
315 const std::string request_key = GenerateRequestKey(); 299 const std::string request_key = GenerateRequestKey();
316 300
317 // Setup downstream fetcher. 301 // Setup downstream fetcher.
318 std::vector<std::string> downstream_args; 302 std::vector<std::string> downstream_args;
319 downstream_args.push_back( 303 downstream_args.push_back(
320 "key=" + net::EscapeQueryParamValue(GetAPIKey(), true)); 304 "key=" + net::EscapeQueryParamValue(google_apis::GetAPIKey(), true));
321 downstream_args.push_back("pair=" + request_key); 305 downstream_args.push_back("pair=" + request_key);
322 downstream_args.push_back("output=pb"); 306 downstream_args.push_back("output=pb");
323 GURL downstream_url(std::string(kWebServiceBaseUrl) + 307 GURL downstream_url(std::string(kWebServiceBaseUrl) +
324 std::string(kDownstreamUrl) + 308 std::string(kDownstreamUrl) +
325 JoinString(downstream_args, '&')); 309 JoinString(downstream_args, '&'));
326 310
327 downstream_fetcher_.reset(URLFetcher::Create( 311 downstream_fetcher_.reset(URLFetcher::Create(
328 kDownstreamUrlFetcherIdForTesting, downstream_url, URLFetcher::GET, 312 kDownstreamUrlFetcherIdForTesting, downstream_url, URLFetcher::GET,
329 this)); 313 this));
330 downstream_fetcher_->SetRequestContext(url_context_.get()); 314 downstream_fetcher_->SetRequestContext(url_context_.get());
331 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | 315 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES |
332 net::LOAD_DO_NOT_SEND_COOKIES | 316 net::LOAD_DO_NOT_SEND_COOKIES |
333 net::LOAD_DO_NOT_SEND_AUTH_DATA); 317 net::LOAD_DO_NOT_SEND_AUTH_DATA);
334 downstream_fetcher_->Start(); 318 downstream_fetcher_->Start();
335 319
336 // Setup upstream fetcher. 320 // Setup upstream fetcher.
337 // TODO(hans): Support for user-selected grammars. 321 // TODO(hans): Support for user-selected grammars.
338 std::vector<std::string> upstream_args; 322 std::vector<std::string> upstream_args;
339 upstream_args.push_back("key=" + 323 upstream_args.push_back("key=" +
340 net::EscapeQueryParamValue(GetAPIKey(), true)); 324 net::EscapeQueryParamValue(google_apis::GetAPIKey(), true));
341 upstream_args.push_back("pair=" + request_key); 325 upstream_args.push_back("pair=" + request_key);
342 upstream_args.push_back("output=pb"); 326 upstream_args.push_back("output=pb");
343 upstream_args.push_back( 327 upstream_args.push_back(
344 "lang=" + net::EscapeQueryParamValue(GetAcceptedLanguages(), true)); 328 "lang=" + net::EscapeQueryParamValue(GetAcceptedLanguages(), true));
345 upstream_args.push_back( 329 upstream_args.push_back(
346 config_.filter_profanities ? "pFilter=2" : "pFilter=0"); 330 config_.filter_profanities ? "pFilter=2" : "pFilter=0");
347 if (config_.max_hypotheses > 0U) { 331 if (config_.max_hypotheses > 0U) {
348 int max_alternatives = std::min(kMaxMaxAlternatives, 332 int max_alternatives = std::min(kMaxMaxAlternatives,
349 config_.max_hypotheses); 333 config_.max_hypotheses);
350 upstream_args.push_back("maxAlternatives=" + 334 upstream_args.push_back("maxAlternatives=" +
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 } 574 }
591 575
592 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 576 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
593 : event(event_value) { 577 : event(event_value) {
594 } 578 }
595 579
596 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { 580 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() {
597 } 581 }
598 582
599 } // namespace content 583 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/public/common/content_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698