Chromium Code Reviews| 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/speech_recognition_engine.h" | 5 #include "content/browser/speech/speech_recognition_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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "content/browser/speech/audio_buffer.h" | 17 #include "content/browser/speech/audio_buffer.h" |
| 18 #include "content/browser/speech/proto/google_streaming_api.pb.h" | 18 #include "content/browser/speech/proto/google_streaming_api.pb.h" |
| 19 #include "content/public/common/speech_recognition_error.h" | 19 #include "content/public/common/speech_recognition_error.h" |
| 20 #include "content/public/common/speech_recognition_result.h" | 20 #include "content/public/common/speech_recognition_result.h" |
| 21 #include "google_apis/google_api_keys.h" | 21 #include "google_apis/google_api_keys.h" |
| 22 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 24 #include "net/traffic_annotation/network_traffic_annotation.h" | |
| 24 #include "net/url_request/http_user_agent_settings.h" | 25 #include "net/url_request/http_user_agent_settings.h" |
| 25 #include "net/url_request/url_fetcher.h" | 26 #include "net/url_request/url_fetcher.h" |
| 26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 27 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 28 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 29 | 30 |
| 30 using net::URLFetcher; | 31 using net::URLFetcher; |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 namespace { | 34 namespace { |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 // Setup downstream fetcher. | 331 // Setup downstream fetcher. |
| 331 std::vector<std::string> downstream_args; | 332 std::vector<std::string> downstream_args; |
| 332 downstream_args.push_back( | 333 downstream_args.push_back( |
| 333 "key=" + net::EscapeQueryParamValue(google_apis::GetAPIKey(), true)); | 334 "key=" + net::EscapeQueryParamValue(google_apis::GetAPIKey(), true)); |
| 334 downstream_args.push_back("pair=" + request_key); | 335 downstream_args.push_back("pair=" + request_key); |
| 335 downstream_args.push_back("output=pb"); | 336 downstream_args.push_back("output=pb"); |
| 336 GURL downstream_url(std::string(kWebServiceBaseUrl) + | 337 GURL downstream_url(std::string(kWebServiceBaseUrl) + |
| 337 std::string(kDownstreamUrl) + | 338 std::string(kDownstreamUrl) + |
| 338 base::JoinString(downstream_args, "&")); | 339 base::JoinString(downstream_args, "&")); |
| 339 | 340 |
| 340 downstream_fetcher_ = URLFetcher::Create( | 341 net::NetworkTrafficAnnotationTag downstream_traffic_annotation = |
| 341 kDownstreamUrlFetcherIdForTesting, downstream_url, URLFetcher::GET, this); | 342 net::DefineNetworkTrafficAnnotation("speech_recognition_downstream", R"( |
| 343 semantics { | |
| 344 sender: "Speech Recognition" | |
| 345 description: | |
| 346 "Chrome provides translation from speech audio recorded with a " | |
| 347 "microphone to text, by using the Google speech recognition web " | |
| 348 "service. Audio is sent to Google's servers and text is returned." | |
| 349 trigger: | |
| 350 "The user chooses to start the recognition by clicking the " | |
| 351 "microphone icon in the Google search field." | |
| 352 data: "Audio recorded with the microphone." | |
|
Henrik Grunell
2017/05/09 09:03:30
This only gets text data, afaik it only sends a re
Ramin Halavati
2017/05/09 09:24:18
You mean this request just sends the id to initial
Henrik Grunell
2017/05/11 07:14:08
A unique id is generated for a speech recognition
Ramin Halavati
2017/05/11 07:21:09
Done.
| |
| 353 destination: GOOGLE_OWNED_SERVICE | |
| 354 } | |
| 355 policy { | |
| 356 cookies_allowed: false | |
| 357 setting: | |
| 358 "The user must allow the browser to access the microphone in a " | |
| 359 "popup notification. This is set per site (hostname pattern). In " | |
| 360 "the content settings, microphone access can be turned off for all " | |
| 361 "sites and site specific settings can be changed." | |
| 362 policy_exception_justification: "Not implemented." | |
| 363 })"); | |
| 364 downstream_fetcher_ = | |
| 365 URLFetcher::Create(kDownstreamUrlFetcherIdForTesting, downstream_url, | |
| 366 URLFetcher::GET, this, downstream_traffic_annotation); | |
| 342 downstream_fetcher_->SetRequestContext(url_context_.get()); | 367 downstream_fetcher_->SetRequestContext(url_context_.get()); |
| 343 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 368 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 344 net::LOAD_DO_NOT_SEND_COOKIES | | 369 net::LOAD_DO_NOT_SEND_COOKIES | |
| 345 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 370 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 346 downstream_fetcher_->Start(); | 371 downstream_fetcher_->Start(); |
| 347 | 372 |
| 348 // Setup upstream fetcher. | 373 // Setup upstream fetcher. |
| 349 // TODO(hans): Support for user-selected grammars. | 374 // TODO(hans): Support for user-selected grammars. |
| 350 std::vector<std::string> upstream_args; | 375 std::vector<std::string> upstream_args; |
| 351 upstream_args.push_back("key=" + | 376 upstream_args.push_back("key=" + |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 if (preamble_encoder_) | 411 if (preamble_encoder_) |
| 387 audio_format = preamble_encoder_->GetMimeType() + ","; | 412 audio_format = preamble_encoder_->GetMimeType() + ","; |
| 388 audio_format += encoder_->GetMimeType(); | 413 audio_format += encoder_->GetMimeType(); |
| 389 upstream_args.push_back( | 414 upstream_args.push_back( |
| 390 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true)); | 415 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true)); |
| 391 } | 416 } |
| 392 GURL upstream_url(std::string(kWebServiceBaseUrl) + | 417 GURL upstream_url(std::string(kWebServiceBaseUrl) + |
| 393 std::string(kUpstreamUrl) + | 418 std::string(kUpstreamUrl) + |
| 394 base::JoinString(upstream_args, "&")); | 419 base::JoinString(upstream_args, "&")); |
| 395 | 420 |
| 396 upstream_fetcher_ = URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, | 421 net::NetworkTrafficAnnotationTag upstream_traffic_annotation = |
| 397 upstream_url, URLFetcher::POST, this); | 422 net::DefineNetworkTrafficAnnotation("speech_recognition_upstream", R"( |
| 423 semantics { | |
| 424 sender: "Speech Recognition" | |
| 425 description: | |
| 426 "Chrome provides translation from speech audio recorded with a " | |
| 427 "microphone to text, by using the Google speech recognition web " | |
| 428 "service. Audio is sent to Google's servers and text is returned." | |
|
Henrik Grunell
2017/05/09 09:03:30
Change to "Audio is sent to Google's servers (upst
Ramin Halavati
2017/05/09 09:24:18
We are working on a next version of annotation fun
Henrik Grunell
2017/05/11 07:14:08
Acknowledged.
| |
| 429 trigger: | |
| 430 "The user chooses to start the recognition by clicking the " | |
| 431 "microphone icon in the Google search field." | |
| 432 data: "Audio recorded with the microphone." | |
| 433 destination: GOOGLE_OWNED_SERVICE | |
| 434 } | |
| 435 policy { | |
| 436 cookies_allowed: false | |
| 437 setting: | |
| 438 "The user must allow the browser to access the microphone in a " | |
| 439 "popup notification. This is set per site (hostname pattern). In " | |
| 440 "the content settings, microphone access can be turned off for all " | |
| 441 "sites and site specific settings can be changed." | |
| 442 policy_exception_justification: "Not implemented." | |
| 443 })"); | |
| 444 upstream_fetcher_ = | |
| 445 URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, upstream_url, | |
| 446 URLFetcher::POST, this, upstream_traffic_annotation); | |
| 398 if (use_framed_post_data_) | 447 if (use_framed_post_data_) |
| 399 upstream_fetcher_->SetChunkedUpload("application/octet-stream"); | 448 upstream_fetcher_->SetChunkedUpload("application/octet-stream"); |
| 400 else | 449 else |
| 401 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType()); | 450 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType()); |
| 402 upstream_fetcher_->SetRequestContext(url_context_.get()); | 451 upstream_fetcher_->SetRequestContext(url_context_.get()); |
| 403 upstream_fetcher_->SetReferrer(config_.origin_url); | 452 upstream_fetcher_->SetReferrer(config_.origin_url); |
| 404 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 453 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
| 405 net::LOAD_DO_NOT_SEND_COOKIES | | 454 net::LOAD_DO_NOT_SEND_COOKIES | |
| 406 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 455 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 407 upstream_fetcher_->Start(); | 456 upstream_fetcher_->Start(); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 } | 692 } |
| 644 | 693 |
| 645 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 694 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
| 646 : event(event_value) { | 695 : event(event_value) { |
| 647 } | 696 } |
| 648 | 697 |
| 649 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { | 698 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { |
| 650 } | 699 } |
| 651 | 700 |
| 652 } // namespace content | 701 } // namespace content |
| OLD | NEW |