OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/speech/tts_controller_impl.h" | 5 #include "chrome/browser/speech/tts_controller_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/float_util.h" | 10 #include "base/float_util.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 int char_index, | 84 int char_index, |
85 const std::string& error_message) { | 85 const std::string& error_message) { |
86 if (char_index >= 0) | 86 if (char_index >= 0) |
87 char_index_ = char_index; | 87 char_index_ = char_index; |
88 if (IsFinalTtsEventType(event_type)) | 88 if (IsFinalTtsEventType(event_type)) |
89 finished_ = true; | 89 finished_ = true; |
90 | 90 |
91 if (event_delegate_) | 91 if (event_delegate_) |
92 event_delegate_->OnTtsEvent(this, event_type, char_index, error_message); | 92 event_delegate_->OnTtsEvent(this, event_type, char_index, error_message); |
93 if (finished_) | 93 if (finished_) |
94 event_delegate_.reset(); | 94 event_delegate_ = NULL; |
95 } | 95 } |
96 | 96 |
97 void Utterance::Finish() { | 97 void Utterance::Finish() { |
98 finished_ = true; | 98 finished_ = true; |
99 } | 99 } |
100 | 100 |
101 void Utterance::set_options(const base::Value* options) { | 101 void Utterance::set_options(const base::Value* options) { |
102 options_.reset(options->DeepCopy()); | 102 options_.reset(options->DeepCopy()); |
103 } | 103 } |
104 | 104 |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 void TtsControllerImpl::AddVoicesChangedDelegate( | 452 void TtsControllerImpl::AddVoicesChangedDelegate( |
453 VoicesChangedDelegate* delegate) { | 453 VoicesChangedDelegate* delegate) { |
454 voices_changed_delegates_.insert(delegate); | 454 voices_changed_delegates_.insert(delegate); |
455 } | 455 } |
456 | 456 |
457 void TtsControllerImpl::RemoveVoicesChangedDelegate( | 457 void TtsControllerImpl::RemoveVoicesChangedDelegate( |
458 VoicesChangedDelegate* delegate) { | 458 VoicesChangedDelegate* delegate) { |
459 voices_changed_delegates_.erase(delegate); | 459 voices_changed_delegates_.erase(delegate); |
460 } | 460 } |
461 | 461 |
462 void TtsControllerImpl::RemoveUtteranceEventDelegate( | |
463 UtteranceEventDelegate* delegate) { | |
464 // First clear any pending utterances with this delegate. | |
465 std::queue<Utterance*> old_queue = utterance_queue_; | |
466 utterance_queue_ = std::queue<Utterance*>(); | |
467 while (!old_queue.empty()) { | |
468 Utterance* utterance = old_queue.front(); | |
469 old_queue.pop(); | |
470 if (utterance->event_delegate() != delegate) | |
471 utterance_queue_.push(utterance); | |
472 else | |
473 delete utterance; | |
474 } | |
475 | |
476 if (current_utterance_ && current_utterance_->event_delegate() == delegate) { | |
477 current_utterance_->set_event_delegate(NULL); | |
478 if (current_utterance_ && !current_utterance_->extension_id().empty()) { | |
David Tseng
2014/10/31 22:33:04
Why the redundant check for current_utterance?
dmazzoni
2014/10/31 22:44:22
Fixed.
| |
479 #if !defined(OS_ANDROID) | |
David Tseng
2014/10/31 22:33:04
Can this happen? (i.e. an utterance with an extens
dmazzoni
2014/10/31 22:44:22
No. I copied this from other code where we handle
| |
480 if (tts_engine_delegate_) | |
481 tts_engine_delegate_->Stop(current_utterance_); | |
482 #endif | |
483 } else { | |
484 GetPlatformImpl()->clear_error(); | |
David Tseng
2014/10/31 22:33:04
What's the purpose of doing this?
dmazzoni
2014/10/31 22:44:22
We do this before every call to the platform TTS s
| |
485 GetPlatformImpl()->StopSpeaking(); | |
David Tseng
2014/10/31 22:33:04
Is this behavior part of the web speech spec?I'm c
dmazzoni
2014/10/31 22:44:22
See crbug.com/418806, there are concerns about a r
David Tseng
2014/11/02 19:55:44
Are there any concerns over really long utterances
| |
486 } | |
487 | |
488 FinishCurrentUtterance(); | |
489 if (!paused_) | |
490 SpeakNextUtterance(); | |
491 } | |
492 } | |
493 | |
462 void TtsControllerImpl::SetTtsEngineDelegate( | 494 void TtsControllerImpl::SetTtsEngineDelegate( |
463 TtsEngineDelegate* delegate) { | 495 TtsEngineDelegate* delegate) { |
464 tts_engine_delegate_ = delegate; | 496 tts_engine_delegate_ = delegate; |
465 } | 497 } |
466 | 498 |
467 TtsEngineDelegate* TtsControllerImpl::GetTtsEngineDelegate() { | 499 TtsEngineDelegate* TtsControllerImpl::GetTtsEngineDelegate() { |
468 return tts_engine_delegate_; | 500 return tts_engine_delegate_; |
469 } | 501 } |
OLD | NEW |