Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #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.
| |
| 6 #define CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ | |
| 7 | |
| 8 #include <queue> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/singleton.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "chrome/browser/speech/tts_controller.h" | |
| 17 #include "url/gurl.h" | |
| 18 | |
| 19 // Singleton class that manages text-to-speech for the TTS and TTS engine | |
| 20 // extension APIs, maintaining a queue of pending utterances and keeping | |
| 21 // track of all state. | |
| 22 class TtsControllerImpl : public TtsController { | |
| 23 public: | |
| 24 // Get the single instance of this class. | |
| 25 static TtsControllerImpl* GetInstance(); | |
| 26 | |
| 27 // Returns true if we're currently speaking an utterance. | |
| 28 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.
| |
| 29 | |
| 30 // Speak the given utterance. If the utterance's can_enqueue flag is true | |
| 31 // and another utterance is in progress, adds it to the end of the queue. | |
| 32 // Otherwise, interrupts any current utterance and speaks this one | |
| 33 // immediately. | |
| 34 virtual void SpeakOrEnqueue(Utterance* utterance) OVERRIDE; | |
| 35 | |
| 36 // Stop all utterances and flush the queue. Implies leaving pause mode | |
| 37 // as well. | |
| 38 virtual void Stop() OVERRIDE; | |
| 39 | |
| 40 // Pause the speech queue. Some engines may support pausing in the middle | |
| 41 // of an utterance. | |
| 42 virtual void Pause() OVERRIDE; | |
| 43 | |
| 44 // Resume speaking. | |
| 45 virtual void Resume() OVERRIDE; | |
| 46 | |
| 47 // Handle events received from the speech engine. Events are forwarded to | |
| 48 // the callback function, and in addition, completion and error events | |
| 49 // trigger finishing the current utterance and starting the next one, if | |
| 50 // any. | |
| 51 virtual void OnTtsEvent(int utterance_id, | |
| 52 TtsEventType event_type, | |
| 53 int char_index, | |
| 54 const std::string& error_message) OVERRIDE; | |
| 55 | |
| 56 // Return a list of all available voices, including the native voice, | |
| 57 // if supported, and all voices registered by extensions. | |
| 58 virtual void GetVoices(Profile* profile, | |
| 59 std::vector<VoiceData>* out_voices) OVERRIDE; | |
| 60 | |
| 61 // Called by TtsExtensionLoaderChromeOs::LoadTtsExtension when it | |
| 62 // finishes loading the built-in TTS component extension. | |
| 63 virtual void RetrySpeakingQueuedUtterances() OVERRIDE; | |
| 64 | |
| 65 // Called by the extension system or platform implementation when the | |
| 66 // list of voices may have changed and should be re-queried. | |
| 67 virtual void VoicesChanged() OVERRIDE; | |
| 68 | |
| 69 // Add a delegate that wants to be notified when the set of voices changes. | |
| 70 virtual void AddVoicesChangedDelegate( | |
| 71 VoicesChangedDelegate* delegate) OVERRIDE; | |
| 72 | |
| 73 // Remove delegate that wants to be notified when the set of voices changes. | |
| 74 virtual void RemoveVoicesChangedDelegate( | |
| 75 VoicesChangedDelegate* delegate) OVERRIDE; | |
| 76 | |
| 77 // Set the delegate that processes TTS requests with user-installed | |
| 78 // extensions. | |
| 79 virtual void SetTtsEngineDelegate(TtsEngineDelegate* delegate) OVERRIDE; | |
| 80 | |
| 81 // For unit testing. | |
| 82 virtual void SetPlatformImpl(TtsPlatformImpl* platform_impl) OVERRIDE; | |
| 83 virtual int QueueSize() OVERRIDE; | |
| 84 | |
| 85 protected: | |
| 86 TtsControllerImpl(); | |
| 87 virtual ~TtsControllerImpl(); | |
| 88 | |
| 89 private: | |
| 90 // Get the platform TTS implementation (or injected mock). | |
| 91 TtsPlatformImpl* GetPlatformImpl(); | |
| 92 | |
| 93 // Start speaking the given utterance. Will either take ownership of | |
| 94 // |utterance| or delete it if there's an error. Returns true on success. | |
| 95 void SpeakNow(Utterance* utterance); | |
| 96 | |
| 97 // Clear the utterance queue. If send_events is true, will send | |
| 98 // TTS_EVENT_CANCELLED events on each one. | |
| 99 void ClearUtteranceQueue(bool send_events); | |
| 100 | |
| 101 // Finalize and delete the current utterance. | |
| 102 void FinishCurrentUtterance(); | |
| 103 | |
| 104 // Start speaking the next utterance in the queue. | |
| 105 void SpeakNextUtterance(); | |
| 106 | |
| 107 // Given an utterance and a vector of voices, return the | |
| 108 // index of the voice that best matches the utterance. | |
| 109 int GetMatchingVoice(const Utterance* utterance, | |
| 110 std::vector<VoiceData>& voices); | |
| 111 | |
| 112 friend struct DefaultSingletonTraits<TtsControllerImpl>; | |
| 113 | |
| 114 // The current utterance being spoken. | |
| 115 Utterance* current_utterance_; | |
| 116 | |
| 117 // Whether the queue is paused or not. | |
| 118 bool paused_; | |
| 119 | |
| 120 // A queue of utterances to speak after the current one finishes. | |
| 121 std::queue<Utterance*> utterance_queue_; | |
| 122 | |
| 123 // A set of delegates that want to be notified when the voices change. | |
| 124 std::set<VoicesChangedDelegate*> voices_changed_delegates_; | |
| 125 | |
| 126 // A pointer to the platform implementation of text-to-speech, for | |
| 127 // dependency injection. | |
| 128 TtsPlatformImpl* platform_impl_; | |
| 129 | |
| 130 // The delegate that processes TTS requests with user-installed extensions. | |
| 131 TtsEngineDelegate* tts_engine_delegate_; | |
| 132 | |
| 133 DISALLOW_COPY_AND_ASSIGN(TtsControllerImpl); | |
| 134 }; | |
| 135 | |
| 136 #endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_IMPL_H_ | |
| OLD | NEW |