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 (upstream) and text is " | |
349 "returned (downstream). This network request (downstream) sends an " | |
350 "id for getting the text response. Then the (upstream) request " | |
351 "sends the audio data along with the id. When the server has " | |
352 "finished processing the audio data and produced a text response, " | |
353 "it replies to this request." | |
354 trigger: | |
355 "The user chooses to start the recognition by clicking the " | |
356 "microphone icon in the Google search field." | |
357 data: "A unique random id for this speech recognition request." | |
358 destination: GOOGLE_OWNED_SERVICE | |
359 } | |
360 policy { | |
361 cookies_allowed: false | |
362 setting: | |
363 "The user must allow the browser to access the microphone in a " | |
364 "popup notification. This is set per site (hostname pattern). In " | |
msramek
2017/05/15 13:04:28
s/popup notification/permission prompt/
The words
Ramin Halavati
2017/05/15 13:48:43
Done.
| |
365 "the content settings, microphone access can be turned off for all " | |
msramek
2017/05/15 13:04:28
nit: s/content settings/content settings menu/ to
Ramin Halavati
2017/05/15 13:48:43
Done.
| |
366 "sites and site specific settings can be changed." | |
367 policy_exception_justification: "Not implemented." | |
msramek
2017/05/15 13:04:28
The microphone content setting described in "setti
Ramin Halavati
2017/05/15 13:48:43
Done.
| |
368 })"); | |
369 downstream_fetcher_ = | |
370 URLFetcher::Create(kDownstreamUrlFetcherIdForTesting, downstream_url, | |
371 URLFetcher::GET, this, downstream_traffic_annotation); | |
342 downstream_fetcher_->SetRequestContext(url_context_.get()); | 372 downstream_fetcher_->SetRequestContext(url_context_.get()); |
343 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 373 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
344 net::LOAD_DO_NOT_SEND_COOKIES | | 374 net::LOAD_DO_NOT_SEND_COOKIES | |
345 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 375 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
346 downstream_fetcher_->Start(); | 376 downstream_fetcher_->Start(); |
347 | 377 |
348 // Setup upstream fetcher. | 378 // Setup upstream fetcher. |
349 // TODO(hans): Support for user-selected grammars. | 379 // TODO(hans): Support for user-selected grammars. |
350 std::vector<std::string> upstream_args; | 380 std::vector<std::string> upstream_args; |
351 upstream_args.push_back("key=" + | 381 upstream_args.push_back("key=" + |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 if (preamble_encoder_) | 416 if (preamble_encoder_) |
387 audio_format = preamble_encoder_->GetMimeType() + ","; | 417 audio_format = preamble_encoder_->GetMimeType() + ","; |
388 audio_format += encoder_->GetMimeType(); | 418 audio_format += encoder_->GetMimeType(); |
389 upstream_args.push_back( | 419 upstream_args.push_back( |
390 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true)); | 420 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true)); |
391 } | 421 } |
392 GURL upstream_url(std::string(kWebServiceBaseUrl) + | 422 GURL upstream_url(std::string(kWebServiceBaseUrl) + |
393 std::string(kUpstreamUrl) + | 423 std::string(kUpstreamUrl) + |
394 base::JoinString(upstream_args, "&")); | 424 base::JoinString(upstream_args, "&")); |
395 | 425 |
396 upstream_fetcher_ = URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, | 426 net::NetworkTrafficAnnotationTag upstream_traffic_annotation = |
397 upstream_url, URLFetcher::POST, this); | 427 net::DefineNetworkTrafficAnnotation("speech_recognition_upstream", R"( |
428 semantics { | |
429 sender: "Speech Recognition" | |
430 description: | |
431 "Chrome provides translation from speech audio recorded with a " | |
432 "microphone to text, by using the Google speech recognition web " | |
433 "service. Audio is sent to Google's servers (upstream) and text is " | |
434 "returned (downstream)." | |
435 trigger: | |
436 "The user chooses to start the recognition by clicking the " | |
437 "microphone icon in the Google search field." | |
438 data: | |
439 "Audio recorded with the microphone, and the unique id of " | |
440 "downstream speech recognition request." | |
441 destination: GOOGLE_OWNED_SERVICE | |
442 } | |
443 policy { | |
444 cookies_allowed: false | |
445 setting: | |
446 "The user must allow the browser to access the microphone in a " | |
447 "popup notification. This is set per site (hostname pattern). In " | |
448 "the content settings, microphone access can be turned off for all " | |
449 "sites and site specific settings can be changed." | |
450 policy_exception_justification: "Not implemented." | |
451 })"); | |
452 upstream_fetcher_ = | |
453 URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, upstream_url, | |
454 URLFetcher::POST, this, upstream_traffic_annotation); | |
398 if (use_framed_post_data_) | 455 if (use_framed_post_data_) |
399 upstream_fetcher_->SetChunkedUpload("application/octet-stream"); | 456 upstream_fetcher_->SetChunkedUpload("application/octet-stream"); |
400 else | 457 else |
401 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType()); | 458 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType()); |
402 upstream_fetcher_->SetRequestContext(url_context_.get()); | 459 upstream_fetcher_->SetRequestContext(url_context_.get()); |
403 upstream_fetcher_->SetReferrer(config_.origin_url); | 460 upstream_fetcher_->SetReferrer(config_.origin_url); |
404 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 461 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
405 net::LOAD_DO_NOT_SEND_COOKIES | | 462 net::LOAD_DO_NOT_SEND_COOKIES | |
406 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 463 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
407 upstream_fetcher_->Start(); | 464 upstream_fetcher_->Start(); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 } | 700 } |
644 | 701 |
645 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 702 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
646 : event(event_value) { | 703 : event(event_value) { |
647 } | 704 } |
648 | 705 |
649 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { | 706 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { |
650 } | 707 } |
651 | 708 |
652 } // namespace content | 709 } // namespace content |
OLD | NEW |