Bump version numbers for 3.13
[maemo-rb.git] / rbutil / rbutilqt / base / ttsexes.cpp
blob348db103bce538a1f8e78e5fdf777538b536ef47
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
19 #include <QtCore>
20 #include "ttsexes.h"
21 #include "utils.h"
22 #include "rbsettings.h"
24 TTSExes::TTSExes(QObject* parent) : TTSBase(parent)
26 /* default to espeak */
27 m_name = "espeak";
28 m_capabilities = TTSBase::CanSpeak;
29 m_TTSTemplate = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
30 m_TTSSpeakTemplate = "\"%exe\" %options -- \"%text\"";
34 TTSBase::Capabilities TTSExes::capabilities()
36 return m_capabilities;
39 void TTSExes::generateSettings()
41 loadSettings();
42 insertSetting(eEXEPATH, new EncTtsSetting(this, EncTtsSetting::eSTRING,
43 tr("Path to TTS engine:"), m_TTSexec, EncTtsSetting::eBROWSEBTN));
44 insertSetting(eOPTIONS, new EncTtsSetting(this, EncTtsSetting::eSTRING,
45 tr("TTS engine options:"), m_TTSOpts));
48 void TTSExes::saveSettings()
50 RbSettings::setSubValue(m_name, RbSettings::TtsPath,
51 getSetting(eEXEPATH)->current().toString());
52 RbSettings::setSubValue(m_name, RbSettings::TtsOptions,
53 getSetting(eOPTIONS)->current().toString());
54 RbSettings::sync();
58 void TTSExes::loadSettings(void)
60 m_TTSexec = RbSettings::subValue(m_name, RbSettings::TtsPath).toString();
61 if(m_TTSexec.isEmpty()) m_TTSexec = Utils::findExecutable(m_name);
62 m_TTSOpts = RbSettings::subValue(m_name, RbSettings::TtsOptions).toString();
66 bool TTSExes::start(QString *errStr)
68 loadSettings();
70 QFileInfo tts(m_TTSexec);
71 if(tts.exists())
73 return true;
75 else
77 *errStr = tr("TTS executable not found");
78 return false;
82 TTSStatus TTSExes::voice(QString text, QString wavfile, QString *errStr)
84 (void) errStr;
85 QString execstring;
86 if(wavfile.isEmpty() && m_capabilities & TTSBase::CanSpeak) {
87 if(m_TTSSpeakTemplate.isEmpty()) {
88 qDebug() << "[TTSExes] internal error: TTS announces CanSpeak "
89 "but template empty!";
90 return FatalError;
92 execstring = m_TTSSpeakTemplate;
94 else if(wavfile.isEmpty()) {
95 qDebug() << "[TTSExes] no output file passed to voice() "
96 "but TTS can't speak directly.";
97 return FatalError;
99 else {
100 execstring = m_TTSTemplate;
103 execstring.replace("%exe",m_TTSexec);
104 execstring.replace("%options",m_TTSOpts);
105 execstring.replace("%wavfile",wavfile);
106 execstring.replace("%text",text);
108 QProcess::execute(execstring);
110 if(!wavfile.isEmpty() && !QFileInfo(wavfile).isFile()) {
111 qDebug() << "[TTSExes] output file does not exist:" << wavfile;
112 return FatalError;
114 return NoError;
118 bool TTSExes::configOk()
120 loadSettings();
121 if (QFileInfo(m_TTSexec).exists())
122 return true;
123 else
124 return false;