Use a nice apostroph
[kugel-rb.git] / rbutil / rbutilqt / base / ttsexes.cpp
blobbd14e2a9ee33487f3e790abc2489e3b45e232f74
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id$
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "ttsexes.h"
21 #include "utils.h"
22 #include "rbsettings.h"
24 TTSExes::TTSExes(QString name,QObject* parent) : TTSBase(parent)
26 m_name = name;
28 m_TemplateMap["espeak"] = "\"%exe\" %options -w \"%wavfile\" \"%text\"";
29 m_TemplateMap["flite"] = "\"%exe\" %options -o \"%wavfile\" -t \"%text\"";
30 m_TemplateMap["swift"] = "\"%exe\" %options -o \"%wavfile\" \"%text\"";
34 void TTSExes::generateSettings()
36 QString exepath =RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
37 if(exepath == "") exepath = Utils::findExecutable(m_name);
39 insertSetting(eEXEPATH,new EncTtsSetting(this,EncTtsSetting::eSTRING,
40 tr("Path to TTS engine:"),exepath,EncTtsSetting::eBROWSEBTN));
41 insertSetting(eOPTIONS,new EncTtsSetting(this,EncTtsSetting::eSTRING,
42 tr("TTS engine options:"),RbSettings::subValue(m_name,RbSettings::TtsOptions)));
45 void TTSExes::saveSettings()
47 RbSettings::setSubValue(m_name,RbSettings::TtsPath,
48 getSetting(eEXEPATH)->current().toString());
49 RbSettings::setSubValue(m_name,RbSettings::TtsOptions,
50 getSetting(eOPTIONS)->current().toString());
51 RbSettings::sync();
54 bool TTSExes::start(QString *errStr)
56 m_TTSexec = RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
57 m_TTSOpts = RbSettings::subValue(m_name,RbSettings::TtsOptions).toString();
59 m_TTSTemplate = m_TemplateMap.value(m_name);
61 QFileInfo tts(m_TTSexec);
62 if(tts.exists())
64 return true;
66 else
68 *errStr = tr("TTS executable not found");
69 return false;
73 TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr)
75 (void) errStr;
76 QString execstring = m_TTSTemplate;
78 execstring.replace("%exe",m_TTSexec);
79 execstring.replace("%options",m_TTSOpts);
80 execstring.replace("%wavfile",wavfile);
81 execstring.replace("%text",text);
82 //qDebug() << "voicing" << execstring;
83 QProcess::execute(execstring);
84 return NoError;
88 bool TTSExes::configOk()
90 QString path = RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
92 if (QFileInfo(path).exists())
93 return true;
95 return false;