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 #include <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/synchronization/lock.h" | 8 #include "base/synchronization/lock.h" |
9 #include "chrome/browser/speech/tts_platform.h" | 9 #include "chrome/browser/speech/tts_platform.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
23 class TtsPlatformImplLinux : public TtsPlatformImpl { | 23 class TtsPlatformImplLinux : public TtsPlatformImpl { |
24 public: | 24 public: |
25 virtual bool PlatformImplAvailable() OVERRIDE; | 25 virtual bool PlatformImplAvailable() OVERRIDE; |
26 virtual bool Speak( | 26 virtual bool Speak( |
27 int utterance_id, | 27 int utterance_id, |
28 const std::string& utterance, | 28 const std::string& utterance, |
29 const std::string& lang, | 29 const std::string& lang, |
30 const VoiceData& voice, | 30 const VoiceData& voice, |
31 const UtteranceContinuousParameters& params) OVERRIDE; | 31 const UtteranceContinuousParameters& params) OVERRIDE; |
32 virtual bool StopSpeaking() OVERRIDE; | 32 virtual bool StopSpeaking() OVERRIDE; |
33 virtual void Pause() OVERRIDE; | |
34 virtual void Resume() OVERRIDE; | |
33 virtual bool IsSpeaking() OVERRIDE; | 35 virtual bool IsSpeaking() OVERRIDE; |
34 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE; | 36 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE; |
35 | 37 |
36 void OnSpeechEvent(SPDNotificationType type); | 38 void OnSpeechEvent(SPDNotificationType type); |
37 | 39 |
38 // Get the single instance of this class. | 40 // Get the single instance of this class. |
39 static TtsPlatformImplLinux* GetInstance(); | 41 static TtsPlatformImplLinux* GetInstance(); |
40 | 42 |
41 private: | 43 private: |
42 TtsPlatformImplLinux(); | 44 TtsPlatformImplLinux(); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 bool TtsPlatformImplLinux::StopSpeaking() { | 174 bool TtsPlatformImplLinux::StopSpeaking() { |
173 if (!PlatformImplAvailable()) | 175 if (!PlatformImplAvailable()) |
174 return false; | 176 return false; |
175 if (libspeechd_loader_.spd_stop(conn_) == -1) { | 177 if (libspeechd_loader_.spd_stop(conn_) == -1) { |
176 Reset(); | 178 Reset(); |
177 return false; | 179 return false; |
178 } | 180 } |
179 return true; | 181 return true; |
180 } | 182 } |
181 | 183 |
184 void TtsPlatformImplLinux::Pause() { | |
185 if (!PlatformImplAvailable()) | |
186 return; | |
187 libspeechd_loader_.spd_pause(conn_); | |
David Tseng
2013/05/13 21:22:48
Any issues with calling pause (or resume) repeated
dmazzoni
2013/05/14 16:50:27
The Linux speech dispatcher is the only one that a
| |
188 } | |
189 | |
190 void TtsPlatformImplLinux::Resume() { | |
191 if (!PlatformImplAvailable()) | |
192 return; | |
193 libspeechd_loader_.spd_resume(conn_); | |
194 } | |
195 | |
182 bool TtsPlatformImplLinux::IsSpeaking() { | 196 bool TtsPlatformImplLinux::IsSpeaking() { |
183 return current_notification_ == SPD_EVENT_BEGIN; | 197 return current_notification_ == SPD_EVENT_BEGIN; |
184 } | 198 } |
185 | 199 |
186 void TtsPlatformImplLinux::GetVoices( | 200 void TtsPlatformImplLinux::GetVoices( |
187 std::vector<VoiceData>* out_voices) { | 201 std::vector<VoiceData>* out_voices) { |
188 // TODO: get all voices, not just default voice. | 202 // TODO: get all voices, not just default voice. |
189 // http://crbug.com/88059 | 203 // http://crbug.com/88059 |
190 out_voices->push_back(VoiceData()); | 204 out_voices->push_back(VoiceData()); |
191 VoiceData& voice = out_voices->back(); | 205 VoiceData& voice = out_voices->back(); |
192 voice.native = true; | 206 voice.native = true; |
193 voice.name = "native"; | 207 voice.name = "native"; |
194 voice.events.insert(TTS_EVENT_START); | 208 voice.events.insert(TTS_EVENT_START); |
195 voice.events.insert(TTS_EVENT_END); | 209 voice.events.insert(TTS_EVENT_END); |
196 voice.events.insert(TTS_EVENT_CANCELLED); | 210 voice.events.insert(TTS_EVENT_CANCELLED); |
197 voice.events.insert(TTS_EVENT_MARKER); | 211 voice.events.insert(TTS_EVENT_MARKER); |
212 voice.events.insert(TTS_EVENT_PAUSE); | |
213 voice.events.insert(TTS_EVENT_RESUME); | |
198 } | 214 } |
199 | 215 |
200 void TtsPlatformImplLinux::OnSpeechEvent(SPDNotificationType type) { | 216 void TtsPlatformImplLinux::OnSpeechEvent(SPDNotificationType type) { |
201 TtsController* controller = TtsController::GetInstance(); | 217 TtsController* controller = TtsController::GetInstance(); |
202 switch (type) { | 218 switch (type) { |
203 case SPD_EVENT_BEGIN: | 219 case SPD_EVENT_BEGIN: |
204 case SPD_EVENT_RESUME: | |
205 controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string()); | 220 controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string()); |
206 break; | 221 break; |
222 case SPD_EVENT_RESUME: | |
223 controller->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME, 0, std::string()); | |
224 break; | |
207 case SPD_EVENT_END: | 225 case SPD_EVENT_END: |
226 controller->OnTtsEvent( | |
227 utterance_id_, TTS_EVENT_END, utterance_.size(), std::string()); | |
228 break; | |
208 case SPD_EVENT_PAUSE: | 229 case SPD_EVENT_PAUSE: |
209 controller->OnTtsEvent( | 230 controller->OnTtsEvent( |
210 utterance_id_, TTS_EVENT_END, utterance_.size(), std::string()); | 231 utterance_id_, TTS_EVENT_PAUSE, utterance_.size(), std::string()); |
211 break; | 232 break; |
212 case SPD_EVENT_CANCEL: | 233 case SPD_EVENT_CANCEL: |
213 controller->OnTtsEvent( | 234 controller->OnTtsEvent( |
214 utterance_id_, TTS_EVENT_CANCELLED, 0, std::string()); | 235 utterance_id_, TTS_EVENT_CANCELLED, 0, std::string()); |
215 break; | 236 break; |
216 case SPD_EVENT_INDEX_MARK: | 237 case SPD_EVENT_INDEX_MARK: |
217 controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string()); | 238 controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string()); |
218 break; | 239 break; |
219 } | 240 } |
220 } | 241 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 // static | 278 // static |
258 TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() { | 279 TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() { |
259 return Singleton<TtsPlatformImplLinux, | 280 return Singleton<TtsPlatformImplLinux, |
260 LeakySingletonTraits<TtsPlatformImplLinux> >::get(); | 281 LeakySingletonTraits<TtsPlatformImplLinux> >::get(); |
261 } | 282 } |
262 | 283 |
263 // static | 284 // static |
264 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { | 285 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { |
265 return TtsPlatformImplLinux::GetInstance(); | 286 return TtsPlatformImplLinux::GetInstance(); |
266 } | 287 } |
OLD | NEW |