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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 class TtsPlatformImplLinux : public TtsPlatformImpl { | 31 class TtsPlatformImplLinux : public TtsPlatformImpl { |
32 public: | 32 public: |
33 virtual bool PlatformImplAvailable() OVERRIDE; | 33 virtual bool PlatformImplAvailable() OVERRIDE; |
34 virtual bool Speak( | 34 virtual bool Speak( |
35 int utterance_id, | 35 int utterance_id, |
36 const std::string& utterance, | 36 const std::string& utterance, |
37 const std::string& lang, | 37 const std::string& lang, |
38 const VoiceData& voice, | 38 const VoiceData& voice, |
39 const UtteranceContinuousParameters& params) OVERRIDE; | 39 const UtteranceContinuousParameters& params) OVERRIDE; |
40 virtual bool StopSpeaking() OVERRIDE; | 40 virtual bool StopSpeaking() OVERRIDE; |
| 41 virtual void Pause() OVERRIDE; |
| 42 virtual void Resume() OVERRIDE; |
41 virtual bool IsSpeaking() OVERRIDE; | 43 virtual bool IsSpeaking() OVERRIDE; |
42 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE; | 44 virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE; |
43 | 45 |
44 void OnSpeechEvent(SPDNotificationType type); | 46 void OnSpeechEvent(SPDNotificationType type); |
45 | 47 |
46 // Get the single instance of this class. | 48 // Get the single instance of this class. |
47 static TtsPlatformImplLinux* GetInstance(); | 49 static TtsPlatformImplLinux* GetInstance(); |
48 | 50 |
49 private: | 51 private: |
50 TtsPlatformImplLinux(); | 52 TtsPlatformImplLinux(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 bool TtsPlatformImplLinux::StopSpeaking() { | 193 bool TtsPlatformImplLinux::StopSpeaking() { |
192 if (!PlatformImplAvailable()) | 194 if (!PlatformImplAvailable()) |
193 return false; | 195 return false; |
194 if (libspeechd_loader_.spd_stop(conn_) == -1) { | 196 if (libspeechd_loader_.spd_stop(conn_) == -1) { |
195 Reset(); | 197 Reset(); |
196 return false; | 198 return false; |
197 } | 199 } |
198 return true; | 200 return true; |
199 } | 201 } |
200 | 202 |
| 203 void TtsPlatformImplLinux::Pause() { |
| 204 if (!PlatformImplAvailable()) |
| 205 return; |
| 206 libspeechd_loader_.spd_pause(conn_); |
| 207 } |
| 208 |
| 209 void TtsPlatformImplLinux::Resume() { |
| 210 if (!PlatformImplAvailable()) |
| 211 return; |
| 212 libspeechd_loader_.spd_resume(conn_); |
| 213 } |
| 214 |
201 bool TtsPlatformImplLinux::IsSpeaking() { | 215 bool TtsPlatformImplLinux::IsSpeaking() { |
202 return current_notification_ == SPD_EVENT_BEGIN; | 216 return current_notification_ == SPD_EVENT_BEGIN; |
203 } | 217 } |
204 | 218 |
205 void TtsPlatformImplLinux::GetVoices( | 219 void TtsPlatformImplLinux::GetVoices( |
206 std::vector<VoiceData>* out_voices) { | 220 std::vector<VoiceData>* out_voices) { |
207 if (!all_native_voices_.get()) { | 221 if (!all_native_voices_.get()) { |
208 all_native_voices_.reset(new std::map<std::string, SPDChromeVoice>()); | 222 all_native_voices_.reset(new std::map<std::string, SPDChromeVoice>()); |
209 char** modules = libspeechd_loader_.spd_list_modules(conn_); | 223 char** modules = libspeechd_loader_.spd_list_modules(conn_); |
210 if (!modules) | 224 if (!modules) |
(...skipping 29 matching lines...) Expand all Loading... |
240 it != all_native_voices_->end(); | 254 it != all_native_voices_->end(); |
241 it++) { | 255 it++) { |
242 out_voices->push_back(VoiceData()); | 256 out_voices->push_back(VoiceData()); |
243 VoiceData& voice = out_voices->back(); | 257 VoiceData& voice = out_voices->back(); |
244 voice.native = true; | 258 voice.native = true; |
245 voice.name = it->first; | 259 voice.name = it->first; |
246 voice.events.insert(TTS_EVENT_START); | 260 voice.events.insert(TTS_EVENT_START); |
247 voice.events.insert(TTS_EVENT_END); | 261 voice.events.insert(TTS_EVENT_END); |
248 voice.events.insert(TTS_EVENT_CANCELLED); | 262 voice.events.insert(TTS_EVENT_CANCELLED); |
249 voice.events.insert(TTS_EVENT_MARKER); | 263 voice.events.insert(TTS_EVENT_MARKER); |
| 264 voice.events.insert(TTS_EVENT_PAUSE); |
| 265 voice.events.insert(TTS_EVENT_RESUME); |
250 } | 266 } |
251 } | 267 } |
252 | 268 |
253 void TtsPlatformImplLinux::OnSpeechEvent(SPDNotificationType type) { | 269 void TtsPlatformImplLinux::OnSpeechEvent(SPDNotificationType type) { |
254 TtsController* controller = TtsController::GetInstance(); | 270 TtsController* controller = TtsController::GetInstance(); |
255 switch (type) { | 271 switch (type) { |
256 case SPD_EVENT_BEGIN: | 272 case SPD_EVENT_BEGIN: |
257 case SPD_EVENT_RESUME: | |
258 controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string()); | 273 controller->OnTtsEvent(utterance_id_, TTS_EVENT_START, 0, std::string()); |
259 break; | 274 break; |
| 275 case SPD_EVENT_RESUME: |
| 276 controller->OnTtsEvent(utterance_id_, TTS_EVENT_RESUME, 0, std::string()); |
| 277 break; |
260 case SPD_EVENT_END: | 278 case SPD_EVENT_END: |
| 279 controller->OnTtsEvent( |
| 280 utterance_id_, TTS_EVENT_END, utterance_.size(), std::string()); |
| 281 break; |
261 case SPD_EVENT_PAUSE: | 282 case SPD_EVENT_PAUSE: |
262 controller->OnTtsEvent( | 283 controller->OnTtsEvent( |
263 utterance_id_, TTS_EVENT_END, utterance_.size(), std::string()); | 284 utterance_id_, TTS_EVENT_PAUSE, utterance_.size(), std::string()); |
264 break; | 285 break; |
265 case SPD_EVENT_CANCEL: | 286 case SPD_EVENT_CANCEL: |
266 controller->OnTtsEvent( | 287 controller->OnTtsEvent( |
267 utterance_id_, TTS_EVENT_CANCELLED, 0, std::string()); | 288 utterance_id_, TTS_EVENT_CANCELLED, 0, std::string()); |
268 break; | 289 break; |
269 case SPD_EVENT_INDEX_MARK: | 290 case SPD_EVENT_INDEX_MARK: |
270 controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string()); | 291 controller->OnTtsEvent(utterance_id_, TTS_EVENT_MARKER, 0, std::string()); |
271 break; | 292 break; |
272 } | 293 } |
273 } | 294 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // static | 331 // static |
311 TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() { | 332 TtsPlatformImplLinux* TtsPlatformImplLinux::GetInstance() { |
312 return Singleton<TtsPlatformImplLinux, | 333 return Singleton<TtsPlatformImplLinux, |
313 LeakySingletonTraits<TtsPlatformImplLinux> >::get(); | 334 LeakySingletonTraits<TtsPlatformImplLinux> >::get(); |
314 } | 335 } |
315 | 336 |
316 // static | 337 // static |
317 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { | 338 TtsPlatformImpl* TtsPlatformImpl::GetInstance() { |
318 return TtsPlatformImplLinux::GetInstance(); | 339 return TtsPlatformImplLinux::GetInstance(); |
319 } | 340 } |
OLD | NEW |