Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: chrome/browser/speech/tts_controller.cc

Issue 15108002: Add Pause and Resume to Web TTS & Extension TTS APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/speech/tts_controller.cc
diff --git a/chrome/browser/speech/tts_controller.cc b/chrome/browser/speech/tts_controller.cc
index d7fb66e1e63bd4c78bd6ff20acc8081211aa6e57..0d1d131574d46b53b921ec675b9253cef29207d5 100644
--- a/chrome/browser/speech/tts_controller.cc
+++ b/chrome/browser/speech/tts_controller.cc
@@ -117,6 +117,7 @@ TtsController* TtsController::GetInstance() {
TtsController::TtsController()
: current_utterance_(NULL),
+ paused_(false),
platform_impl_(NULL) {
}
@@ -131,7 +132,7 @@ TtsController::~TtsController() {
}
void TtsController::SpeakOrEnqueue(Utterance* utterance) {
- if (IsSpeaking() && utterance->can_enqueue()) {
+ if (paused_ || (IsSpeaking() && utterance->can_enqueue())) {
David Tseng 2013/05/13 17:49:54 I don't remember why isSpeaking is needed here. It
dmazzoni 2013/05/13 19:34:38 Are you thinking about the change we made on Mac w
dmazzoni 2013/05/14 16:50:27 Got it. That won't happen because IsSpeaking check
utterance_queue_.push(utterance);
} else {
David Tseng 2013/05/13 17:49:54 What happens if we're currently paused and get a n
dmazzoni 2013/05/14 16:50:27 Done.
Stop();
@@ -196,6 +197,7 @@ void TtsController::SpeakNow(Utterance* utterance) {
}
void TtsController::Stop() {
+ paused_ = false;
if (current_utterance_ && !current_utterance_->extension_id().empty()) {
ExtensionTtsEngineStop(current_utterance_);
} else {
@@ -210,6 +212,28 @@ void TtsController::Stop() {
ClearUtteranceQueue(true); // Send events.
}
+void TtsController::Pause() {
+ paused_ = true;
+ if (current_utterance_ && !current_utterance_->extension_id().empty()) {
+ ExtensionTtsEnginePause(current_utterance_);
+ } else if (current_utterance_) {
+ GetPlatformImpl()->clear_error();
+ GetPlatformImpl()->Pause();
+ }
+}
+
+void TtsController::Resume() {
+ paused_ = false;
+ if (current_utterance_ && !current_utterance_->extension_id().empty()) {
+ ExtensionTtsEngineResume(current_utterance_);
+ } else if (current_utterance_) {
+ GetPlatformImpl()->clear_error();
+ GetPlatformImpl()->Resume();
+ } else {
+ SpeakNextUtterance();
+ }
+}
+
void TtsController::OnTtsEvent(int utterance_id,
TtsEventType event_type,
int char_index,
@@ -253,6 +277,9 @@ void TtsController::FinishCurrentUtterance() {
}
void TtsController::SpeakNextUtterance() {
+ if (paused_)
+ return;
+
// Start speaking the next utterance in the queue. Keep trying in case
// one fails but there are still more in the queue to try.
while (!utterance_queue_.empty() && !current_utterance_) {

Powered by Google App Engine
This is Rietveld 408576698