| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/big_endian.h" | 10 #include "base/big_endian.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 using net::URLFetcher; | 30 using net::URLFetcher; |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const char kWebServiceBaseUrl[] = | 35 const char kWebServiceBaseUrl[] = |
| 36 "https://www.google.com/speech-api/full-duplex/v1"; | 36 "https://www.google.com/speech-api/full-duplex/v1"; |
| 37 const char kDownstreamUrl[] = "/down?"; | 37 const char kDownstreamUrl[] = "/down?"; |
| 38 const char kUpstreamUrl[] = "/up?"; | 38 const char kUpstreamUrl[] = "/up?"; |
| 39 const AudioEncoder::Codec kDefaultAudioCodec = AudioEncoder::CODEC_FLAC; | |
| 40 | 39 |
| 41 // This matches the maximum maxAlternatives value supported by the server. | 40 // This matches the maximum maxAlternatives value supported by the server. |
| 42 const uint32 kMaxMaxAlternatives = 30; | 41 const uint32 kMaxMaxAlternatives = 30; |
| 43 | 42 |
| 44 // TODO(hans): Remove this and other logging when we don't need it anymore. | 43 // TODO(hans): Remove this and other logging when we don't need it anymore. |
| 45 void DumpResponse(const std::string& response) { | 44 void DumpResponse(const std::string& response) { |
| 46 DVLOG(1) << "------------"; | 45 DVLOG(1) << "------------"; |
| 47 proto::SpeechRecognitionEvent event; | 46 proto::SpeechRecognitionEvent event; |
| 48 if (!event.ParseFromString(response)) { | 47 if (!event.ParseFromString(response)) { |
| 49 DVLOG(1) << "Parse failed!"; | 48 DVLOG(1) << "Parse failed!"; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // ----------- Contract for all the FSM evolution functions below ------------- | 286 // ----------- Contract for all the FSM evolution functions below ------------- |
| 288 // - Are guaranteed to be executed in the same thread (IO, except for tests); | 287 // - Are guaranteed to be executed in the same thread (IO, except for tests); |
| 289 // - Are guaranteed to be not reentrant (themselves and each other); | 288 // - Are guaranteed to be not reentrant (themselves and each other); |
| 290 // - event_args members are guaranteed to be stable during the call; | 289 // - event_args members are guaranteed to be stable during the call; |
| 291 | 290 |
| 292 GoogleStreamingRemoteEngine::FSMState | 291 GoogleStreamingRemoteEngine::FSMState |
| 293 GoogleStreamingRemoteEngine::ConnectBothStreams(const FSMEventArgs&) { | 292 GoogleStreamingRemoteEngine::ConnectBothStreams(const FSMEventArgs&) { |
| 294 DCHECK(!upstream_fetcher_.get()); | 293 DCHECK(!upstream_fetcher_.get()); |
| 295 DCHECK(!downstream_fetcher_.get()); | 294 DCHECK(!downstream_fetcher_.get()); |
| 296 | 295 |
| 297 encoder_.reset(AudioEncoder::Create(kDefaultAudioCodec, | 296 encoder_.reset(AudioEncoder::Create(config_.audio_sample_rate, |
| 298 config_.audio_sample_rate, | |
| 299 config_.audio_num_bits_per_sample)); | 297 config_.audio_num_bits_per_sample)); |
| 300 DCHECK(encoder_.get()); | 298 DCHECK(encoder_.get()); |
| 301 const std::string request_key = GenerateRequestKey(); | 299 const std::string request_key = GenerateRequestKey(); |
| 302 | 300 |
| 303 // Only use the framed post data format when a preamble needs to be logged. | 301 // Only use the framed post data format when a preamble needs to be logged. |
| 304 use_framed_post_data_ = (config_.preamble && | 302 use_framed_post_data_ = (config_.preamble && |
| 305 !config_.preamble->sample_data.empty() && | 303 !config_.preamble->sample_data.empty() && |
| 306 !config_.auth_token.empty() && | 304 !config_.auth_token.empty() && |
| 307 !config_.auth_scope.empty()); | 305 !config_.auth_scope.empty()); |
| 308 if (use_framed_post_data_) { | 306 if (use_framed_post_data_) { |
| 309 preamble_encoder_.reset(AudioEncoder::Create( | 307 preamble_encoder_.reset(AudioEncoder::Create( |
| 310 kDefaultAudioCodec, | |
| 311 config_.preamble->sample_rate, | 308 config_.preamble->sample_rate, |
| 312 config_.preamble->sample_depth * 8)); | 309 config_.preamble->sample_depth * 8)); |
| 313 } | 310 } |
| 314 | 311 |
| 315 // Setup downstream fetcher. | 312 // Setup downstream fetcher. |
| 316 std::vector<std::string> downstream_args; | 313 std::vector<std::string> downstream_args; |
| 317 downstream_args.push_back( | 314 downstream_args.push_back( |
| 318 "key=" + net::EscapeQueryParamValue(google_apis::GetAPIKey(), true)); | 315 "key=" + net::EscapeQueryParamValue(google_apis::GetAPIKey(), true)); |
| 319 downstream_args.push_back("pair=" + request_key); | 316 downstream_args.push_back("pair=" + request_key); |
| 320 downstream_args.push_back("output=pb"); | 317 downstream_args.push_back("output=pb"); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 } | 624 } |
| 628 | 625 |
| 629 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 626 GoogleStreamingRemoteEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
| 630 : event(event_value) { | 627 : event(event_value) { |
| 631 } | 628 } |
| 632 | 629 |
| 633 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { | 630 GoogleStreamingRemoteEngine::FSMEventArgs::~FSMEventArgs() { |
| 634 } | 631 } |
| 635 | 632 |
| 636 } // namespace content | 633 } // namespace content |
| OLD | NEW |