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

Unified Diff: chrome/browser/speech/tts_mac.mm

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_linux.cc ('k') | chrome/browser/speech/tts_message_filter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/speech/tts_mac.mm
diff --git a/chrome/browser/speech/tts_mac.mm b/chrome/browser/speech/tts_mac.mm
index 689effc7be91c600b7f9dda4c71ba9538c704b8e..bdb9b1cd7b72f380a158b48f37b4bc2de9c91ae2 100644
--- a/chrome/browser/speech/tts_mac.mm
+++ b/chrome/browser/speech/tts_mac.mm
@@ -63,6 +63,10 @@ class TtsPlatformImplMac : public TtsPlatformImpl {
virtual bool StopSpeaking() OVERRIDE;
+ virtual void Pause() OVERRIDE;
+
+ virtual void Resume() OVERRIDE;
+
virtual bool IsSpeaking() OVERRIDE;
virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE;
@@ -86,6 +90,8 @@ class TtsPlatformImplMac : public TtsPlatformImpl {
int utterance_id_;
std::string utterance_;
bool sent_start_event_;
+ int last_char_index_;
+ bool paused_;
friend struct DefaultSingletonTraits<TtsPlatformImplMac>;
@@ -105,6 +111,7 @@ bool TtsPlatformImplMac::Speak(
const UtteranceContinuousParameters& params) {
// TODO: convert SSML to SAPI xml. http://crbug.com/88072
utterance_ = utterance;
+ paused_ = false;
NSString* utterance_nsstring =
[NSString stringWithUTF8String:utterance_.c_str()];
@@ -165,9 +172,28 @@ bool TtsPlatformImplMac::StopSpeaking() {
[speech_synthesizer_ stopSpeaking];
speech_synthesizer_.reset(nil);
}
+ paused_ = false;
return true;
}
+void TtsPlatformImplMac::Pause() {
+ if (speech_synthesizer_.get() && utterance_id_ && !paused_) {
+ [speech_synthesizer_ pauseSpeakingAtBoundary:NSSpeechImmediateBoundary];
+ paused_ = true;
+ TtsController::GetInstance()->OnTtsEvent(
+ utterance_id_, TTS_EVENT_PAUSE, last_char_index_, "");
+ }
+}
+
+void TtsPlatformImplMac::Resume() {
+ if (speech_synthesizer_.get() && utterance_id_ && paused_) {
+ [speech_synthesizer_ continueSpeaking];
+ paused_ = false;
+ TtsController::GetInstance()->OnTtsEvent(
+ utterance_id_, TTS_EVENT_RESUME, last_char_index_, "");
+ }
+}
+
bool TtsPlatformImplMac::IsSpeaking() {
return [NSSpeechSynthesizer isAnyApplicationSpeaking];
}
@@ -223,6 +249,8 @@ void TtsPlatformImplMac::GetVoices(std::vector<VoiceData>* outVoices) {
data.events.insert(TTS_EVENT_ERROR);
data.events.insert(TTS_EVENT_CANCELLED);
data.events.insert(TTS_EVENT_INTERRUPTED);
+ data.events.insert(TTS_EVENT_PAUSE);
+ data.events.insert(TTS_EVENT_RESUME);
}
}
@@ -247,11 +275,13 @@ void TtsPlatformImplMac::OnSpeechEvent(
}
controller->OnTtsEvent(
utterance_id_, event_type, char_index, error_message);
+ last_char_index_ = char_index;
}
TtsPlatformImplMac::TtsPlatformImplMac() {
utterance_id_ = -1;
sent_start_event_ = true;
+ paused_ = false;
delegate_.reset([[ChromeTtsDelegate alloc] initWithPlatformImplMac:this]);
}
« no previous file with comments | « chrome/browser/speech/tts_linux.cc ('k') | chrome/browser/speech/tts_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698