From e70f7f4ca857e9e88a6e076360b6c9c235d7739b Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Sun, 5 Aug 2007 16:17:35 +0000 Subject: rbutilQt: added Talkfile creation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14197 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/installbl.cpp | 33 ++--- rbutil/rbutilqt/installtalkfrm.ui | 268 ++++++++++++++++++++++++++++++++++ rbutil/rbutilqt/installtalkwindow.cpp | 264 +++++++++++++++++++++++++++++++++ rbutil/rbutilqt/installtalkwindow.h | 66 +++++++++ rbutil/rbutilqt/rbutil.ini | 18 +++ rbutil/rbutilqt/rbutilqt.cpp | 14 +- rbutil/rbutilqt/rbutilqt.h | 1 + rbutil/rbutilqt/rbutilqt.pro | 7 +- rbutil/rbutilqt/rbutilqt.qrc | 1 + rbutil/rbutilqt/rbutilqtfrm.ui | 35 ++++- rbutil/rbutilqt/talkfile.cpp | 212 +++++++++++++++++++++++++++ rbutil/rbutilqt/talkfile.h | 105 +++++++++++++ 12 files changed, 1001 insertions(+), 23 deletions(-) create mode 100644 rbutil/rbutilqt/installtalkfrm.ui create mode 100644 rbutil/rbutilqt/installtalkwindow.cpp create mode 100644 rbutil/rbutilqt/installtalkwindow.h create mode 100644 rbutil/rbutilqt/talkfile.cpp create mode 100644 rbutil/rbutilqt/talkfile.h (limited to 'rbutil') diff --git a/rbutil/rbutilqt/installbl.cpp b/rbutil/rbutilqt/installbl.cpp index 627fa961b6..9d9dba4760 100644 --- a/rbutil/rbutilqt/installbl.cpp +++ b/rbutil/rbutilqt/installbl.cpp @@ -152,27 +152,26 @@ void InstallBl::done(bool error) void InstallBl::setDeviceSettings(QSettings *dev) { devices = dev; - - if(userSettings->value("defaults/platform").toString() == "h100" || - userSettings->value("defaults/platform").toString() == "h120" || - userSettings->value("defaults/platform").toString() == "h300") - { - ui.buttonBrowseOF->show(); - ui.lineOriginalFirmware->show(); - ui.label_3->show(); - needextrafile = true; - } - else - { - ui.buttonBrowseOF->hide(); - ui.lineOriginalFirmware->hide(); - ui.label_3->hide(); - needextrafile = false; - } qDebug() << "Install::setDeviceSettings:" << devices; } void InstallBl::setUserSettings(QSettings *user) { userSettings = user; + if(userSettings->value("defaults/platform").toString() == "h100" || + userSettings->value("defaults/platform").toString() == "h120" || + userSettings->value("defaults/platform").toString() == "h300") + { + ui.buttonBrowseOF->show(); + ui.lineOriginalFirmware->show(); + ui.label_3->show(); + needextrafile = true; + } + else + { + ui.buttonBrowseOF->hide(); + ui.lineOriginalFirmware->hide(); + ui.label_3->hide(); + needextrafile = false; + } } diff --git a/rbutil/rbutilqt/installtalkfrm.ui b/rbutil/rbutilqt/installtalkfrm.ui new file mode 100644 index 0000000000..d43326dd6e --- /dev/null +++ b/rbutil/rbutilqt/installtalkfrm.ui @@ -0,0 +1,268 @@ + + InstallTalkFrm + + + Qt::WindowModal + + + + 0 + 0 + 681 + 516 + + + + Install Talk Files + + + + + + + + + :/icons/icons/wizard.xpm + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Select the Folder to generate Talkfiles for. + + + + + + + + + + &Browse + + + :/icons/icons/system-search.png + + + + + + + TTS Engine + + + + + + Select a TTS Engine + + + + + + + + + + Select the TTS executable in your Filesystem + + + + + + + + + + Browse + + + + + + + TTS Options + + + + + + + + + + + + + Encoder Engine + + + + + + Select an Encoder + + + + + + + + + + Select the Encoder executable in your Filesystem + + + + + + + + + + Browse + + + + + + + Encoder Options + + + + + + + + + + + + + Overwrite Wavefiles + + + + + + + Remove Wavefiles + + + + + + + Run recursive + + + + + + + Overwrite Talkfiles + + + + + + + Strip Extensions + + + + + + + Qt::Vertical + + + + 20 + 111 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + &Ok + + + :/icons/icons/go-next.png + + + + + + + &Cancel + + + :/icons/icons/process-stop.png + + + + + + + + + + + + + buttonOk + clicked() + InstallTalkFrm + accept() + + + 472 + 418 + + + 382 + 328 + + + + + buttonCancel + clicked() + InstallTalkFrm + reject() + + + 561 + 428 + + + 522 + 332 + + + + + diff --git a/rbutil/rbutilqt/installtalkwindow.cpp b/rbutil/rbutilqt/installtalkwindow.cpp new file mode 100644 index 0000000000..4d1cdb1491 --- /dev/null +++ b/rbutil/rbutilqt/installtalkwindow.cpp @@ -0,0 +1,264 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Riebeling + * $Id: installtalkwindow.cpp 14151 2007-08-02 22:27:51Z bluebrother $ + * + * 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 "installtalkwindow.h" +#include "ui_installtalkfrm.h" + +InstallTalkWindow::InstallTalkWindow(QWidget *parent) : QDialog(parent) +{ + ui.setupUi(this); + talkcreator = new TalkFileCreator(this); + + connect(ui.buttonBrowse, SIGNAL(clicked()), this, SLOT(browseFolder())); + connect(ui.buttonBrowseTTS, SIGNAL(clicked()), this, SLOT(browseTTS())); + connect(ui.buttonBrowseEncoder, SIGNAL(clicked()), this, SLOT(browseEncoder())); + + connect(ui.Encodercbx,SIGNAL(currentIndexChanged(int)),this,SLOT(setEncoderOptions(int))); + connect(ui.TTScbx,SIGNAL(currentIndexChanged(int)),this,SLOT(setTTSOptions(int))); + + ui.OverwriteWav->setChecked(true); + ui.RemoveWav->setChecked(true); + ui.recursive->setChecked(true); + ui.OverwriteTalk->setChecked(true); + ui.StripExtensions->setChecked(true); + + +} + +void InstallTalkWindow::browseFolder() +{ + QFileDialog browser(this); + if(QFileInfo(ui.lineTalkFolder->text()).isDir()) + browser.setDirectory(ui.lineTalkFolder->text()); + else + browser.setDirectory("/media"); + browser.setReadOnly(true); + browser.setFileMode(QFileDialog::DirectoryOnly); + browser.setAcceptMode(QFileDialog::AcceptOpen); + if(browser.exec()) { + qDebug() << browser.directory(); + QStringList files = browser.selectedFiles(); + setTalkFolder(files.at(0)); + } +} + +void InstallTalkWindow::setTalkFolder(QString folder) +{ + ui.lineTalkFolder->clear(); + ui.lineTalkFolder->insert(folder); +} + +void InstallTalkWindow::browseTTS() +{ + QFileDialog browser(this); + if(QFileInfo(ui.TTSpath->text()).isDir()) + browser.setDirectory(ui.TTSpath->text()); + else + browser.setDirectory("/media"); + browser.setReadOnly(true); + browser.setFileMode(QFileDialog::ExistingFile); + browser.setAcceptMode(QFileDialog::AcceptOpen); + if(browser.exec()) { + qDebug() << browser.directory(); + QStringList files = browser.selectedFiles(); + setTTSExec(files.at(0)); + } +} + +void InstallTalkWindow::setTTSExec(QString path) +{ + ui.TTSpath->clear(); + ui.TTSpath->insert(path); +} + +void InstallTalkWindow::browseEncoder() +{ + QFileDialog browser(this); + if(QFileInfo(ui.Encoderpath->text()).isDir()) + browser.setDirectory(ui.Encoderpath->text()); + else + browser.setDirectory("/media"); + browser.setReadOnly(true); + browser.setFileMode(QFileDialog::ExistingFile); + browser.setAcceptMode(QFileDialog::AcceptOpen); + if(browser.exec()) { + qDebug() << browser.directory(); + QStringList files = browser.selectedFiles(); + setEncoderExec(files.at(0)); + } +} + +void InstallTalkWindow::setEncoderExec(QString path) +{ + ui.Encoderpath->clear(); + ui.Encoderpath->insert(path); +} + +void InstallTalkWindow::setEncoderOptions(int index) +{ + QString options = talkcreator->getEncOpts(ui.Encodercbx->itemText(index)); + setEncoderOptions(options); +} +void InstallTalkWindow::setEncoderOptions(QString options) +{ + ui.EncoderOptions->clear(); + ui.EncoderOptions->insert(options); +} +void InstallTalkWindow::setTTSOptions(QString options) +{ + ui.TTSOptions->clear(); + ui.TTSOptions->insert(options); +} +void InstallTalkWindow::setTTSOptions(int index) +{ + QString options = talkcreator->getTTsOpts(ui.TTScbx->itemText(index)); + setEncoderOptions(options); +} + +void InstallTalkWindow::accept() +{ + logger = new ProgressLoggerGui(this); + logger->show(); + + QString folderToTalk = ui.lineTalkFolder->text(); + QString pathEncoder = ui.Encoderpath->text(); + QString pathTTS = ui.TTSpath->text(); + + if(!QFileInfo(folderToTalk).isDir()) + { + logger->addItem(tr("The Folder to Talk is wrong!"),LOGERROR); + logger->abort(); + return; + } + + if(!QFileInfo(pathEncoder).exists()) + { + logger->addItem(tr("Path to Encoder is wrong!"),LOGERROR); + logger->abort(); + return; + } + + if(!QFileInfo(pathTTS).exists()) + { + logger->addItem(tr("Path to TTS is wrong!"),LOGERROR); + logger->abort(); + return; + } + + userSettings->setValue("defaults/folderToTalk",folderToTalk); + userSettings->setValue("defaults/pathEncoder",pathEncoder); + userSettings->setValue("defaults/pathTTS",pathTTS); + + userSettings->sync(); + + talkcreator->setDir(folderToTalk); + talkcreator->setTTSexe(pathTTS); + talkcreator->setEncexe(pathEncoder); + talkcreator->setEncOpts(ui.EncoderOptions->text()); + talkcreator->setTTsOpts(ui.TTSOptions->text()); + talkcreator->setTTsType(ui.TTScbx->currentText()); + talkcreator->setEncType(ui.Encodercbx->currentText()); + + talkcreator->setOverwriteTalk(ui.OverwriteTalk->isChecked()); + talkcreator->setOverwriteWav(ui.OverwriteWav->isChecked()); + talkcreator->setRemoveWav(ui.RemoveWav->isChecked()); + talkcreator->setRecursive(ui.recursive->isChecked()); + talkcreator->setStripExtensions(ui.StripExtensions->isChecked()); + + talkcreator->createTalkFiles(logger); +} + + +void InstallTalkWindow::setDeviceSettings(QSettings *dev) +{ + devices = dev; + qDebug() << "Install::setDeviceSettings:" << devices; + + QStringList encoders; + QStringList encodersOpts; + QStringList encodersTemplates; + + QStringList tts; + QStringList ttsOpts; + QStringList ttsTemplates; + + devices->beginGroup("encoders"); + QStringList keys = devices->allKeys(); + qDebug() << keys; + for(int i=0; i < keys.size();i++) + { + encoders << devices->value(keys.at(i),"null").toString(); + } + qDebug() << encoders; + devices->endGroup(); + for(int i=0; i < encoders.size();i++) + { + devices->beginGroup(encoders.at(i)); + encodersOpts << devices->value("options","null").toString(); + encodersTemplates << devices->value("template","null").toString(); + devices->endGroup(); + } + qDebug() << encodersOpts; + qDebug() << encodersTemplates; + + devices->beginGroup("tts"); + keys = devices->allKeys(); + qDebug() << keys; + for(int i=0; i < keys.size();i++) + { + tts << devices->value(keys.at(i),"null").toString(); + } + qDebug() << tts; + devices->endGroup(); + for(int i= 0; i < tts.size();i++) + { + devices->beginGroup(tts.at(i)); + ttsOpts << devices->value("options","null").toString(); + ttsTemplates << devices->value("template","null").toString(); + devices->endGroup(); + } + qDebug() << ttsOpts; + qDebug() << ttsTemplates; + + talkcreator->setSupportedEnc(encoders); + talkcreator->setSupportedEncOptions(encodersOpts); + talkcreator->setSupportedEncTemplates(encodersTemplates); + + talkcreator->setSupportedTTS(tts); + talkcreator->setSupportedTTSOptions(ttsOpts); + talkcreator->setSupportedTTSTemplates(ttsTemplates); + + ui.Encodercbx->insertItems(0,talkcreator->getSupportedEnc()); + ui.TTScbx->insertItems(0,talkcreator->getSupportedTTS()); + +} + + + + +void InstallTalkWindow::setUserSettings(QSettings *user) +{ + userSettings = user; + + + + setTalkFolder(userSettings->value("defaults/folderToTalk").toString()); + setEncoderExec(userSettings->value("defaults/pathEncoder").toString()); + setTTSExec(userSettings->value("defaults/pathTTS").toString()); +} diff --git a/rbutil/rbutilqt/installtalkwindow.h b/rbutil/rbutilqt/installtalkwindow.h new file mode 100644 index 0000000000..1962d36a52 --- /dev/null +++ b/rbutil/rbutilqt/installtalkwindow.h @@ -0,0 +1,66 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: installtalkwindow.h 14151 2007-08-02 22:27:51Z 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. + * + ****************************************************************************/ + +#ifndef INSTALLTALKWINDOW_H +#define INSTALLTALKWINDOW_H + +#include + +#include + +#include "ui_installtalkfrm.h" +#include "progressloggergui.h" +#include "talkfile.h" + +class InstallTalkWindow : public QDialog +{ + Q_OBJECT + public: + InstallTalkWindow(QWidget *parent = 0); + void setUserSettings(QSettings*); + void setDeviceSettings(QSettings*); + + public slots: + void accept(void); + + private slots: + void browseFolder(void); + void browseTTS(void); + void browseEncoder(void); + + void setTalkFolder(QString folder); + void setTTSExec(QString path); + void setEncoderExec(QString path); + + void setEncoderOptions(int index); + void setTTSOptions(int index); + void setEncoderOptions(QString options); + void setTTSOptions(QString options); + + private: + TalkFileCreator* talkcreator; + Ui::InstallTalkFrm ui; + ProgressLoggerGui* logger; + QSettings *devices; + QSettings *userSettings; + +}; + + +#endif diff --git a/rbutil/rbutilqt/rbutil.ini b/rbutil/rbutilqt/rbutil.ini index c3d962952a..4052ef45e5 100644 --- a/rbutil/rbutilqt/rbutil.ini +++ b/rbutil/rbutilqt/rbutil.ini @@ -337,3 +337,21 @@ resolution=176x220x16 manualname= brand=Sandisk +[encoders] +encoder01 = lame + +[tts] +tts01 = espeak +tts02 = flite + +[lame] +options = "" +template = "\"%exe\" %options \"%input\" \"%output\"" + +[espeak] +options = "" +template = "\"%exe\" %options -w \"%wavfile\" \"%text\"" + +[flite] +options = "" +template = "\"%exe\" %options -o \"%wavfile\" \"%text\"" \ No newline at end of file diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index 5fcfc39d18..8cacdfc78b 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp @@ -26,6 +26,7 @@ #include "configure.h" #include "install.h" #include "installbl.h" +#include "installtalkwindow.h" #include "httpget.h" #include "installbootloader.h" @@ -78,7 +79,9 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent) connect(ui.buttonBootloader, SIGNAL(clicked()), this, SLOT(installBl())); connect(ui.buttonFonts, SIGNAL(clicked()), this, SLOT(installFonts())); connect(ui.buttonGames, SIGNAL(clicked()), this, SLOT(installDoom())); - + connect(ui.buttonTalk, SIGNAL(clicked()), this, SLOT(createTalkFiles())); + + // disable unimplemented stuff ui.buttonThemes->setEnabled(false); ui.buttonSmall->setEnabled(false); @@ -345,3 +348,12 @@ void RbUtilQt::installDoom() } + +void RbUtilQt::createTalkFiles(void) +{ + InstallTalkWindow *installWindow = new InstallTalkWindow(this); + installWindow->setUserSettings(userSettings); + installWindow->setDeviceSettings(devices); + installWindow->show(); + +} diff --git a/rbutil/rbutilqt/rbutilqt.h b/rbutil/rbutilqt/rbutilqt.h index 50bca0b4fa..e23188a136 100644 --- a/rbutil/rbutilqt/rbutilqt.h +++ b/rbutil/rbutilqt/rbutilqt.h @@ -59,6 +59,7 @@ class RbUtilQt : public QMainWindow void installBl(void); void installFonts(void); void installDoom(void); + void createTalkFiles(void); void downloadDone(bool); void downloadDone(int, bool); void downloadInfo(void); diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index 217451cf1b..56d471df65 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro @@ -9,6 +9,8 @@ SOURCES += rbutilqt.cpp \ installbootloader.cpp \ installbl.cpp \ progressloggergui.cpp \ + installtalkwindow.cpp \ + talkfile.cpp \ ../ipodpatcher/ipodpatcher.c \ ../sansapatcher/sansapatcher.c \ irivertools/irivertools.cpp \ @@ -29,6 +31,8 @@ HEADERS += rbutilqt.h \ installzip.h \ installbootloader.h \ installbl.h \ + installtalkwindow.h \ + talkfile.h \ progressloggerinterface.h \ progressloggergui.h \ ../ipodpatcher/ipodpatcher.h \ @@ -55,7 +59,8 @@ FORMS += rbutilqtfrm.ui \ installfrm.ui \ installprogressfrm.ui \ configurefrm.ui \ - installbootloaderfrm.ui + installbootloaderfrm.ui \ + installtalkfrm.ui RESOURCES += rbutilqt.qrc diff --git a/rbutil/rbutilqt/rbutilqt.qrc b/rbutil/rbutilqt/rbutilqt.qrc index e1ba2a2093..3f62c786da 100644 --- a/rbutil/rbutilqt/rbutilqt.qrc +++ b/rbutil/rbutilqt/rbutilqt.qrc @@ -21,6 +21,7 @@ icons/rembootloader_btn.png icons/remrb_btn.png icons/system-search.png + icons/talkfile_btn.png icons/themes_btn.png icons/wizard.xpm diff --git a/rbutil/rbutilqt/rbutilqtfrm.ui b/rbutil/rbutilqt/rbutilqtfrm.ui index c8135de184..afa3bb0e76 100644 --- a/rbutil/rbutilqt/rbutilqtfrm.ui +++ b/rbutil/rbutilqt/rbutilqtfrm.ui @@ -130,7 +130,7 @@ p, li { white-space: pre-wrap; } - 0 + 2 @@ -436,7 +436,7 @@ p, li { white-space: pre-wrap; } - + Qt::Vertical @@ -449,7 +449,7 @@ p, li { white-space: pre-wrap; } - + Qt::Vertical @@ -462,6 +462,33 @@ p, li { white-space: pre-wrap; } + + + + Install Talk files + + + :/icons/icons/talkfile_btn.png + + + + 56 + 46 + + + + + + + + <html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Create Talk Files</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-weight:600;"><span style=" font-weight:400;">Talkfiles are needed to let Rockbox speak File and Foldernames</span></p></body></html> + + + @@ -675,7 +702,7 @@ p, li { white-space: pre-wrap; } 0 0 600 - 29 + 21 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 @@ +/*************************************************************************** + * __________ __ ___. + * 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); +} + diff --git a/rbutil/rbutilqt/talkfile.h b/rbutil/rbutilqt/talkfile.h new file mode 100644 index 0000000000..20bf1e5a70 --- /dev/null +++ b/rbutil/rbutilqt/talkfile.h @@ -0,0 +1,105 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * + * Copyright (C) 2007 by Dominik Wenger + * $Id: talkfile.h 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. + * + ****************************************************************************/ + + +#ifndef TALKFILE_H +#define TALKFILE_H + +#include "progressloggerinterface.h" + +class TalkFileCreator :public QObject +{ + Q_OBJECT + +public: + TalkFileCreator(QObject* parent=0); + + bool createTalkFiles(ProgressloggerInterface* logger); + + void setTTSexe(QString exe){m_TTSexec=exe;} + void setEncexe(QString exe){m_EncExec=exe;} + + void setSupportedTTS(QStringList list) {m_supportedTTS=list;} + void setSupportedTTSOptions(QStringList list) {m_supportedTTSOpts=list;} + void setSupportedTTSTemplates(QStringList list) {m_supportedTTSTemplates=list;} + + QStringList getSupportedTTS(){return m_supportedTTS;} + void setTTsType(QString tts); + QString getTTsOpts(QString ttsname); + void setTTsOpts(QString opts) {m_TTSOpts=opts;} + + void setSupportedEnc(QStringList list) {m_supportedEnc=list;} + void setSupportedEncOptions(QStringList list) {m_supportedEncOpts=list;} + void setSupportedEncTemplates(QStringList list) {m_supportedEncTemplates=list;} + + QStringList getSupportedEnc(){return m_supportedEnc;} + void setEncType(QString enc); + QString getEncOpts(QString encname); + void setEncOpts(QString opts) {m_EncOpts=opts;} + + void setDir(QString dir){m_dir = dir; } + + void setOverwriteTalk(bool ov) {m_overwriteTalk = ov;} + void setOverwriteWav(bool ov) {m_overwriteWav = ov;} + void setRemoveWav(bool ov) {m_removeWav = ov;} + void setRecursive(bool ov) {m_recursive = ov;} + void setStripExtensions(bool ov) {m_stripExtensions = ov;} + +private slots: + void abort(); + +private: + + bool initTTS(); + bool stopTTS(); + bool initEncoder(); + + bool encode(QString input,QString output); + bool voice(QString text,QString wavfile); + + QString m_dir; + + QString m_curTTS; + QString m_TTSexec; + QStringList m_supportedTTS; + QStringList m_supportedTTSOpts; + QStringList m_supportedTTSTemplates; + QString m_TTSOpts; + QString m_curTTSTemplate; + + QString m_curEnc; + QString m_EncExec; + QStringList m_supportedEnc; + QStringList m_supportedEncOpts; + QStringList m_supportedEncTemplates; + QString m_EncOpts; + QString m_curEncTemplate; + + bool m_overwriteTalk; + bool m_overwriteWav; + bool m_removeWav; + bool m_recursive; + bool m_stripExtensions; + + ProgressloggerInterface* m_logger; + + bool m_abort; +}; + +#endif -- cgit v1.2.3