Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ | 6 #define CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 class Utterance; | 18 class Utterance; |
| 19 class TtsPlatformImpl; | 19 class TtsPlatformImpl; |
| 20 class Profile; | |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class Value; | 22 class Value; |
| 24 } | 23 } |
| 25 | 24 |
| 25 namespace content { | |
| 26 class BrowserContext; | |
| 27 } | |
| 28 | |
| 26 // Events sent back from the TTS engine indicating the progress. | 29 // Events sent back from the TTS engine indicating the progress. |
| 27 enum TtsEventType { | 30 enum TtsEventType { |
| 28 TTS_EVENT_START, | 31 TTS_EVENT_START, |
| 29 TTS_EVENT_END, | 32 TTS_EVENT_END, |
| 30 TTS_EVENT_WORD, | 33 TTS_EVENT_WORD, |
| 31 TTS_EVENT_SENTENCE, | 34 TTS_EVENT_SENTENCE, |
| 32 TTS_EVENT_MARKER, | 35 TTS_EVENT_MARKER, |
| 33 TTS_EVENT_INTERRUPTED, | 36 TTS_EVENT_INTERRUPTED, |
| 34 TTS_EVENT_CANCELLED, | 37 TTS_EVENT_CANCELLED, |
| 35 TTS_EVENT_ERROR, | 38 TTS_EVENT_ERROR, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 bool native; | 79 bool native; |
| 77 std::string native_voice_identifier; | 80 std::string native_voice_identifier; |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 // Interface that delegates TTS requests to user-installed extensions. | 83 // Interface that delegates TTS requests to user-installed extensions. |
| 81 class TtsEngineDelegate { | 84 class TtsEngineDelegate { |
| 82 public: | 85 public: |
| 83 virtual ~TtsEngineDelegate() {} | 86 virtual ~TtsEngineDelegate() {} |
| 84 | 87 |
| 85 // Return a list of all available voices registered. | 88 // Return a list of all available voices registered. |
| 86 virtual void GetVoices(Profile* profile, | 89 virtual void GetVoices(content::BrowserContext* browser_context, |
| 87 std::vector<VoiceData>* out_voices) = 0; | 90 std::vector<VoiceData>* out_voices) = 0; |
| 88 | 91 |
| 89 // Speak the given utterance by sending an event to the given TTS engine. | 92 // Speak the given utterance by sending an event to the given TTS engine. |
| 90 virtual void Speak(Utterance* utterance, const VoiceData& voice) = 0; | 93 virtual void Speak(Utterance* utterance, const VoiceData& voice) = 0; |
| 91 | 94 |
| 92 // Stop speaking the given utterance by sending an event to the target | 95 // Stop speaking the given utterance by sending an event to the target |
| 93 // associated with this utterance. | 96 // associated with this utterance. |
| 94 virtual void Stop(Utterance* utterance) = 0; | 97 virtual void Stop(Utterance* utterance) = 0; |
| 95 | 98 |
| 96 // Pause in the middle of speaking this utterance. | 99 // Pause in the middle of speaking this utterance. |
| 97 virtual void Pause(Utterance* utterance) = 0; | 100 virtual void Pause(Utterance* utterance) = 0; |
| 98 | 101 |
| 99 // Resume speaking this utterance. | 102 // Resume speaking this utterance. |
| 100 virtual void Resume(Utterance* utterance) = 0; | 103 virtual void Resume(Utterance* utterance) = 0; |
| 101 | 104 |
| 102 // Load the built-in component extension for ChromeOS. | 105 // Load the built-in component extension for ChromeOS. |
| 103 virtual bool LoadBuiltInTtsExtension(Profile* profile) = 0; | 106 virtual bool LoadBuiltInTtsExtension( |
| 107 content::BrowserContext* browser_context) = 0; | |
|
dmazzoni
2014/08/12 06:21:08
nit: indentation
| |
| 104 }; | 108 }; |
| 105 | 109 |
| 106 // Class that wants to receive events on utterances. | 110 // Class that wants to receive events on utterances. |
| 107 class UtteranceEventDelegate { | 111 class UtteranceEventDelegate { |
| 108 public: | 112 public: |
| 109 virtual ~UtteranceEventDelegate() {} | 113 virtual ~UtteranceEventDelegate() {} |
| 110 virtual void OnTtsEvent(Utterance* utterance, | 114 virtual void OnTtsEvent(Utterance* utterance, |
| 111 TtsEventType event_type, | 115 TtsEventType event_type, |
| 112 int char_index, | 116 int char_index, |
| 113 const std::string& error_message) = 0; | 117 const std::string& error_message) = 0; |
| 114 }; | 118 }; |
| 115 | 119 |
| 116 // Class that wants to be notified when the set of | 120 // Class that wants to be notified when the set of |
| 117 // voices has changed. | 121 // voices has changed. |
| 118 class VoicesChangedDelegate { | 122 class VoicesChangedDelegate { |
| 119 public: | 123 public: |
| 120 virtual ~VoicesChangedDelegate() {} | 124 virtual ~VoicesChangedDelegate() {} |
| 121 virtual void OnVoicesChanged() = 0; | 125 virtual void OnVoicesChanged() = 0; |
| 122 }; | 126 }; |
| 123 | 127 |
| 124 // One speech utterance. | 128 // One speech utterance. |
| 125 class Utterance { | 129 class Utterance { |
| 126 public: | 130 public: |
| 127 // Construct an utterance given a profile and a completion task to call | 131 // Construct an utterance given a profile and a completion task to call |
| 128 // when the utterance is done speaking. Before speaking this utterance, | 132 // when the utterance is done speaking. Before speaking this utterance, |
| 129 // its other parameters like text, rate, pitch, etc. should all be set. | 133 // its other parameters like text, rate, pitch, etc. should all be set. |
| 130 explicit Utterance(Profile* profile); | 134 explicit Utterance(content::BrowserContext* browser_context); |
| 131 ~Utterance(); | 135 ~Utterance(); |
| 132 | 136 |
| 133 // Sends an event to the delegate. If the event type is TTS_EVENT_END | 137 // Sends an event to the delegate. If the event type is TTS_EVENT_END |
| 134 // or TTS_EVENT_ERROR, deletes the utterance. If |char_index| is -1, | 138 // or TTS_EVENT_ERROR, deletes the utterance. If |char_index| is -1, |
| 135 // uses the last good value. | 139 // uses the last good value. |
| 136 void OnTtsEvent(TtsEventType event_type, | 140 void OnTtsEvent(TtsEventType event_type, |
| 137 int char_index, | 141 int char_index, |
| 138 const std::string& error_message); | 142 const std::string& error_message); |
| 139 | 143 |
| 140 // Finish an utterance without sending an event to the delegate. | 144 // Finish an utterance without sending an event to the delegate. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 | 208 |
| 205 UtteranceEventDelegate* event_delegate() const { | 209 UtteranceEventDelegate* event_delegate() const { |
| 206 return event_delegate_.get(); | 210 return event_delegate_.get(); |
| 207 } | 211 } |
| 208 void set_event_delegate( | 212 void set_event_delegate( |
| 209 base::WeakPtr<UtteranceEventDelegate> event_delegate) { | 213 base::WeakPtr<UtteranceEventDelegate> event_delegate) { |
| 210 event_delegate_ = event_delegate; | 214 event_delegate_ = event_delegate; |
| 211 } | 215 } |
| 212 | 216 |
| 213 // Getters and setters for internal state. | 217 // Getters and setters for internal state. |
| 214 Profile* profile() const { return profile_; } | 218 content::BrowserContext* browser_context() const { return browser_context_; } |
| 215 int id() const { return id_; } | 219 int id() const { return id_; } |
| 216 bool finished() const { return finished_; } | 220 bool finished() const { return finished_; } |
| 217 | 221 |
| 218 private: | 222 private: |
| 219 // The profile that initiated this utterance. | 223 // The profile that initiated this utterance. |
|
dmazzoni
2014/08/12 06:21:08
Update the comment.
| |
| 220 Profile* profile_; | 224 content::BrowserContext* browser_context_; |
| 221 | 225 |
| 222 // The extension ID of the extension providing TTS for this utterance, or | 226 // The extension ID of the extension providing TTS for this utterance, or |
| 223 // empty if native TTS is being used. | 227 // empty if native TTS is being used. |
| 224 std::string extension_id_; | 228 std::string extension_id_; |
| 225 | 229 |
| 226 // The unique ID of this utterance, used to associate callback functions | 230 // The unique ID of this utterance, used to associate callback functions |
| 227 // with utterances. | 231 // with utterances. |
| 228 int id_; | 232 int id_; |
| 229 | 233 |
| 230 // The id of the next utterance, so we can associate requests with | 234 // The id of the next utterance, so we can associate requests with |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 // the callback function, and in addition, completion and error events | 304 // the callback function, and in addition, completion and error events |
| 301 // trigger finishing the current utterance and starting the next one, if | 305 // trigger finishing the current utterance and starting the next one, if |
| 302 // any. | 306 // any. |
| 303 virtual void OnTtsEvent(int utterance_id, | 307 virtual void OnTtsEvent(int utterance_id, |
| 304 TtsEventType event_type, | 308 TtsEventType event_type, |
| 305 int char_index, | 309 int char_index, |
| 306 const std::string& error_message) = 0; | 310 const std::string& error_message) = 0; |
| 307 | 311 |
| 308 // Return a list of all available voices, including the native voice, | 312 // Return a list of all available voices, including the native voice, |
| 309 // if supported, and all voices registered by extensions. | 313 // if supported, and all voices registered by extensions. |
| 310 virtual void GetVoices(Profile* profile, | 314 virtual void GetVoices(content::BrowserContext* browser_context, |
| 311 std::vector<VoiceData>* out_voices) = 0; | 315 std::vector<VoiceData>* out_voices) = 0; |
| 312 | 316 |
| 313 // Called by the extension system or platform implementation when the | 317 // Called by the extension system or platform implementation when the |
| 314 // list of voices may have changed and should be re-queried. | 318 // list of voices may have changed and should be re-queried. |
| 315 virtual void VoicesChanged() = 0; | 319 virtual void VoicesChanged() = 0; |
| 316 | 320 |
| 317 // Add a delegate that wants to be notified when the set of voices changes. | 321 // Add a delegate that wants to be notified when the set of voices changes. |
| 318 virtual void AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0; | 322 virtual void AddVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0; |
| 319 | 323 |
| 320 // Remove delegate that wants to be notified when the set of voices changes. | 324 // Remove delegate that wants to be notified when the set of voices changes. |
| 321 virtual void RemoveVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0; | 325 virtual void RemoveVoicesChangedDelegate(VoicesChangedDelegate* delegate) = 0; |
| 322 | 326 |
| 323 // Set the delegate that processes TTS requests with user-installed | 327 // Set the delegate that processes TTS requests with user-installed |
| 324 // extensions. | 328 // extensions. |
| 325 virtual void SetTtsEngineDelegate(TtsEngineDelegate* delegate) = 0; | 329 virtual void SetTtsEngineDelegate(TtsEngineDelegate* delegate) = 0; |
| 326 | 330 |
| 327 // Get the delegate that processes TTS requests with user-installed | 331 // Get the delegate that processes TTS requests with user-installed |
| 328 // extensions. | 332 // extensions. |
| 329 virtual TtsEngineDelegate* GetTtsEngineDelegate() = 0; | 333 virtual TtsEngineDelegate* GetTtsEngineDelegate() = 0; |
| 330 | 334 |
| 331 // For unit testing. | 335 // For unit testing. |
| 332 virtual void SetPlatformImpl(TtsPlatformImpl* platform_impl) = 0; | 336 virtual void SetPlatformImpl(TtsPlatformImpl* platform_impl) = 0; |
| 333 virtual int QueueSize() = 0; | 337 virtual int QueueSize() = 0; |
| 334 | 338 |
| 335 protected: | 339 protected: |
| 336 virtual ~TtsController() {} | 340 virtual ~TtsController() {} |
| 337 }; | 341 }; |
| 338 | 342 |
| 339 #endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ | 343 #endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ |
| OLD | NEW |