Index: chrome/browser/speech/tts_controller_impl.h |
diff --git a/chrome/browser/speech/tts_controller_impl.h b/chrome/browser/speech/tts_controller_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fbf576a34940b9a3ff69f2c5ea7a6699ad27fe73 |
--- /dev/null |
+++ b/chrome/browser/speech/tts_controller_impl.h |
@@ -0,0 +1,136 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ |
sky
2014/07/23 16:34:37
I'm surprised this file didn't show up as a copy.
mrunal
2014/07/23 17:17:06
Do u mean above header name is duplicate? or Do u
sky
2014/07/23 19:11:06
I meant that is this file is basically of a copy o
mrunal
2014/07/23 19:18:26
Got it.
|
+#define CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ |
+ |
+#include <queue> |
+#include <set> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/singleton.h" |
+#include "base/memory/weak_ptr.h" |
+#include "chrome/browser/speech/tts_controller.h" |
+#include "url/gurl.h" |
+ |
+// Singleton class that manages text-to-speech for the TTS and TTS engine |
+// extension APIs, maintaining a queue of pending utterances and keeping |
+// track of all state. |
+class TtsControllerImpl : public TtsController { |
+ public: |
+ // Get the single instance of this class. |
+ static TtsControllerImpl* GetInstance(); |
+ |
+ // Returns true if we're currently speaking an utterance. |
+ virtual bool IsSpeaking() OVERRIDE; |
sky
2014/07/23 16:34:37
overrides are grouped together with no comments. S
mrunal
2014/07/23 17:17:06
Acknowledged.
|
+ |
+ // Speak the given utterance. If the utterance's can_enqueue flag is true |
+ // and another utterance is in progress, adds it to the end of the queue. |
+ // Otherwise, interrupts any current utterance and speaks this one |
+ // immediately. |
+ virtual void SpeakOrEnqueue(Utterance* utterance) OVERRIDE; |
+ |
+ // Stop all utterances and flush the queue. Implies leaving pause mode |
+ // as well. |
+ virtual void Stop() OVERRIDE; |
+ |
+ // Pause the speech queue. Some engines may support pausing in the middle |
+ // of an utterance. |
+ virtual void Pause() OVERRIDE; |
+ |
+ // Resume speaking. |
+ virtual void Resume() OVERRIDE; |
+ |
+ // Handle events received from the speech engine. Events are forwarded to |
+ // the callback function, and in addition, completion and error events |
+ // trigger finishing the current utterance and starting the next one, if |
+ // any. |
+ virtual void OnTtsEvent(int utterance_id, |
+ TtsEventType event_type, |
+ int char_index, |
+ const std::string& error_message) OVERRIDE; |
+ |
+ // Return a list of all available voices, including the native voice, |
+ // if supported, and all voices registered by extensions. |
+ virtual void GetVoices(Profile* profile, |
+ std::vector<VoiceData>* out_voices) OVERRIDE; |
+ |
+ // Called by TtsExtensionLoaderChromeOs::LoadTtsExtension when it |
+ // finishes loading the built-in TTS component extension. |
+ virtual void RetrySpeakingQueuedUtterances() OVERRIDE; |
+ |
+ // Called by the extension system or platform implementation when the |
+ // list of voices may have changed and should be re-queried. |
+ virtual void VoicesChanged() OVERRIDE; |
+ |
+ // Add a delegate that wants to be notified when the set of voices changes. |
+ virtual void AddVoicesChangedDelegate( |
+ VoicesChangedDelegate* delegate) OVERRIDE; |
+ |
+ // Remove delegate that wants to be notified when the set of voices changes. |
+ virtual void RemoveVoicesChangedDelegate( |
+ VoicesChangedDelegate* delegate) OVERRIDE; |
+ |
+ // Set the delegate that processes TTS requests with user-installed |
+ // extensions. |
+ virtual void SetTtsEngineDelegate(TtsEngineDelegate* delegate) OVERRIDE; |
+ |
+ // For unit testing. |
+ virtual void SetPlatformImpl(TtsPlatformImpl* platform_impl) OVERRIDE; |
+ virtual int QueueSize() OVERRIDE; |
+ |
+ protected: |
+ TtsControllerImpl(); |
+ virtual ~TtsControllerImpl(); |
+ |
+ private: |
+ // Get the platform TTS implementation (or injected mock). |
+ TtsPlatformImpl* GetPlatformImpl(); |
+ |
+ // Start speaking the given utterance. Will either take ownership of |
+ // |utterance| or delete it if there's an error. Returns true on success. |
+ void SpeakNow(Utterance* utterance); |
+ |
+ // Clear the utterance queue. If send_events is true, will send |
+ // TTS_EVENT_CANCELLED events on each one. |
+ void ClearUtteranceQueue(bool send_events); |
+ |
+ // Finalize and delete the current utterance. |
+ void FinishCurrentUtterance(); |
+ |
+ // Start speaking the next utterance in the queue. |
+ void SpeakNextUtterance(); |
+ |
+ // Given an utterance and a vector of voices, return the |
+ // index of the voice that best matches the utterance. |
+ int GetMatchingVoice(const Utterance* utterance, |
+ std::vector<VoiceData>& voices); |
+ |
+ friend struct DefaultSingletonTraits<TtsControllerImpl>; |
+ |
+ // The current utterance being spoken. |
+ Utterance* current_utterance_; |
+ |
+ // Whether the queue is paused or not. |
+ bool paused_; |
+ |
+ // A queue of utterances to speak after the current one finishes. |
+ std::queue<Utterance*> utterance_queue_; |
+ |
+ // A set of delegates that want to be notified when the voices change. |
+ std::set<VoicesChangedDelegate*> voices_changed_delegates_; |
+ |
+ // A pointer to the platform implementation of text-to-speech, for |
+ // dependency injection. |
+ TtsPlatformImpl* platform_impl_; |
+ |
+ // The delegate that processes TTS requests with user-installed extensions. |
+ TtsEngineDelegate* tts_engine_delegate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TtsControllerImpl); |
+}; |
+ |
+#endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ |