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_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" | 10 #include "base/command_line.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 using content::BrowserThread; | 29 using content::BrowserThread; |
30 using content::SpeechRecognitionError; | 30 using content::SpeechRecognitionError; |
31 using content::SpeechRecognitionErrorCode; | 31 using content::SpeechRecognitionErrorCode; |
32 using content::SpeechRecognitionHypothesis; | 32 using content::SpeechRecognitionHypothesis; |
33 using content::SpeechRecognitionResult; | 33 using content::SpeechRecognitionResult; |
34 using net::URLFetcher; | 34 using net::URLFetcher; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // TODO(primiano) This shouldn't be a const, rather it should be taken from | |
39 // maxNBest property (which is not yet implemented in WebKit). | |
40 const int kMaxResults = 5; | |
41 const char kDownstreamUrl[] = "/down?"; | 38 const char kDownstreamUrl[] = "/down?"; |
42 const char kUpstreamUrl[] = "/up?"; | 39 const char kUpstreamUrl[] = "/up?"; |
43 const speech::AudioEncoder::Codec kDefaultAudioCodec = | 40 const speech::AudioEncoder::Codec kDefaultAudioCodec = |
44 speech::AudioEncoder::CODEC_FLAC; | 41 speech::AudioEncoder::CODEC_FLAC; |
45 | 42 |
46 // TODO(primiano) /////////// Remove this after debug stage. ///////////////// | 43 // TODO(primiano) /////////// Remove this after debug stage. ///////////////// |
47 void DumpResponse(const std::string& response) { | 44 void DumpResponse(const std::string& response) { |
48 bool parse_ok; | 45 bool parse_ok; |
49 speech::HttpStreamingResult res; | 46 speech::HttpStreamingResult res; |
50 parse_ok = res.ParseFromString(response); | 47 parse_ok = res.ParseFromString(response); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, | 312 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, |
316 config_.audio_sample_rate, | 313 config_.audio_sample_rate, |
317 config_.audio_num_bits_per_sample)); | 314 config_.audio_num_bits_per_sample)); |
318 DCHECK(encoder_.get()); | 315 DCHECK(encoder_.get()); |
319 const std::string request_key = GenerateRequestKey(); | 316 const std::string request_key = GenerateRequestKey(); |
320 | 317 |
321 // Setup downstream fetcher. | 318 // Setup downstream fetcher. |
322 std::vector<std::string> downstream_args; | 319 std::vector<std::string> downstream_args; |
323 downstream_args.push_back("sky=" + GetWebserviceKey()); | 320 downstream_args.push_back("sky=" + GetWebserviceKey()); |
324 downstream_args.push_back("pair=" + request_key); | 321 downstream_args.push_back("pair=" + request_key); |
325 downstream_args.push_back("maxresults=" + base::IntToString(kMaxResults)); | |
326 | |
327 GURL downstream_url(GetWebserviceBaseURL() + std::string(kDownstreamUrl) + | 322 GURL downstream_url(GetWebserviceBaseURL() + std::string(kDownstreamUrl) + |
328 JoinString(downstream_args, '&')); | 323 JoinString(downstream_args, '&')); |
329 // TODO(primiano) /////////// Remove this after debug stage. ///////////// | 324 // TODO(primiano) /////////// Remove this after debug stage. ///////////// |
330 DVLOG(1) << "Opening downstream: " + downstream_url.PathForRequest(); | 325 DVLOG(1) << "Opening downstream: " + downstream_url.PathForRequest(); |
331 | 326 |
332 downstream_fetcher_.reset(URLFetcher::Create( | 327 downstream_fetcher_.reset(URLFetcher::Create( |
333 kDownstreamUrlFetcherIdForTests, downstream_url, URLFetcher::GET, this)); | 328 kDownstreamUrlFetcherIdForTests, downstream_url, URLFetcher::GET, this)); |
334 downstream_fetcher_->SetRequestContext(url_context_); | 329 downstream_fetcher_->SetRequestContext(url_context_); |
335 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 330 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
336 net::LOAD_DO_NOT_SEND_COOKIES | | 331 net::LOAD_DO_NOT_SEND_COOKIES | |
337 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 332 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
338 downstream_fetcher_->Start(); | 333 downstream_fetcher_->Start(); |
339 | 334 |
340 // Setup upstream fetcher. | 335 // Setup upstream fetcher. |
341 // TODO(primiano) Handle config_.grammar array when it will be implemented by | 336 // TODO(primiano) Handle config_.grammar array when it will be implemented by |
342 // the speech recognition webservice. | 337 // the speech recognition webservice. |
343 std::vector<std::string> upstream_args; | 338 std::vector<std::string> upstream_args; |
344 upstream_args.push_back("sky=" + GetWebserviceKey()); | 339 upstream_args.push_back("sky=" + GetWebserviceKey()); |
345 upstream_args.push_back("pair=" + request_key); | 340 upstream_args.push_back("pair=" + request_key); |
346 upstream_args.push_back( | 341 upstream_args.push_back( |
347 "lang=" + net::EscapeQueryParamValue(GetAcceptedLanguages(), true)); | 342 "lang=" + net::EscapeQueryParamValue(GetAcceptedLanguages(), true)); |
348 upstream_args.push_back( | 343 upstream_args.push_back( |
349 config_.filter_profanities ? "pfilter=2" : "pfilter=0"); | 344 config_.filter_profanities ? "pfilter=2" : "pfilter=0"); |
350 upstream_args.push_back("maxresults=" + base::IntToString(kMaxResults)); | 345 if (config_.max_hypotheses > 0U) { |
| 346 upstream_args.push_back("maxresults=" + |
| 347 base::UintToString(config_.max_hypotheses)); |
| 348 } |
| 349 // TODO(primiano) What is this client= parameter? Check with speech team. |
351 upstream_args.push_back("client=myapp.mycompany.com"); | 350 upstream_args.push_back("client=myapp.mycompany.com"); |
352 // TODO(primiano) Can we remove this feature sending audio HW information? | |
353 if (!config_.hardware_info.empty()) { | 351 if (!config_.hardware_info.empty()) { |
354 upstream_args.push_back( | 352 upstream_args.push_back( |
355 "xhw=" + net::EscapeQueryParamValue(config_.hardware_info, true)); | 353 "xhw=" + net::EscapeQueryParamValue(config_.hardware_info, true)); |
356 } | 354 } |
357 | 355 |
358 GURL upstream_url(GetWebserviceBaseURL() + std::string(kUpstreamUrl) + | 356 GURL upstream_url(GetWebserviceBaseURL() + std::string(kUpstreamUrl) + |
359 JoinString(upstream_args, '&')); | 357 JoinString(upstream_args, '&')); |
360 | 358 |
361 // TODO(primiano) /////////// Remove this after debug stage. ///////////////// | 359 // TODO(primiano) /////////// Remove this after debug stage. ///////////////// |
362 DVLOG(1) << "Opening upstream: " + upstream_url.PathForRequest(); | 360 DVLOG(1) << "Opening upstream: " + upstream_url.PathForRequest(); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 } | 577 } |
580 | 578 |
581 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 579 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
582 : event(event_value) { | 580 : event(event_value) { |
583 } | 581 } |
584 | 582 |
585 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { | 583 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { |
586 } | 584 } |
587 | 585 |
588 } // namespace speech | 586 } // namespace speech |
OLD | NEW |