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 = |
Henrik Grunell
2017/05/09 08:27:11
Oh, I wrote the upstream text here. Please change
Ramin Halavati
2017/05/09 08:37:18
Done, I will copy it here to make it easier for ne
| |
341 kDownstreamUrlFetcherIdForTesting, downstream_url, URLFetcher::GET, this); | 342 net::DefineNetworkTrafficAnnotation("...", R"( |
Henrik Grunell
2017/05/09 08:27:11
"speech_recognition"
Ramin Halavati
2017/05/09 08:37:18
Done.
| |
343 semantics { | |
344 sender: "..." | |
Henrik Grunell
2017/05/09 08:27:11
"Speech Recognition"
Ramin Halavati
2017/05/09 08:37:17
Done.
| |
345 description: "..." | |
Henrik Grunell
2017/05/09 08:27:11
"Chromium provides translation from speech audio r
Ramin Halavati
2017/05/09 08:37:18
Done.
| |
346 trigger: "..." | |
Henrik Grunell
2017/05/09 08:27:11
This needs to be expanded and clarified.
Henrik Grunell
2017/05/09 08:27:11
"The user chooses to start the recognition by clic
| |
347 data: "..." | |
Henrik Grunell
2017/05/09 08:27:11
"Audio recorded with a microphone."
Henrik Grunell
2017/05/09 08:27:11
How much data is recorded?
| |
348 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
Henrik Grunell
2017/05/09 08:27:11
GOOGLE_OWNED_SERVICE
Ramin Halavati
2017/05/09 08:37:18
Done.
| |
349 } | |
350 policy { | |
351 cookies_allowed: false | |
Henrik Grunell
2017/05/09 08:27:11
I don't know, but guess false.
Tommi?
Ramin Halavati
2017/05/09 08:37:17
They are disabled in line 365.
| |
352 setting: "..." | |
Henrik Grunell
2017/05/09 08:27:12
"The user must allow the browser to access the mic
Ramin Halavati
2017/05/09 08:37:17
Done.
| |
353 chrome_policy { | |
354 [POLICY_NAME] { | |
355 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
356 [POLICY_NAME]: ... //(value to disable it) | |
357 } | |
358 } | |
359 policy_exception_justification: "..." | |
Henrik Grunell
2017/05/09 08:27:11
No policy is implemented.
Ramin Halavati
2017/05/09 08:37:18
Done.
| |
360 })"); | |
361 downstream_fetcher_ = | |
362 URLFetcher::Create(kDownstreamUrlFetcherIdForTesting, downstream_url, | |
363 URLFetcher::GET, this, downstream_traffic_annotation); | |
342 downstream_fetcher_->SetRequestContext(url_context_.get()); | 364 downstream_fetcher_->SetRequestContext(url_context_.get()); |
343 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 365 downstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
344 net::LOAD_DO_NOT_SEND_COOKIES | | 366 net::LOAD_DO_NOT_SEND_COOKIES | |
345 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 367 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
346 downstream_fetcher_->Start(); | 368 downstream_fetcher_->Start(); |
347 | 369 |
348 // Setup upstream fetcher. | 370 // Setup upstream fetcher. |
349 // TODO(hans): Support for user-selected grammars. | 371 // TODO(hans): Support for user-selected grammars. |
350 std::vector<std::string> upstream_args; | 372 std::vector<std::string> upstream_args; |
351 upstream_args.push_back("key=" + | 373 upstream_args.push_back("key=" + |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 if (preamble_encoder_) | 408 if (preamble_encoder_) |
387 audio_format = preamble_encoder_->GetMimeType() + ","; | 409 audio_format = preamble_encoder_->GetMimeType() + ","; |
388 audio_format += encoder_->GetMimeType(); | 410 audio_format += encoder_->GetMimeType(); |
389 upstream_args.push_back( | 411 upstream_args.push_back( |
390 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true)); | 412 "audioFormat=" + net::EscapeQueryParamValue(audio_format, true)); |
391 } | 413 } |
392 GURL upstream_url(std::string(kWebServiceBaseUrl) + | 414 GURL upstream_url(std::string(kWebServiceBaseUrl) + |
393 std::string(kUpstreamUrl) + | 415 std::string(kUpstreamUrl) + |
394 base::JoinString(upstream_args, "&")); | 416 base::JoinString(upstream_args, "&")); |
395 | 417 |
396 upstream_fetcher_ = URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, | 418 net::NetworkTrafficAnnotationTag upstream_traffic_annotation = |
397 upstream_url, URLFetcher::POST, this); | 419 net::DefineNetworkTrafficAnnotation("...", R"( |
420 semantics { | |
421 sender: "..." | |
422 description: "..." | |
423 trigger: "..." | |
424 data: "..." | |
425 destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER | |
426 } | |
427 policy { | |
428 cookies_allowed: false | |
429 setting: "..." | |
430 chrome_policy { | |
431 [POLICY_NAME] { | |
432 policy_options {mode: MANDATORY/RECOMMENDED/UNSET} | |
433 [POLICY_NAME]: ... //(value to disable it) | |
434 } | |
435 } | |
436 policy_exception_justification: "..." | |
437 })"); | |
438 upstream_fetcher_ = | |
439 URLFetcher::Create(kUpstreamUrlFetcherIdForTesting, upstream_url, | |
440 URLFetcher::POST, this, upstream_traffic_annotation); | |
398 if (use_framed_post_data_) | 441 if (use_framed_post_data_) |
399 upstream_fetcher_->SetChunkedUpload("application/octet-stream"); | 442 upstream_fetcher_->SetChunkedUpload("application/octet-stream"); |
400 else | 443 else |
401 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType()); | 444 upstream_fetcher_->SetChunkedUpload(encoder_->GetMimeType()); |
402 upstream_fetcher_->SetRequestContext(url_context_.get()); | 445 upstream_fetcher_->SetRequestContext(url_context_.get()); |
403 upstream_fetcher_->SetReferrer(config_.origin_url); | 446 upstream_fetcher_->SetReferrer(config_.origin_url); |
404 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | | 447 upstream_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES | |
405 net::LOAD_DO_NOT_SEND_COOKIES | | 448 net::LOAD_DO_NOT_SEND_COOKIES | |
406 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 449 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
407 upstream_fetcher_->Start(); | 450 upstream_fetcher_->Start(); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 } | 686 } |
644 | 687 |
645 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) | 688 SpeechRecognitionEngine::FSMEventArgs::FSMEventArgs(FSMEvent event_value) |
646 : event(event_value) { | 689 : event(event_value) { |
647 } | 690 } |
648 | 691 |
649 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { | 692 SpeechRecognitionEngine::FSMEventArgs::~FSMEventArgs() { |
650 } | 693 } |
651 | 694 |
652 } // namespace content | 695 } // namespace content |
OLD | NEW |