diff options
Diffstat (limited to 'rbutil/rbutilqt/base/tts.h')
-rw-r--r-- | rbutil/rbutilqt/base/tts.h | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/base/tts.h b/rbutil/rbutilqt/base/tts.h new file mode 100644 index 0000000000..093ccd6138 --- /dev/null +++ b/rbutil/rbutilqt/base/tts.h | |||
@@ -0,0 +1,185 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Wenger | ||
10 | * $Id$ | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | |||
23 | #ifndef TTS_H | ||
24 | #define TTS_H | ||
25 | |||
26 | #include "rbsettings.h" | ||
27 | #include <QtCore> | ||
28 | #include <QProcess> | ||
29 | #include <QDateTime> | ||
30 | #include <QRegExp> | ||
31 | #include <QTcpSocket> | ||
32 | |||
33 | #include "encttssettings.h" | ||
34 | |||
35 | enum TTSStatus{ FatalError, NoError, Warning }; | ||
36 | |||
37 | class TTSBase : public EncTtsSettingInterface | ||
38 | { | ||
39 | Q_OBJECT | ||
40 | public: | ||
41 | TTSBase(QObject *parent); | ||
42 | //! Child class should generate a clip | ||
43 | virtual TTSStatus voice(QString text,QString wavfile, QString* errStr) =0; | ||
44 | //! Child class should do startup | ||
45 | virtual bool start(QString *errStr) =0; | ||
46 | //! child class should stop | ||
47 | virtual bool stop() =0; | ||
48 | |||
49 | // configuration | ||
50 | //! Child class should return true, when configuration is good | ||
51 | virtual bool configOk()=0; | ||
52 | //! Child class should generate and insertSetting(..) its settings | ||
53 | virtual void generateSettings() = 0; | ||
54 | //! Chlid class should commit the Settings to permanent storage | ||
55 | virtual void saveSettings() = 0; | ||
56 | |||
57 | // static functions | ||
58 | static TTSBase* getTTS(QObject* parent,QString ttsname); | ||
59 | static QStringList getTTSList(); | ||
60 | static QString getTTSName(QString tts); | ||
61 | |||
62 | // sets the config. Users of TTS classes, always have to call this first | ||
63 | void setCfg(RbSettings* sett) { settings = sett; } | ||
64 | |||
65 | private: | ||
66 | //inits the tts List | ||
67 | static void initTTSList(); | ||
68 | |||
69 | protected: | ||
70 | RbSettings* settings; | ||
71 | static QMap<QString,QString> ttsList; | ||
72 | }; | ||
73 | |||
74 | class TTSSapi : public TTSBase | ||
75 | { | ||
76 | //! Enum to identify the settings | ||
77 | enum ESettings | ||
78 | { | ||
79 | eLANGUAGE, | ||
80 | eVOICE, | ||
81 | eSPEED, | ||
82 | eOPTIONS | ||
83 | }; | ||
84 | |||
85 | Q_OBJECT | ||
86 | public: | ||
87 | TTSSapi(QObject* parent=NULL); | ||
88 | |||
89 | TTSStatus voice(QString text,QString wavfile, QString *errStr); | ||
90 | bool start(QString *errStr); | ||
91 | bool stop(); | ||
92 | |||
93 | // for settings | ||
94 | bool configOk(); | ||
95 | void generateSettings(); | ||
96 | void saveSettings(); | ||
97 | |||
98 | private slots: | ||
99 | void updateVoiceList(); | ||
100 | |||
101 | private: | ||
102 | QStringList getVoiceList(QString language); | ||
103 | |||
104 | QProcess* voicescript; | ||
105 | QTextStream* voicestream; | ||
106 | QString defaultLanguage; | ||
107 | |||
108 | QString m_TTSexec; | ||
109 | QString m_TTSOpts; | ||
110 | QString m_TTSTemplate; | ||
111 | QString m_TTSLanguage; | ||
112 | QString m_TTSVoice; | ||
113 | QString m_TTSSpeed; | ||
114 | bool m_sapi4; | ||
115 | }; | ||
116 | |||
117 | |||
118 | class TTSExes : public TTSBase | ||
119 | { | ||
120 | enum ESettings | ||
121 | { | ||
122 | eEXEPATH, | ||
123 | eOPTIONS | ||
124 | }; | ||
125 | |||
126 | Q_OBJECT | ||
127 | public: | ||
128 | TTSExes(QString name,QObject* parent=NULL); | ||
129 | TTSStatus voice(QString text,QString wavfile, QString *errStr); | ||
130 | bool start(QString *errStr); | ||
131 | bool stop() {return true;} | ||
132 | |||
133 | // for settings | ||
134 | void generateSettings(); | ||
135 | void saveSettings(); | ||
136 | bool configOk(); | ||
137 | |||
138 | private: | ||
139 | QString m_name; | ||
140 | QString m_TTSexec; | ||
141 | QString m_TTSOpts; | ||
142 | QString m_TTSTemplate; | ||
143 | QMap<QString,QString> m_TemplateMap; | ||
144 | }; | ||
145 | |||
146 | class TTSFestival : public TTSBase | ||
147 | { | ||
148 | enum ESettings | ||
149 | { | ||
150 | eSERVERPATH, | ||
151 | eCLIENTPATH, | ||
152 | eVOICE, | ||
153 | eVOICEDESC | ||
154 | }; | ||
155 | |||
156 | Q_OBJECT | ||
157 | public: | ||
158 | TTSFestival(QObject* parent=NULL) :TTSBase(parent) {} | ||
159 | ~TTSFestival(); | ||
160 | bool start(QString *errStr); | ||
161 | bool stop(); | ||
162 | TTSStatus voice(QString text,QString wavfile, QString *errStr); | ||
163 | |||
164 | // for settings | ||
165 | bool configOk(); | ||
166 | void generateSettings(); | ||
167 | void saveSettings(); | ||
168 | |||
169 | private slots: | ||
170 | void updateVoiceList(); | ||
171 | void updateVoiceDescription(); | ||
172 | void clearVoiceDescription(); | ||
173 | private: | ||
174 | QStringList getVoiceList(QString path =""); | ||
175 | QString getVoiceInfo(QString voice,QString path =""); | ||
176 | |||
177 | inline void startServer(QString path=""); | ||
178 | inline void ensureServerRunning(QString path=""); | ||
179 | QString queryServer(QString query, int timeout = -1,QString path=""); | ||
180 | QProcess serverProcess; | ||
181 | QStringList voices; | ||
182 | QMap<QString, QString> voiceDescriptions; | ||
183 | }; | ||
184 | |||
185 | #endif | ||