summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/talkfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/talkfile.cpp')
-rw-r--r--rbutil/rbutilqt/talkfile.cpp212
1 files changed, 212 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/talkfile.cpp b/rbutil/rbutilqt/talkfile.cpp
new file mode 100644
index 0000000000..da532e327c
--- /dev/null
+++ b/rbutil/rbutilqt/talkfile.cpp
@@ -0,0 +1,212 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2007 by Dominik Wenger
10 * $Id: talkfile.cpp 14027 2007-07-27 17:42:49Z domonoky $
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "talkfile.h"
21
22TalkFileCreator::TalkFileCreator(QObject* parent): QObject(parent)
23{
24
25}
26
27void TalkFileCreator::setTTsType(QString tts)
28{
29 m_curTTS = tts;
30 int index = m_supportedTTS.indexOf(m_curTTS);
31 m_curTTSTemplate = m_supportedTTSTemplates.at(index);
32}
33
34void TalkFileCreator::setEncType(QString enc)
35{
36 m_curEnc = enc;
37 int index = m_supportedEnc.indexOf(m_curEnc);
38 m_curEncTemplate = m_supportedEncTemplates.at(index);
39}
40
41bool TalkFileCreator::initEncoder()
42{
43 QFileInfo enc(m_EncExec);
44 if(enc.exists())
45 {
46 return true;
47 }
48 else
49 {
50 return false;
51 }
52}
53
54bool TalkFileCreator::initTTS()
55{
56 QFileInfo tts(m_TTSexec);
57
58 if(tts.exists())
59 {
60 return true;
61 }
62 else
63 {
64 return false;
65 }
66}
67
68bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
69{
70 m_abort = false;
71 m_logger = logger;
72 m_logger->addItem("Starting Talkfile generation",LOGINFO);
73 if(!initTTS())
74 {
75 m_logger->addItem("Init of TTS engine failed",LOGERROR);
76 return false;
77 }
78 if(!initEncoder())
79 {
80 m_logger->addItem("Init of encoder failed",LOGERROR);
81 return false;
82 }
83 QApplication::processEvents();
84
85 connect(logger,SIGNAL(aborted()),this,SLOT(abort()));
86 m_logger->setProgressMax(0);
87 QDirIterator it(m_dir,QDirIterator::Subdirectories);
88 // iterate over all entrys
89 while (it.hasNext())
90 {
91 if(m_abort)
92 {
93 m_logger->addItem("Talkfile creation aborted",LOGERROR);
94 return false;
95 }
96
97 QApplication::processEvents();
98 QFileInfo fileInf = it.fileInfo();
99 QString toSpeak;
100 QString filename;
101 QString wavfilename;
102
103 if(fileInf.fileName() == "." || fileInf.fileName() == ".." || fileInf.suffix() == "talk")
104 {
105 it.next();
106 continue;
107 }
108 if(fileInf.isDir()) // if it is a dir
109 {
110 toSpeak = fileInf.fileName();
111 filename = fileInf.absolutePath() + "/_dirname.talk";
112 }
113 else // if it is a file
114 {
115 if(m_stripExtensions)
116 toSpeak = fileInf.baseName();
117 else
118 toSpeak = fileInf.fileName();
119 filename = fileInf.absoluteFilePath() + ".talk";
120 }
121 wavfilename = filename + ".wav";
122
123 QFileInfo filenameInf(filename);
124 QFileInfo wavfilenameInf(wavfilename);
125
126 if(!filenameInf.exists() || m_overwriteTalk)
127 {
128 if(!wavfilenameInf.exists() || m_overwriteWav)
129 {
130 m_logger->addItem("Voicing of " + toSpeak,LOGINFO);
131 if(!voice(toSpeak,wavfilename))
132 {
133 m_logger->addItem("Voicing of " + toSpeak + " failed",LOGERROR);
134 m_logger->abort();
135 return false;
136 }
137 }
138 m_logger->addItem("Encoding of " + toSpeak,LOGINFO);
139 if(!encode(wavfilename,filename))
140 {
141 m_logger->addItem("Encoding of " + wavfilename + " failed",LOGERROR);
142 m_logger->abort();
143 return false;
144 }
145 }
146
147 if(m_removeWav)
148 {
149 QFile wavfile(wavfilename);
150 wavfile.remove();
151 }
152
153 it.next();
154 }
155
156 m_logger->addItem("Finished creating Talkfiles",LOGOK);
157 m_logger->setProgressMax(1);
158 m_logger->setProgressValue(1);
159 m_logger->abort();
160
161 return true;
162
163}
164
165void TalkFileCreator::abort()
166{
167 m_abort = true;
168}
169
170bool TalkFileCreator::voice(QString text,QString wavfile)
171{
172
173 QString execstring = m_curTTSTemplate;
174
175 execstring.replace("%exe",m_TTSexec);
176 execstring.replace("%options",m_TTSOpts);
177 execstring.replace("%wavfile",wavfile);
178 execstring.replace("%text",text);
179
180 QProcess::execute(execstring);
181 return true;
182
183}
184
185bool TalkFileCreator::encode(QString input,QString output)
186{
187 QString execstring = m_curEncTemplate;
188
189 execstring.replace("%exe",m_EncExec);
190 execstring.replace("%options",m_EncOpts);
191 execstring.replace("%input",input);
192 execstring.replace("%output",output);
193
194 QProcess::execute(execstring);
195 return true;
196
197}
198
199QString TalkFileCreator::getTTsOpts(QString ttsname)
200{
201 int index = m_supportedTTS.indexOf(ttsname);
202
203 return m_supportedTTSOpts.at(index);
204}
205
206QString TalkFileCreator::getEncOpts(QString encname)
207{
208 int index = m_supportedEnc.indexOf(encname);
209
210 return m_supportedEncOpts.at(index);
211}
212