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"
29namespace Common {
30
31
44class 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
126 void setDescription(String description) { _description = description; };
127
128 protected:
129 Gender _gender;
130 Age _age;
131 void *_data;
134};
135
136struct TTSState {
137 int _rate;
138 int _pitch;
139 int _volume;
140 String _language;
141 int _activeVoice;
142 Array<TTSVoice> _availableVoices;
143 bool _enabled;
144 TTSState *_next;
145};
146
151public:
152 enum Action {
153 INTERRUPT,
154 INTERRUPT_NO_REPEAT,
155 QUEUE,
156 QUEUE_NO_REPEAT,
157 DROP
158 };
165 virtual ~TextToSpeechManager() {}
166
183 virtual bool say(const U32String &str, Action action) { return false; }
184
189 bool say(const String &str, Action action, CodePage charset = kUtf8) {
190 U32String textToSpeak(str, charset);
191 return say(textToSpeak, action);
192 }
193
199 bool say(const U32String &str) { return say(str, INTERRUPT_NO_REPEAT); }
200
208 bool say(const String &str, CodePage charset = kUtf8) {
209 return say(str, INTERRUPT_NO_REPEAT, charset);
210 }
211
215 virtual bool stop() { return false; }
216
220 virtual bool pause() { return false; }
221
229 virtual bool resume() { return false; }
230
234 virtual bool isSpeaking() { return false; }
235
239 virtual bool isPaused() { return false; }
240
244 virtual bool isReady() { return false; }
245
251 virtual void setVoice(unsigned index) {}
252
257
263 virtual void setRate(int rate) { _ttsState->_rate = rate; }
264
268 int getRate() { return _ttsState->_rate; }
269
275 virtual void setPitch(int pitch) { _ttsState->_pitch = pitch; }
276
280 int getPitch() { return _ttsState->_pitch; }
281
287 virtual void setVolume(unsigned volume) { _ttsState->_volume = volume; }
288
292 int getVolume() { return _ttsState->_volume; }
293
303 virtual void setLanguage(String language);
304
308 String getLanguage() { return _ttsState->_language; }
309
313 Array<TTSVoice> getVoicesArray() { return _ttsState->_availableVoices; }
314
323 Array<int> getVoiceIndicesByGender (TTSVoice::Gender gender);
324
328 virtual int getDefaultVoice() { return 0; }
329
333 void pushState();
334
338 bool popState();
339
343 virtual void freeVoiceData(void *data) {}
344
348 void enable(bool on);
349
350protected:
351 TTSState *_ttsState;
352
353 void clearState();
354 virtual void updateVoices() {};
355};
356
359} // End of namespace Common
360
361#endif // BACKENDS_TEXT_TO_SPEECH_ABSTRACT_H
Definition: array.h:52
Definition: str.h:59
Definition: text-to-speech.h:44
void * _data
Pointer to tts engine specific data about the voice.
Definition: text-to-speech.h:131
Age _age
Age of the voice.
Definition: text-to-speech.h:130
Gender getGender()
Definition: text-to-speech.h:79
void * getData()
Definition: text-to-speech.h:109
String _description
Description of the voice (gets displayed in GUI)
Definition: text-to-speech.h:132
Gender _gender
Gender of the voice.
Definition: text-to-speech.h:129
int * _refCount
Reference count (serves for proper feeing of _data)
Definition: text-to-speech.h:133
String getDescription()
Definition: text-to-speech.h:121
void setAge(Age age)
Definition: text-to-speech.h:101
Age getAge()
Definition: text-to-speech.h:95
void setGender(Gender gender)
Definition: text-to-speech.h:85
void setDescription(String description)
Definition: text-to-speech.h:126
void setData(void *data)
Definition: text-to-speech.h:115
Definition: text-to-speech.h:150
virtual bool isPaused()
Definition: text-to-speech.h:239
String getLanguage()
Definition: text-to-speech.h:308
virtual void setLanguage(String language)
int getPitch()
Definition: text-to-speech.h:280
int getVolume()
Definition: text-to-speech.h:292
bool say(const U32String &str)
Definition: text-to-speech.h:199
virtual bool stop()
Definition: text-to-speech.h:215
virtual void freeVoiceData(void *data)
Definition: text-to-speech.h:343
virtual void setRate(int rate)
Definition: text-to-speech.h:263
virtual void setVolume(unsigned volume)
Definition: text-to-speech.h:287
bool say(const String &str, Action action, CodePage charset=kUtf8)
Definition: text-to-speech.h:189
virtual bool pause()
Definition: text-to-speech.h:220
bool say(const String &str, CodePage charset=kUtf8)
Definition: text-to-speech.h:208
virtual void setPitch(int pitch)
Definition: text-to-speech.h:275
virtual bool isReady()
Definition: text-to-speech.h:244
int getRate()
Definition: text-to-speech.h:268
virtual void setVoice(unsigned index)
Definition: text-to-speech.h:251
Array< int > getVoiceIndicesByGender(TTSVoice::Gender gender)
virtual bool say(const U32String &str, Action action)
Definition: text-to-speech.h:183
virtual bool isSpeaking()
Definition: text-to-speech.h:234
virtual bool resume()
Definition: text-to-speech.h:229
virtual int getDefaultVoice()
Definition: text-to-speech.h:328
Array< TTSVoice > getVoicesArray()
Definition: text-to-speech.h:313
Definition: ustr.h:57
Definition: algorithm.h:29
Definition: text-to-speech.h:136