1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
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 ****************************************************************************/
22 TalkFileCreator::TalkFileCreator(QObject
* parent
): QObject(parent
)
28 bool TalkFileCreator::initEncoder()
30 QFileInfo
enc(m_EncExec
);
42 bool TalkFileCreator::createTalkFiles(ProgressloggerInterface
* logger
)
46 m_logger
->addItem("Starting Talk file generation",LOGINFO
);
48 if(m_curTTS
== "sapi")
49 m_tts
= new TTSSapi();
51 m_tts
= new TTSExes();
53 m_tts
->setTTSexe(m_TTSexec
);
54 m_tts
->setTTsOpts(m_TTSOpts
);
55 m_tts
->setTTsLanguage(m_TTSLanguage
);
56 m_tts
->setTTsTemplate(m_curTTSTemplate
);
60 m_logger
->addItem("Init of TTS engine failed",LOGERROR
);
65 m_logger
->addItem("Init of encoder failed",LOGERROR
);
69 QApplication::processEvents();
71 connect(logger
,SIGNAL(aborted()),this,SLOT(abort()));
72 m_logger
->setProgressMax(0);
73 QDirIterator
it(m_dir
,QDirIterator::Subdirectories
);
74 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
75 installlog
.beginGroup("talkfiles");
76 // iterate over all entrys
81 m_logger
->addItem("Talk file creation aborted",LOGERROR
);
86 QApplication::processEvents();
87 QFileInfo fileInf
= it
.fileInfo();
92 //! skip dotdot and .talk files
93 if(fileInf
.fileName() == ".." || fileInf
.suffix() == "talk")
101 // skip entry if folder talking isnt enabled
102 if(m_talkFolders
== false)
107 toSpeak
= fileInf
.absoluteDir().dirName();
108 filename
= fileInf
.absolutePath() + "/_dirname.talk";
110 else // if it is a file
112 // skip entry if file talking isnt enabled
113 if(m_talkFiles
== false)
118 if(m_stripExtensions
)
119 toSpeak
= fileInf
.baseName();
121 toSpeak
= fileInf
.fileName();
122 filename
= fileInf
.absoluteFilePath() + ".talk";
124 wavfilename
= filename
+ ".wav";
126 QFileInfo
filenameInf(filename
);
127 QFileInfo
wavfilenameInf(wavfilename
);
129 //! the actual generation of the .talk files
130 if(!filenameInf
.exists() || m_overwriteTalk
)
132 if(!wavfilenameInf
.exists() || m_overwriteWav
)
134 m_logger
->addItem("Voicing of " + toSpeak
,LOGINFO
);
135 if(!m_tts
->voice(toSpeak
,wavfilename
))
137 m_logger
->addItem("Voicing of " + toSpeak
+ " failed",LOGERROR
);
143 m_logger
->addItem("Encoding of " + toSpeak
,LOGINFO
);
144 if(!encode(wavfilename
,filename
))
146 m_logger
->addItem("Encoding of " + wavfilename
+ " failed",LOGERROR
);
153 //! remove the intermedia wav file, if requested
154 QString now
= QDate::currentDate().toString("yyyyMMdd");
157 QFile
wavfile(wavfilename
);
159 installlog
.remove(wavfilename
);
162 installlog
.setValue(wavfilename
.remove(0,m_mountpoint
.length()),now
);
164 //! add the .talk file to the install log
165 installlog
.setValue(filename
.remove(0,m_mountpoint
.length()),now
);
169 installlog
.endGroup();
171 m_logger
->addItem("Finished creating Talk files",LOGOK
);
172 m_logger
->setProgressMax(1);
173 m_logger
->setProgressValue(1);
180 void TalkFileCreator::abort()
185 bool TalkFileCreator::encode(QString input
,QString output
)
187 qDebug() << "encoding..";
188 QString execstring
= m_curEncTemplate
;
190 execstring
.replace("%exe",m_EncExec
);
191 execstring
.replace("%options",m_EncOpts
);
192 execstring
.replace("%input",input
);
193 execstring
.replace("%output",output
);
194 qDebug() << execstring
;
195 QProcess::execute(execstring
);
200 bool TTSSapi::start()
202 QFileInfo
tts(m_TTSexec
);
206 // create the voice process
207 QString execstring
= m_TTSTemplate
;
208 execstring
.replace("%exe",m_TTSexec
);
209 execstring
.replace("%options",m_TTSOpts
);
210 execstring
.replace("%lang",m_TTSLanguage
);
211 qDebug() << "init" << execstring
;
212 voicescript
= new QProcess(NULL
);
213 voicescript
->start(execstring
);
214 if(!voicescript
->waitForStarted())
219 bool TTSSapi::voice(QString text
,QString wavfile
)
221 QString query
= "SPEAK\t"+wavfile
+"\t"+text
+"\r\n";
222 qDebug() << "voicing" << query
;
223 voicescript
->write(query
.toLocal8Bit());
224 voicescript
->write("SYNC\tbla\r\n");
225 voicescript
->waitForReadyRead();
231 QString query
= "QUIT\r\n";
232 voicescript
->write(query
.toLocal8Bit());
233 voicescript
->waitForFinished();
238 bool TTSExes::start()
240 QFileInfo
tts(m_TTSexec
);
241 qDebug() << "ttsexe init";
252 bool TTSExes::voice(QString text
,QString wavfile
)
254 QString execstring
= m_TTSTemplate
;
256 execstring
.replace("%exe",m_TTSexec
);
257 execstring
.replace("%options",m_TTSOpts
);
258 execstring
.replace("%wavfile",wavfile
);
259 execstring
.replace("%text",text
);
260 qDebug() << "voicing" << execstring
;
261 QProcess::execute(execstring
);