ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
linux-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_LINUX_H
23 #define BACKENDS_TEXT_TO_SPEECH_LINUX_H
24 
25 #include "common/scummsys.h"
26 
27 #if defined(USE_TTS) && defined(USE_SPEECH_DISPATCHER) && defined(POSIX)
28 
29 #include "common/text-to-speech.h"
30 #include "common/str.h"
31 #include "common/ustr.h"
32 #include "common/list.h"
33 #include "common/mutex.h"
34 
35 #include <pthread.h>
36 
37 struct StartSpeechParams {
38  pthread_mutex_t *mutex;
39  Common::List<Common::String> *speechQueue;
40 };
41 
42 class SpeechDispatcherManager : public Common::TextToSpeechManager {
43 public:
44  enum SpeechState {
45  READY,
46  PAUSED,
47  SPEAKING,
48  BROKEN
49  };
50 
51  enum SpeechEvent {
52  SPEECH_ENDED,
53  SPEECH_PAUSED,
54  SPEECH_CANCELED,
55  SPEECH_RESUMED,
56  SPEECH_BEGUN
57  };
58 
59  SpeechDispatcherManager();
60  ~SpeechDispatcherManager() override;
61 
62  bool say(const Common::U32String &str, Action action) override;
63 
64  bool stop() override;
65  bool pause() override;
66  bool resume() override;
67 
68  bool isSpeaking() override;
69  bool isPaused() override;
70  bool isReady() override;
71 
72  void setVoice(unsigned index) override;
73  void setRate(int rate) override;
74  void setPitch(int pitch) override;
75  void setVolume(unsigned volume) override;
76  void setLanguage(Common::String language) override;
77 
78  void updateState(SpeechEvent event);
79 
80  void freeVoiceData(void *data) override;
81 
82 private:
83  void init();
84  void updateVoices() override;
85  void createVoice(int typeNumber, Common::TTSVoice::Gender, Common::TTSVoice::Age, char *description);
86  Common::String strToUtf8(Common::String str, Common::String charset);
87  static void *startSpeech(void *p);
88 
89  StartSpeechParams _params;
90  SpeechState _speechState;
91  Common::List<Common::String> _speechQueue;
92  pthread_mutex_t _speechMutex;
93  pthread_t _thread;
94  bool _threadCreated;
95 };
96 
97 #endif
98 
99 #endif // BACKENDS_UPDATES_LINUX_H
Definition: str.h:59
Definition: ustr.h:57
Definition: text-to-speech.h:145