rbutil: completely rework how tts and encoders are configured. (FS#10070)
[kugel-rb.git] / rbutil / rbutilqt / tts.h
blob093ccd6138b40628c5ae07a752b7bde65f53f619
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id$
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #ifndef TTS_H
24 #define TTS_H
26 #include "rbsettings.h"
27 #include <QtCore>
28 #include <QProcess>
29 #include <QDateTime>
30 #include <QRegExp>
31 #include <QTcpSocket>
33 #include "encttssettings.h"
35 enum TTSStatus{ FatalError, NoError, Warning };
37 class TTSBase : public EncTtsSettingInterface
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;
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;
57 // static functions
58 static TTSBase* getTTS(QObject* parent,QString ttsname);
59 static QStringList getTTSList();
60 static QString getTTSName(QString tts);
62 // sets the config. Users of TTS classes, always have to call this first
63 void setCfg(RbSettings* sett) { settings = sett; }
65 private:
66 //inits the tts List
67 static void initTTSList();
69 protected:
70 RbSettings* settings;
71 static QMap<QString,QString> ttsList;
74 class TTSSapi : public TTSBase
76 //! Enum to identify the settings
77 enum ESettings
79 eLANGUAGE,
80 eVOICE,
81 eSPEED,
82 eOPTIONS
85 Q_OBJECT
86 public:
87 TTSSapi(QObject* parent=NULL);
89 TTSStatus voice(QString text,QString wavfile, QString *errStr);
90 bool start(QString *errStr);
91 bool stop();
93 // for settings
94 bool configOk();
95 void generateSettings();
96 void saveSettings();
98 private slots:
99 void updateVoiceList();
101 private:
102 QStringList getVoiceList(QString language);
104 QProcess* voicescript;
105 QTextStream* voicestream;
106 QString defaultLanguage;
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;
118 class TTSExes : public TTSBase
120 enum ESettings
122 eEXEPATH,
123 eOPTIONS
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;}
133 // for settings
134 void generateSettings();
135 void saveSettings();
136 bool configOk();
138 private:
139 QString m_name;
140 QString m_TTSexec;
141 QString m_TTSOpts;
142 QString m_TTSTemplate;
143 QMap<QString,QString> m_TemplateMap;
146 class TTSFestival : public TTSBase
148 enum ESettings
150 eSERVERPATH,
151 eCLIENTPATH,
152 eVOICE,
153 eVOICEDESC
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);
164 // for settings
165 bool configOk();
166 void generateSettings();
167 void saveSettings();
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 ="");
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;
185 #endif