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::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;
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Starting Talk file generation"),LOGINFO);
|
2007-09-23 13:35:45 +00:00
|
|
|
|
2007-12-15 13:13:57 +00:00
|
|
|
//tts
|
2008-02-12 21:45:50 +00:00
|
|
|
m_tts = TTSBase::getTTS(settings->curTTS());
|
2008-01-25 00:12:25 +00:00
|
|
|
m_tts->setCfg(settings);
|
2007-09-23 13:35:45 +00:00
|
|
|
|
2008-01-19 18:33:33 +00:00
|
|
|
QString errStr;
|
|
|
|
if(!m_tts->start(&errStr))
|
2007-08-05 16:17:35 +00:00
|
|
|
{
|
2008-06-25 22:25:52 +00:00
|
|
|
m_logger->addItem(errStr.trimmed(),LOGERROR);
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Init of TTS engine failed"),LOGERROR);
|
2007-12-16 10:20:56 +00:00
|
|
|
m_logger->abort();
|
2007-08-05 16:17:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-12-14 19:26:54 +00:00
|
|
|
|
|
|
|
// Encoder
|
2008-02-13 18:11:09 +00:00
|
|
|
m_enc = EncBase::getEncoder(settings->curEncoder());
|
2008-01-25 00:12:25 +00:00
|
|
|
m_enc->setCfg(settings);
|
2007-12-14 19:26:54 +00:00
|
|
|
|
|
|
|
if(!m_enc->start())
|
2007-08-05 16:17:35 +00:00
|
|
|
{
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Init of Encoder engine failed"),LOGERROR);
|
2007-12-16 10:20:56 +00:00
|
|
|
m_logger->abort();
|
2007-09-23 13:35:45 +00:00
|
|
|
m_tts->stop();
|
2007-08-05 16:17:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-12-14 19:26:54 +00:00
|
|
|
|
2008-02-10 18:25:49 +00:00
|
|
|
QCoreApplication::processEvents();
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-05 16:17:35 +00:00
|
|
|
connect(logger,SIGNAL(aborted()),this,SLOT(abort()));
|
|
|
|
m_logger->setProgressMax(0);
|
2008-02-09 12:28:12 +00:00
|
|
|
|
2008-02-09 18:58:14 +00:00
|
|
|
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
|
|
|
|
if(m_recursive)
|
|
|
|
flags = QDirIterator::Subdirectories;
|
|
|
|
|
2008-02-09 12:28:12 +00:00
|
|
|
QDirIterator it(m_dir,flags);
|
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
|
2007-09-15 22:57:07 +00:00
|
|
|
while (it.hasNext())
|
2007-08-05 16:17:35 +00:00
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
if(m_abort)
|
|
|
|
{
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Talk file creation aborted"),LOGERROR);
|
2007-12-16 10:20:56 +00:00
|
|
|
m_logger->abort();
|
2007-09-23 13:35:45 +00:00
|
|
|
m_tts->stop();
|
2008-07-03 19:54:44 +00:00
|
|
|
m_enc->stop();
|
2007-08-29 09:27:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-10 18:25:49 +00:00
|
|
|
QCoreApplication::processEvents();
|
2007-08-05 16:17:35 +00:00
|
|
|
QFileInfo fileInf = it.fileInfo();
|
|
|
|
QString toSpeak;
|
|
|
|
QString filename;
|
|
|
|
QString wavfilename;
|
2008-05-27 20:02:25 +00:00
|
|
|
QString filepath;
|
2007-12-14 19:26:54 +00:00
|
|
|
|
|
|
|
QString path = fileInf.filePath();
|
|
|
|
qDebug() << path;
|
|
|
|
|
2008-05-27 20:02:25 +00:00
|
|
|
if( path.endsWith("..") || path.endsWith(".") || path.endsWith(".talk") )
|
2007-08-29 09:27:35 +00:00
|
|
|
{
|
|
|
|
it.next();
|
2007-08-05 16:17:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-12-14 19:26:54 +00:00
|
|
|
|
2007-10-19 21:49:07 +00:00
|
|
|
//! if it is a dir
|
|
|
|
if(fileInf.isDir())
|
2007-08-05 16:17:35 +00:00
|
|
|
{
|
2007-10-12 15:52:04 +00:00
|
|
|
// skip entry if folder talking isnt enabled
|
|
|
|
if(m_talkFolders == false)
|
|
|
|
{
|
|
|
|
it.next();
|
|
|
|
continue;
|
2007-12-14 19:26:54 +00:00
|
|
|
}
|
2008-05-27 20:02:25 +00:00
|
|
|
|
|
|
|
toSpeak = fileInf.fileName();
|
|
|
|
|
|
|
|
filepath = fileInf.filePath() + "/";
|
|
|
|
filename = "_dirname.talk";
|
|
|
|
qDebug() << "toSpeak: " << toSpeak << "filename: " << filename << " path: " <<filepath;
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
|
|
|
else // if it is a file
|
|
|
|
{
|
2007-10-12 15:52:04 +00:00
|
|
|
// skip entry if file talking isnt enabled
|
|
|
|
if(m_talkFiles == false)
|
|
|
|
{
|
|
|
|
it.next();
|
|
|
|
continue;
|
|
|
|
}
|
2008-05-27 20:02:25 +00:00
|
|
|
|
|
|
|
// create toSpeak string
|
2007-08-05 16:17:35 +00:00
|
|
|
if(m_stripExtensions)
|
|
|
|
toSpeak = fileInf.baseName();
|
|
|
|
else
|
|
|
|
toSpeak = fileInf.fileName();
|
2008-05-27 20:02:25 +00:00
|
|
|
// create filename and path
|
|
|
|
filepath = fileInf.absolutePath();
|
|
|
|
filename = fileInf.fileName() + ".talk";
|
|
|
|
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
2008-05-27 20:02:25 +00:00
|
|
|
|
|
|
|
wavfilename = QDir::tempPath()+ "/"+ filename + ".wav";
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2008-07-03 20:03:17 +00:00
|
|
|
QFileInfo filenameInf(filepath+"/"+filename);
|
2007-08-05 16:17:35 +00:00
|
|
|
QFileInfo wavfilenameInf(wavfilename);
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-10-19 21:49:07 +00:00
|
|
|
//! the actual generation of the .talk files
|
2007-08-05 16:17:35 +00:00
|
|
|
if(!filenameInf.exists() || m_overwriteTalk)
|
|
|
|
{
|
|
|
|
if(!wavfilenameInf.exists() || m_overwriteWav)
|
|
|
|
{
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Voicing of %1").arg(toSpeak),LOGINFO);
|
2007-09-23 13:35:45 +00:00
|
|
|
if(!m_tts->voice(toSpeak,wavfilename))
|
2007-08-05 16:17:35 +00:00
|
|
|
{
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Voicing of %s failed").arg(toSpeak),LOGERROR);
|
2007-08-05 16:17:35 +00:00
|
|
|
m_logger->abort();
|
2007-09-23 13:35:45 +00:00
|
|
|
m_tts->stop();
|
2007-12-14 19:26:54 +00:00
|
|
|
m_enc->stop();
|
2008-02-09 18:58:14 +00:00
|
|
|
|
2007-08-05 16:17:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-02-10 18:25:49 +00:00
|
|
|
QCoreApplication::processEvents();
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Encoding of %1").arg(toSpeak),LOGINFO);
|
2008-07-03 20:03:17 +00:00
|
|
|
if(!m_enc->encode(wavfilename,filepath+"/"+filename))
|
2007-08-05 16:17:35 +00:00
|
|
|
{
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Encoding of %1 failed").arg(wavfilename),LOGERROR);
|
2007-08-05 16:17:35 +00:00
|
|
|
m_logger->abort();
|
2007-09-23 13:35:45 +00:00
|
|
|
m_tts->stop();
|
2007-12-14 19:26:54 +00:00
|
|
|
m_enc->stop();
|
2008-02-09 18:58:14 +00:00
|
|
|
|
2007-08-05 16:17:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-02-10 18:25:49 +00:00
|
|
|
QCoreApplication::processEvents();
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
2007-10-19 21:49:07 +00:00
|
|
|
|
|
|
|
//! remove the intermedia wav file, if requested
|
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-10-19 21:49:07 +00:00
|
|
|
installlog.setValue(wavfilename.remove(0,m_mountpoint.length()),now);
|
|
|
|
|
|
|
|
//! add the .talk file to the install log
|
2008-07-03 20:03:17 +00:00
|
|
|
installlog.setValue(QString(filepath+"/"+filename).remove(0,m_mountpoint.length()),now);
|
2007-08-05 16:17:35 +00:00
|
|
|
it.next();
|
|
|
|
}
|
2007-09-15 22:57:07 +00:00
|
|
|
|
2007-08-10 22:17:43 +00:00
|
|
|
installlog.endGroup();
|
2007-09-23 13:35:45 +00:00
|
|
|
m_tts->stop();
|
2008-07-03 19:54:44 +00:00
|
|
|
m_enc->stop();
|
2008-01-19 18:33:33 +00:00
|
|
|
m_logger->addItem(tr("Finished creating Talk files"),LOGOK);
|
2007-08-05 16:17:35 +00:00
|
|
|
m_logger->setProgressMax(1);
|
|
|
|
m_logger->setProgressValue(1);
|
|
|
|
m_logger->abort();
|
2007-09-15 22:57:07 +00:00
|
|
|
|
|
|
|
return true;
|
2007-08-05 16:17:35 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void TalkFileCreator::abort()
|
|
|
|
{
|
2007-08-29 09:27:35 +00:00
|
|
|
m_abort = true;
|
2007-08-05 16:17:35 +00:00
|
|
|
}
|
|
|
|
|