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 | 12 |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 | 16 |
| 17 class Utterance; | |
| 16 class TtsPlatformImpl; | 18 class TtsPlatformImpl; |
| 17 class Profile; | 19 class Profile; |
| 18 | 20 |
| 19 namespace base { | 21 namespace base { |
| 20 class ListValue; | |
| 21 class Value; | 22 class Value; |
| 22 } | 23 } |
| 23 | 24 |
| 24 // Events sent back from the TTS engine indicating the progress. | 25 // Events sent back from the TTS engine indicating the progress. |
| 25 enum TtsEventType { | 26 enum TtsEventType { |
| 26 TTS_EVENT_START, | 27 TTS_EVENT_START, |
| 27 TTS_EVENT_END, | 28 TTS_EVENT_END, |
| 28 TTS_EVENT_WORD, | 29 TTS_EVENT_WORD, |
| 29 TTS_EVENT_SENTENCE, | 30 TTS_EVENT_SENTENCE, |
| 30 TTS_EVENT_MARKER, | 31 TTS_EVENT_MARKER, |
| 31 TTS_EVENT_INTERRUPTED, | 32 TTS_EVENT_INTERRUPTED, |
| 32 TTS_EVENT_CANCELLED, | 33 TTS_EVENT_CANCELLED, |
| 33 TTS_EVENT_ERROR | 34 TTS_EVENT_ERROR |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 | 37 |
|
tommi (sloooow) - chröme
2013/03/07 13:04:46
nit: one empty line is fine as a separator (here a
dmazzoni
2013/03/19 17:30:22
Done.
| |
| 38 // Returns true if this event type is one that indicates an utterance | |
| 39 // is finished and can be destroyed. | |
| 40 bool IsFinalTtsEventType(TtsEventType event_type); | |
| 41 | |
| 42 | |
| 37 // The continuous parameters that apply to a given utterance. | 43 // The continuous parameters that apply to a given utterance. |
| 38 struct UtteranceContinuousParameters { | 44 struct UtteranceContinuousParameters { |
| 39 UtteranceContinuousParameters(); | 45 UtteranceContinuousParameters(); |
| 40 | 46 |
| 41 double rate; | 47 double rate; |
| 42 double pitch; | 48 double pitch; |
| 43 double volume; | 49 double volume; |
| 44 }; | 50 }; |
| 45 | 51 |
| 46 | 52 |
| 53 // Information about one voice. | |
| 54 struct VoiceData { | |
| 55 VoiceData(); | |
| 56 ~VoiceData(); | |
| 57 | |
| 58 std::string name; | |
| 59 std::string lang; | |
| 60 std::string gender; | |
| 61 std::string extension_id; | |
| 62 std::vector<std::string> events; | |
| 63 }; | |
| 64 | |
| 65 | |
| 66 // Class that wants to receive events on utterances. | |
| 67 class UtteranceEventDelegate { | |
| 68 public: | |
| 69 virtual ~UtteranceEventDelegate() {} | |
| 70 virtual void OnTtsEvent(Utterance* utterance, | |
| 71 TtsEventType event_type, | |
| 72 int char_index, | |
| 73 const std::string& error_message) = 0; | |
| 74 }; | |
| 75 | |
| 76 | |
| 47 // One speech utterance. | 77 // One speech utterance. |
| 48 class Utterance { | 78 class Utterance { |
| 49 public: | 79 public: |
| 50 // Construct an utterance given a profile and a completion task to call | 80 // Construct an utterance given a profile and a completion task to call |
| 51 // when the utterance is done speaking. Before speaking this utterance, | 81 // when the utterance is done speaking. Before speaking this utterance, |
| 52 // its other parameters like text, rate, pitch, etc. should all be set. | 82 // its other parameters like text, rate, pitch, etc. should all be set. |
| 53 explicit Utterance(Profile* profile); | 83 explicit Utterance(Profile* profile); |
| 54 ~Utterance(); | 84 ~Utterance(); |
| 55 | 85 |
| 56 // Sends an event to the delegate. If the event type is TTS_EVENT_END | 86 // Sends an event to the delegate. If the event type is TTS_EVENT_END |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 } | 148 } |
| 119 const std::set<std::string>& desired_event_types() const { | 149 const std::set<std::string>& desired_event_types() const { |
| 120 return desired_event_types_; | 150 return desired_event_types_; |
| 121 } | 151 } |
| 122 | 152 |
| 123 const std::string& extension_id() const { return extension_id_; } | 153 const std::string& extension_id() const { return extension_id_; } |
| 124 void set_extension_id(const std::string& extension_id) { | 154 void set_extension_id(const std::string& extension_id) { |
| 125 extension_id_ = extension_id; | 155 extension_id_ = extension_id; |
| 126 } | 156 } |
| 127 | 157 |
| 158 UtteranceEventDelegate* event_delegate() const { return event_delegate_; } | |
| 159 void set_event_delegate(UtteranceEventDelegate* event_delegate) { | |
| 160 event_delegate_ = event_delegate; | |
| 161 } | |
| 162 | |
| 128 // Getters and setters for internal state. | 163 // Getters and setters for internal state. |
| 129 Profile* profile() const { return profile_; } | 164 Profile* profile() const { return profile_; } |
| 130 int id() const { return id_; } | 165 int id() const { return id_; } |
| 131 bool finished() const { return finished_; } | 166 bool finished() const { return finished_; } |
| 132 | 167 |
| 133 private: | 168 private: |
| 134 // The profile that initiated this utterance. | 169 // The profile that initiated this utterance. |
| 135 Profile* profile_; | 170 Profile* profile_; |
| 136 | 171 |
| 137 // The extension ID of the extension providing TTS for this utterance, or | 172 // The extension ID of the extension providing TTS for this utterance, or |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 157 // receive events. | 192 // receive events. |
| 158 std::string src_extension_id_; | 193 std::string src_extension_id_; |
| 159 | 194 |
| 160 // The source extension's ID of this utterance, so that it can associate | 195 // The source extension's ID of this utterance, so that it can associate |
| 161 // events with the appropriate callback. | 196 // events with the appropriate callback. |
| 162 int src_id_; | 197 int src_id_; |
| 163 | 198 |
| 164 // The URL of the page where the source extension called speak. | 199 // The URL of the page where the source extension called speak. |
| 165 GURL src_url_; | 200 GURL src_url_; |
| 166 | 201 |
| 202 // The delegate to be called when an utterance event is fired. | |
| 203 UtteranceEventDelegate* event_delegate_; | |
|
tommi (sloooow) - chröme
2013/03/07 13:04:46
document ownership?
dmazzoni
2013/03/19 17:30:22
Done.
| |
| 204 | |
| 167 // The parsed options. | 205 // The parsed options. |
| 168 std::string voice_name_; | 206 std::string voice_name_; |
| 169 std::string lang_; | 207 std::string lang_; |
| 170 std::string gender_; | 208 std::string gender_; |
| 171 UtteranceContinuousParameters continuous_parameters_; | 209 UtteranceContinuousParameters continuous_parameters_; |
| 172 bool can_enqueue_; | 210 bool can_enqueue_; |
| 173 std::set<std::string> required_event_types_; | 211 std::set<std::string> required_event_types_; |
| 174 std::set<std::string> desired_event_types_; | 212 std::set<std::string> desired_event_types_; |
| 175 | 213 |
| 176 // The index of the current char being spoken. | 214 // The index of the current char being spoken. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 205 // the callback function, and in addition, completion and error events | 243 // the callback function, and in addition, completion and error events |
| 206 // trigger finishing the current utterance and starting the next one, if | 244 // trigger finishing the current utterance and starting the next one, if |
| 207 // any. | 245 // any. |
| 208 void OnTtsEvent(int utterance_id, | 246 void OnTtsEvent(int utterance_id, |
| 209 TtsEventType event_type, | 247 TtsEventType event_type, |
| 210 int char_index, | 248 int char_index, |
| 211 const std::string& error_message); | 249 const std::string& error_message); |
| 212 | 250 |
| 213 // Return a list of all available voices, including the native voice, | 251 // Return a list of all available voices, including the native voice, |
| 214 // if supported, and all voices registered by extensions. | 252 // if supported, and all voices registered by extensions. |
| 215 base::ListValue* GetVoices(Profile* profile); | 253 void GetVoices(Profile* profile, std::vector<VoiceData>* out_voices); |
| 216 | 254 |
| 217 // Called by TtsExtensionLoaderChromeOs::LoadTtsExtension when it | 255 // Called by TtsExtensionLoaderChromeOs::LoadTtsExtension when it |
| 218 // finishes loading the built-in TTS component extension. | 256 // finishes loading the built-in TTS component extension. |
| 219 void RetrySpeakingQueuedUtterances(); | 257 void RetrySpeakingQueuedUtterances(); |
| 220 | 258 |
| 221 // For unit testing. | 259 // For unit testing. |
| 222 void SetPlatformImpl(TtsPlatformImpl* platform_impl); | 260 void SetPlatformImpl(TtsPlatformImpl* platform_impl); |
| 223 int QueueSize(); | 261 int QueueSize(); |
| 224 | 262 |
| 225 protected: | 263 protected: |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 253 std::queue<Utterance*> utterance_queue_; | 291 std::queue<Utterance*> utterance_queue_; |
| 254 | 292 |
| 255 // A pointer to the platform implementation of text-to-speech, for | 293 // A pointer to the platform implementation of text-to-speech, for |
| 256 // dependency injection. | 294 // dependency injection. |
| 257 TtsPlatformImpl* platform_impl_; | 295 TtsPlatformImpl* platform_impl_; |
| 258 | 296 |
| 259 DISALLOW_COPY_AND_ASSIGN(TtsController); | 297 DISALLOW_COPY_AND_ASSIGN(TtsController); |
| 260 }; | 298 }; |
| 261 | 299 |
| 262 #endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ | 300 #endif // CHROME_BROWSER_SPEECH_TTS_CONTROLLER_H_ |
| OLD | NEW |