ScummVM API documentation
text-to-speech.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_TEXT_TO_SPEECH_ABSTRACT_H
23 #define BACKENDS_TEXT_TO_SPEECH_ABSTRACT_H
24 
25 #include "common/scummsys.h"
26 #include "common/str.h"
27 
28 #include "common/array.h"
29 namespace Common {
30 
31 
44 class TTSVoice {
45  friend class TextToSpeechManager;
46 
47  public:
48  enum Gender {
49  MALE,
50  FEMALE,
51  UNKNOWN_GENDER
52  };
53 
54  enum Age {
55  CHILD,
56  ADULT,
57  UNKNOWN_AGE
58  };
59 
60  public:
61  TTSVoice();
62 
63  TTSVoice(Gender gender, Age age, void *data, String description) ;
64 
65  TTSVoice(const TTSVoice& voice);
66 
67  ~TTSVoice();
68 
69  TTSVoice& operator=(const TTSVoice& voice);
70 
79  Gender getGender() { return _gender; };
80 
85  void setGender(Gender gender) { _gender = gender; };
86 
95  Age getAge() { return _age; };
96 
101  void setAge(Age age) { _age = age; };
102 
109  void *getData() { return _data; };
110 
115  void setData(void *data) { _data = data; };
116 
122 
123  protected:
124  Gender _gender;
125  Age _age;
126  void *_data;
128  int *_refCount;
129 };
130 
131 struct TTSState {
132  int _rate;
133  int _pitch;
134  int _volume;
135  String _language;
136  int _activeVoice;
137  Array<TTSVoice> _availableVoices;
138  bool _enabled;
139  TTSState *_next;
140 };
141 
146 public:
147  enum Action {
148  INTERRUPT,
149  INTERRUPT_NO_REPEAT,
150  QUEUE,
151  QUEUE_NO_REPEAT,
152  DROP
153  };
160  virtual ~TextToSpeechManager() {}
161 
178  virtual bool say(const U32String &str, Action action) { return false; }
179 
184  bool say(const String &str, Action action, CodePage charset = kUtf8) {
185  U32String textToSpeak(str, charset);
186  return say(textToSpeak, action);
187  }
188 
194  bool say(const U32String &str) { return say(str, INTERRUPT_NO_REPEAT); }
195 
203  bool say(const String &str, CodePage charset = kUtf8) {
204  return say(str, INTERRUPT_NO_REPEAT, charset);
205  }
206 
210  virtual bool stop() { return false; }
211 
215  virtual bool pause() { return false; }
216 
224  virtual bool resume() { return false; }
225 
229  virtual bool isSpeaking() { return false; }
230 
234  virtual bool isPaused() { return false; }
235 
239  virtual bool isReady() { return false; }
240 
246  virtual void setVoice(unsigned index) {}
247 
251  TTSVoice getVoice();
252 
258  virtual void setRate(int rate) { _ttsState->_rate = rate; }
259 
263  int getRate() { return _ttsState->_rate; }
264 
270  virtual void setPitch(int pitch) { _ttsState->_pitch = pitch; }
271 
275  int getPitch() { return _ttsState->_pitch; }
276 
282  virtual void setVolume(unsigned volume) { _ttsState->_volume = volume; }
283 
287  int getVolume() { return _ttsState->_volume; }
288 
298  virtual void setLanguage(String language);
299 
303  String getLanguage() { return _ttsState->_language; }
304 
308  Array<TTSVoice> getVoicesArray() { return _ttsState->_availableVoices; }
309 
318  Array<int> getVoiceIndicesByGender (TTSVoice::Gender gender);
319 
323  virtual int getDefaultVoice() { return 0; }
324 
328  void pushState();
329 
333  bool popState();
334 
338  virtual void freeVoiceData(void *data) {}
339 
343  void enable(bool on);
344 
345 protected:
346  TTSState *_ttsState;
347 
348  void clearState();
349  virtual void updateVoices() {};
350 };
351 
354 } // End of namespace Common
355 
356 #endif // BACKENDS_TEXT_TO_SPEECH_ABSTRACT_H
Age getAge()
Definition: text-to-speech.h:95
void setAge(Age age)
Definition: text-to-speech.h:101
Definition: str.h:59
void * _data
Pointer to tts engine specific data about the voice.
Definition: text-to-speech.h:126
virtual void setRate(int rate)
Definition: text-to-speech.h:258
virtual bool stop()
Definition: text-to-speech.h:210
String getDescription()
Definition: text-to-speech.h:121
virtual void setVoice(unsigned index)
Definition: text-to-speech.h:246
Array< TTSVoice > getVoicesArray()
Definition: text-to-speech.h:308
Definition: array.h:52
int * _refCount
Reference count (serves for proper feeing of _data)
Definition: text-to-speech.h:128
int getPitch()
Definition: text-to-speech.h:275
Definition: text-to-speech.h:44
virtual void freeVoiceData(void *data)
Definition: text-to-speech.h:338
int getVolume()
Definition: text-to-speech.h:287
virtual bool isSpeaking()
Definition: text-to-speech.h:229
bool say(const U32String &str)
Definition: text-to-speech.h:194
virtual void setVolume(unsigned volume)
Definition: text-to-speech.h:282
virtual bool say(const U32String &str, Action action)
Definition: text-to-speech.h:178
virtual void setPitch(int pitch)
Definition: text-to-speech.h:270
String getLanguage()
Definition: text-to-speech.h:303
virtual bool isReady()
Definition: text-to-speech.h:239
void * getData()
Definition: text-to-speech.h:109
Definition: ustr.h:57
Gender _gender
Gender of the voice.
Definition: text-to-speech.h:121
Definition: algorithm.h:29
virtual bool pause()
Definition: text-to-speech.h:215
virtual int getDefaultVoice()
Definition: text-to-speech.h:323
Definition: text-to-speech.h:145
virtual bool resume()
Definition: text-to-speech.h:224
Gender getGender()
Definition: text-to-speech.h:79
void setData(void *data)
Definition: text-to-speech.h:115
String _description
Description of the voice (gets displayed in GUI)
Definition: text-to-speech.h:127
int getRate()
Definition: text-to-speech.h:263
virtual bool isPaused()
Definition: text-to-speech.h:234
bool say(const String &str, Action action, CodePage charset=kUtf8)
Definition: text-to-speech.h:184
void setGender(Gender gender)
Definition: text-to-speech.h:85
Definition: text-to-speech.h:131
bool say(const String &str, CodePage charset=kUtf8)
Definition: text-to-speech.h:203
Age _age
Age of the voice.
Definition: text-to-speech.h:125