2007-08-05 16:17:35 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
2007-08-23 22:11:50 +00:00
|
|
|
* $Id$
|
2007-08-05 16:17:35 +00:00
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "talkfile.h"
|
|
|
|
|
|
|
|
TalkFileCreator::TalkFileCreator(QObject* parent): QObject(parent)
|
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TalkFileCreator::initEncoder()
|
|
|
|
{
|
|
|
|
QFileInfo enc(m_EncExec);
|
|
|
|
if(enc.exists())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TalkFileCreator::initTTS()
|
|
|
|
{
|
|
|
|
QFileInfo tts(m_TTSexec);
|
|
|
|
|
|
|
|
if(tts.exists())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
|
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
m_abort = false;
|
2007-08-05 16:17:35 +00:00
|
|
|
m_logger = logger;
|
|
|
|
m_logger->addItem("Starting Talkfile generation",LOGINFO);
|
|
|
|
if(!initTTS())
|
|
|
|
{
|
|
|
|
m_logger->addItem("Init of TTS engine failed",LOGERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!initEncoder())
|
|
|
|
{
|
|
|
|
m_logger->addItem("Init of encoder failed",LOGERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
connect(logger,SIGNAL(aborted()),this,SLOT(abort()));
|
|
|
|
m_logger->setProgressMax(0);
|
|
|
|
QDirIterator it(m_dir,QDirIterator::Subdirectories);
|
2007-08-10 22:17:43 +00:00
|
|
|
QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
|
|
|
|
installlog.beginGroup("talkfiles");
|
2007-08-05 16:17:35 +00:00
|
|
|
// iterate over all entrys
|
|
|
|
while (it.hasNext())
|
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
if(m_abort)
|
|
|
|
{
|
|
|
|
m_logger->addItem("Talkfile creation aborted",LOGERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QApplication::processEvents();
|
2007-08-05 16:17:35 +00:00
|
|
|
QFileInfo fileInf = it.fileInfo();
|
|
|
|
QString toSpeak;
|
|
|
|
QString filename;
|
|
|
|
QString wavfilename;
|
|
|
|
|
|
|
|
if(fileInf.fileName() == "." || fileInf.fileName() == ".." || fileInf.suffix() == "talk")
|
2007-08-29 09:27:35 +00:00
|
|
|
{
|
|
|
|
it.next();
|
2007-08-05 16:17:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(fileInf.isDir()) // if it is a dir
|
|
|
|
{
|
|
|
|
toSpeak = fileInf.fileName();
|
|
|
|
filename = fileInf.absolutePath() + "/_dirname.talk";
|
|
|
|
}
|
|
|
|
else // if it is a file
|
|
|
|
{
|
|
|
|
if(m_stripExtensions)
|
|
|
|
toSpeak = fileInf.baseName();
|
|
|
|
else
|
|
|
|
toSpeak = fileInf.fileName();
|
|
|
|
filename = fileInf.absoluteFilePath() + ".talk";
|
|
|
|
}
|
|
|
|
wavfilename = filename + ".wav";
|
|
|
|
|
|
|
|
QFileInfo filenameInf(filename);
|
|
|
|
QFileInfo wavfilenameInf(wavfilename);
|
|
|
|
|
|
|
|
if(!filenameInf.exists() || m_overwriteTalk)
|
|
|
|
{
|
|
|
|
if(!wavfilenameInf.exists() || m_overwriteWav)
|
|
|
|
{
|
|
|
|
m_logger->addItem("Voicing of " + toSpeak,LOGINFO);
|
|
|
|
if(!voice(toSpeak,wavfilename))
|
|
|
|
{
|
|
|
|
m_logger->addItem("Voicing of " + toSpeak + " failed",LOGERROR);
|
|
|
|
m_logger->abort();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_logger->addItem("Encoding of " + toSpeak,LOGINFO);
|
|
|
|
if(!encode(wavfilename,filename))
|
|
|
|
{
|
|
|
|
m_logger->addItem("Encoding of " + wavfilename + " failed",LOGERROR);
|
|
|
|
m_logger->abort();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-29 17:54:52 +00:00
|
|
|
QString now = QDate::currentDate().toString("yyyyMMdd");
|
2007-08-05 16:17:35 +00:00
|
|
|
if(m_removeWav)
|
|
|
|
{
|
|
|
|
QFile wavfile(wavfilename);
|
|
|
|
wavfile.remove();
|
2007-08-10 22:17:43 +00:00
|
|
|
installlog.remove(wavfilename);
|
|
|
|
}
|
|
|
|
else
|
2007-08-29 17:54:52 +00:00
|
|
|
installlog.setValue(wavfilename.remove(m_mountpoint),now);
|
2007-08-10 22:17:43 +00:00
|
|
|
|
2007-08-29 17:54:52 +00:00
|
|
|
installlog.setValue(filename.remove(m_mountpoint),now);
|
2007-08-05 16:17:35 +00:00
|
|
|
it.next();
|
|
|
|
}
|
|
|
|
|
2007-08-10 22:17:43 +00:00
|
|
|
installlog.endGroup();
|
2007-08-05 16:17:35 +00:00
|
|
|
m_logger->addItem("Finished creating Talkfiles",LOGOK);
|
|
|
|
m_logger->setProgressMax(1);
|
|
|
|
m_logger->setProgressValue(1);
|
|
|
|
m_logger->abort();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TalkFileCreator::abort()
|
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
m_abort = true;
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TalkFileCreator::voice(QString text,QString wavfile)
|
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
|
|
|
|
QString execstring = m_curTTSTemplate;
|
|
|
|
|
|
|
|
execstring.replace("%exe",m_TTSexec);
|
|
|
|
execstring.replace("%options",m_TTSOpts);
|
|
|
|
execstring.replace("%wavfile",wavfile);
|
|
|
|
execstring.replace("%text",text);
|
|
|
|
|
|
|
|
QProcess::execute(execstring);
|
|
|
|
return true;
|
|
|
|
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TalkFileCreator::encode(QString input,QString output)
|
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
QString execstring = m_curEncTemplate;
|
|
|
|
|
2007-08-05 16:17:35 +00:00
|
|
|
execstring.replace("%exe",m_EncExec);
|
|
|
|
execstring.replace("%options",m_EncOpts);
|
|
|
|
execstring.replace("%input",input);
|
|
|
|
execstring.replace("%output",output);
|
2007-08-29 09:27:35 +00:00
|
|
|
|
|
|
|
QProcess::execute(execstring);
|
|
|
|
return true;
|
2007-08-05 16:17:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|