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

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: Rebase 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
« no previous file with comments | « chrome/browser/speech/tts_controller.h ('k') | chrome/browser/speech/tts_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/speech/tts_controller.cc
diff --git a/chrome/browser/speech/tts_controller.cc b/chrome/browser/speech/tts_controller.cc
index 73b094e64930de976b4e84f578efdb64a89f8094..2ae1678d1eeeb9ed6b6bcdd832f3488502cd7a12 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,15 @@ TtsController::~TtsController() {
}
void TtsController::SpeakOrEnqueue(Utterance* utterance) {
- if (IsSpeaking() && utterance->can_enqueue()) {
+ // If we're paused and we get an utterance that can't be queued,
+ // flush the queue but stay in the paused state.
+ if (paused_ && !utterance->can_enqueue()) {
+ Stop();
+ paused_ = true;
+ return;
+ }
+
+ if (paused_ || (IsSpeaking() && utterance->can_enqueue())) {
utterance_queue_.push(utterance);
} else {
Stop();
@@ -198,6 +207,7 @@ void TtsController::SpeakNow(Utterance* utterance) {
}
void TtsController::Stop() {
+ paused_ = false;
if (current_utterance_ && !current_utterance_->extension_id().empty()) {
#if !defined(OS_ANDROID)
ExtensionTtsEngineStop(current_utterance_);
@@ -214,6 +224,32 @@ void TtsController::Stop() {
ClearUtteranceQueue(true); // Send events.
}
+void TtsController::Pause() {
+ paused_ = true;
+ if (current_utterance_ && !current_utterance_->extension_id().empty()) {
+#if !defined(OS_ANDROID)
+ ExtensionTtsEnginePause(current_utterance_);
+#endif
+ } else if (current_utterance_) {
+ GetPlatformImpl()->clear_error();
+ GetPlatformImpl()->Pause();
+ }
+}
+
+void TtsController::Resume() {
+ paused_ = false;
+ if (current_utterance_ && !current_utterance_->extension_id().empty()) {
+#if !defined(OS_ANDROID)
+ ExtensionTtsEngineResume(current_utterance_);
+#endif
+ } else if (current_utterance_) {
+ GetPlatformImpl()->clear_error();
+ GetPlatformImpl()->Resume();
+ } else {
+ SpeakNextUtterance();
+ }
+}
+
void TtsController::OnTtsEvent(int utterance_id,
TtsEventType event_type,
int char_index,
@@ -259,6 +295,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_) {
« no previous file with comments | « chrome/browser/speech/tts_controller.h ('k') | chrome/browser/speech/tts_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698