summaryrefslogtreecommitdiff
path: root/utils/rbutilqt/base/ttsexes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils/rbutilqt/base/ttsexes.cpp')
-rw-r--r--utils/rbutilqt/base/ttsexes.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/utils/rbutilqt/base/ttsexes.cpp b/utils/rbutilqt/base/ttsexes.cpp
new file mode 100644
index 0000000000..446725968f
--- /dev/null
+++ b/utils/rbutilqt/base/ttsexes.cpp
@@ -0,0 +1,127 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8*
9* Copyright (C) 2007 by Dominik Wenger
10*
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.
13*
14* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15* KIND, either express or implied.
16*
17****************************************************************************/
18
19#include <QtCore>
20#include "ttsexes.h"
21#include "utils.h"
22#include "rbsettings.h"
23#include "Logger.h"
24
25TTSExes::TTSExes(QObject* parent) : TTSBase(parent)
26{
27 /* default to espeak */
28 m_name = "espeak";
29 m_capabilities = TTSBase::CanSpeak;
30 m_TTSTemplate = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
31 m_TTSSpeakTemplate = "\"%exe\" %options -- \"%text\"";
32}
33
34
35TTSBase::Capabilities TTSExes::capabilities()
36{
37 return m_capabilities;
38}
39
40void TTSExes::generateSettings()
41{
42 loadSettings();
43 insertSetting(eEXEPATH, new EncTtsSetting(this, EncTtsSetting::eSTRING,
44 tr("Path to TTS engine:"), m_TTSexec, EncTtsSetting::eBROWSEBTN));
45 insertSetting(eOPTIONS, new EncTtsSetting(this, EncTtsSetting::eSTRING,
46 tr("TTS engine options:"), m_TTSOpts));
47}
48
49void TTSExes::saveSettings()
50{
51 RbSettings::setSubValue(m_name, RbSettings::TtsPath,
52 getSetting(eEXEPATH)->current().toString());
53 RbSettings::setSubValue(m_name, RbSettings::TtsOptions,
54 getSetting(eOPTIONS)->current().toString());
55 RbSettings::sync();
56}
57
58
59void TTSExes::loadSettings(void)
60{
61 m_TTSexec = RbSettings::subValue(m_name, RbSettings::TtsPath).toString();
62 if(m_TTSexec.isEmpty()) m_TTSexec = Utils::findExecutable(m_name);
63 m_TTSOpts = RbSettings::subValue(m_name, RbSettings::TtsOptions).toString();
64}
65
66
67bool TTSExes::start(QString *errStr)
68{
69 loadSettings();
70
71 QFileInfo tts(m_TTSexec);
72 if(tts.exists())
73 {
74 return true;
75 }
76 else
77 {
78 *errStr = tr("TTS executable not found");
79 return false;
80 }
81}
82
83TTSStatus TTSExes::voice(QString text, QString wavfile, QString *errStr)
84{
85 (void) errStr;
86 QString execstring;
87 if(wavfile.isEmpty() && m_capabilities & TTSBase::CanSpeak) {
88 if(m_TTSSpeakTemplate.isEmpty()) {
89 LOG_ERROR() << "internal error: TTS announces CanSpeak "
90 "but template empty!";
91 return FatalError;
92 }
93 execstring = m_TTSSpeakTemplate;
94 }
95 else if(wavfile.isEmpty()) {
96 LOG_ERROR() << "no output file passed to voice() "
97 "but TTS can't speak directly.";
98 return FatalError;
99 }
100 else {
101 execstring = m_TTSTemplate;
102 }
103
104 execstring.replace("%exe",m_TTSexec);
105 execstring.replace("%options",m_TTSOpts);
106 execstring.replace("%wavfile",wavfile);
107 execstring.replace("%text",text);
108
109 QProcess::execute(execstring);
110
111 if(!wavfile.isEmpty() && !QFileInfo(wavfile).isFile()) {
112 LOG_ERROR() << "output file does not exist:" << wavfile;
113 return FatalError;
114 }
115 return NoError;
116
117}
118
119bool TTSExes::configOk()
120{
121 loadSettings();
122 if (QFileInfo::exists(m_TTSexec))
123 return true;
124 else
125 return false;
126}
127