mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 21:25:19 -05:00
rbutilQt: added Talkfile creation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14197 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
1d9f693658
commit
e70f7f4ca8
12 changed files with 1001 additions and 23 deletions
212
rbutil/rbutilqt/talkfile.cpp
Normal file
212
rbutil/rbutilqt/talkfile.cpp
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2007 by Dominik Wenger
|
||||
* $Id: talkfile.cpp 14027 2007-07-27 17:42:49Z domonoky $
|
||||
*
|
||||
* 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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TalkFileCreator::setTTsType(QString tts)
|
||||
{
|
||||
m_curTTS = tts;
|
||||
int index = m_supportedTTS.indexOf(m_curTTS);
|
||||
m_curTTSTemplate = m_supportedTTSTemplates.at(index);
|
||||
}
|
||||
|
||||
void TalkFileCreator::setEncType(QString enc)
|
||||
{
|
||||
m_curEnc = enc;
|
||||
int index = m_supportedEnc.indexOf(m_curEnc);
|
||||
m_curEncTemplate = m_supportedEncTemplates.at(index);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
m_abort = false;
|
||||
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);
|
||||
// iterate over all entrys
|
||||
while (it.hasNext())
|
||||
{
|
||||
if(m_abort)
|
||||
{
|
||||
m_logger->addItem("Talkfile creation aborted",LOGERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
QApplication::processEvents();
|
||||
QFileInfo fileInf = it.fileInfo();
|
||||
QString toSpeak;
|
||||
QString filename;
|
||||
QString wavfilename;
|
||||
|
||||
if(fileInf.fileName() == "." || fileInf.fileName() == ".." || fileInf.suffix() == "talk")
|
||||
{
|
||||
it.next();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if(m_removeWav)
|
||||
{
|
||||
QFile wavfile(wavfilename);
|
||||
wavfile.remove();
|
||||
}
|
||||
|
||||
it.next();
|
||||
}
|
||||
|
||||
m_logger->addItem("Finished creating Talkfiles",LOGOK);
|
||||
m_logger->setProgressMax(1);
|
||||
m_logger->setProgressValue(1);
|
||||
m_logger->abort();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void TalkFileCreator::abort()
|
||||
{
|
||||
m_abort = true;
|
||||
}
|
||||
|
||||
bool TalkFileCreator::voice(QString text,QString wavfile)
|
||||
{
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
bool TalkFileCreator::encode(QString input,QString output)
|
||||
{
|
||||
QString execstring = m_curEncTemplate;
|
||||
|
||||
execstring.replace("%exe",m_EncExec);
|
||||
execstring.replace("%options",m_EncOpts);
|
||||
execstring.replace("%input",input);
|
||||
execstring.replace("%output",output);
|
||||
|
||||
QProcess::execute(execstring);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
QString TalkFileCreator::getTTsOpts(QString ttsname)
|
||||
{
|
||||
int index = m_supportedTTS.indexOf(ttsname);
|
||||
|
||||
return m_supportedTTSOpts.at(index);
|
||||
}
|
||||
|
||||
QString TalkFileCreator::getEncOpts(QString encname)
|
||||
{
|
||||
int index = m_supportedEnc.indexOf(encname);
|
||||
|
||||
return m_supportedEncOpts.at(index);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue