1
0
Fork 0
forked from len0rd/rockbox

rbutil: reworked configuration of TTS engines to the new Style.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15932 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Wenger 2007-12-15 13:13:57 +00:00
parent 1e489e53b8
commit bebddd42c2
14 changed files with 920 additions and 352 deletions

View file

@ -24,6 +24,7 @@
#include "ui_configurefrm.h"
#include "browsedirtree.h"
#include "encoders.h"
#include "tts.h"
#include <stdio.h>
#if defined(Q_OS_WIN32)
@ -75,9 +76,9 @@ Config::Config(QWidget *parent,int index) : QDialog(parent)
connect(ui.buttonAutodetect,SIGNAL(clicked()),this,SLOT(autodetect()));
connect(ui.buttonCacheBrowse, SIGNAL(clicked()), this, SLOT(browseCache()));
connect(ui.buttonCacheClear, SIGNAL(clicked()), this, SLOT(cacheClear()));
connect(ui.browseTts, SIGNAL(clicked()), this, SLOT(browseTts()));
connect(ui.configTts, SIGNAL(clicked()), this, SLOT(configTts()));
connect(ui.configEncoder, SIGNAL(clicked()), this, SLOT(configEnc()));
connect(ui.comboTts, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsOpts(int)));
connect(ui.comboTts, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTtsState(int)));
connect(ui.comboEncoder, SIGNAL(currentIndexChanged(int)), this, SLOT(updateEncState(int)));
}
@ -131,20 +132,7 @@ void Config::accept()
userSettings->setValue("offline", ui.cacheOfflineMode->isChecked());
// tts settings
QString preset;
preset = ui.comboTts->itemData(ui.comboTts->currentIndex(), Qt::UserRole).toString();
userSettings->setValue("ttspreset", preset);
userSettings->beginGroup(preset);
if(QFileInfo(ui.ttsExecutable->text()).exists())
userSettings->setValue("binary", ui.ttsExecutable->text());
userSettings->setValue("options", ui.ttsOptions->text());
userSettings->setValue("language", ui.ttsLanguage->text());
devices->beginGroup(preset);
userSettings->setValue("template", devices->value("template").toString());
userSettings->setValue("type", devices->value("tts").toString());
devices->endGroup();
userSettings->endGroup();
userSettings->setValue("tts",ui.comboTts->currentText());
//encoder settings
userSettings->setValue("encoder",ui.comboEncoder->currentText());
@ -316,86 +304,34 @@ void Config::setDevices(QSettings *dev)
updateEncState(index);
//tts
devices->beginGroup("tts");
QStringList keys = devices->allKeys();
for(int i=0; i < keys.size();i++)
{
devices->endGroup();
devices->beginGroup(keys.at(i));
QString os = devices->value("os").toString();
devices->endGroup();
devices->beginGroup("tts");
if(os == "all")
ui.comboTts->addItem(devices->value(keys.at(i), "null").toString(), keys.at(i));
#if defined(Q_OS_WIN32)
if(os == "win32")
ui.comboTts->addItem(devices->value(keys.at(i), "null").toString(), keys.at(i));
#endif
}
devices->endGroup();
index = ui.comboTts->findData(userSettings->value("ttspreset").toString(),
Qt::UserRole, Qt::MatchExactly);
ui.comboTts->addItems(getTTSList());
//update index of combobox
index = ui.comboTts->findText(userSettings->value("tts").toString(),Qt::MatchExactly);
if(index < 0) index = 0;
ui.comboTts->setCurrentIndex(index);
updateTtsOpts(index);
updateTtsState(index);
}
void Config::updateTtsOpts(int index)
void Config::updateTtsState(int index)
{
bool edit;
QString e;
bool needsLanguageCfg;
QString c = ui.comboTts->itemData(index, Qt::UserRole).toString();
devices->beginGroup(c);
edit = devices->value("edit").toBool();
needsLanguageCfg = devices->value("needslanguagecfg").toBool();
ui.ttsLanguage->setVisible(needsLanguageCfg);
ui.ttsLanguageLabel->setVisible(needsLanguageCfg);
ui.ttsOptions->setText(devices->value("options").toString());
ui.ttsOptions->setEnabled(devices->value("edit").toBool());
e = devices->value("tts").toString();
devices->endGroup();
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
#elif defined(Q_OS_WIN)
QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
#endif
qDebug() << path;
ui.ttsExecutable->setEnabled(true);
for(int i = 0; i < path.size(); i++) {
QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + e;
#if defined(Q_OS_WIN)
executable += ".exe";
QStringList ex = executable.split("\"", QString::SkipEmptyParts);
executable = ex.join("");
#endif
qDebug() << executable;
if(QFileInfo(executable).isExecutable()) {
ui.ttsExecutable->setText(QDir::toNativeSeparators(executable));
// disallow changing the detected path if non-customizable profile
if(!edit)
ui.ttsExecutable->setEnabled(false);
break;
}
}
QString ttsName = ui.comboTts->itemText(index);
TTSBase* tts = getTTS(ttsName);
tts->setUserCfg(userSettings);
//user settings
userSettings->beginGroup(c);
QString temp = userSettings->value("binary","null").toString();
if(temp != "null") ui.ttsExecutable->setText(temp);
temp = userSettings->value("options","null").toString();
if(temp != "null") ui.ttsOptions->setText(temp);
temp = userSettings->value("language","null").toString();
if(temp != "null") ui.ttsLanguage->setText(temp);
userSettings->endGroup();
if(tts->configOk())
{
ui.configTTSstatus->setText("Configuration OK");
ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/go-next.png")));
}
else
{
ui.configTTSstatus->setText("Configuration INVALID");
ui.configTTSstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/dialog-error.png")));
}
}
void Config::updateEncState(int index)
@ -406,13 +342,13 @@ void Config::updateEncState(int index)
if(enc->configOk())
{
ui.configstatus->setText("Configuration OK");
ui.configstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/go-next.png")));
ui.configEncstatus->setText("Configuration OK");
ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/go-next.png")));
}
else
{
ui.configstatus->setText("Configuration INVALID");
ui.configstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/dialog-error.png")));
ui.configEncstatus->setText("Configuration INVALID");
ui.configEncstatusimg->setPixmap(QPixmap(QString::fromUtf8(":/icons/icons/dialog-error.png")));
}
}
@ -676,24 +612,13 @@ void Config::cacheClear()
}
void Config::browseTts()
void Config::configTts()
{
BrowseDirtree browser(this);
browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
if(QFileInfo(ui.ttsExecutable->text()).isDir())
{
browser.setDir(ui.ttsExecutable->text());
}
if(browser.exec() == QDialog::Accepted)
{
qDebug() << browser.getSelected();
QString exe = browser.getSelected();
if(!QFileInfo(exe).exists())
return;
ui.ttsExecutable->setText(exe);
}
TTSBase* tts =getTTS(ui.comboTts->currentText());
tts->setUserCfg(userSettings);
tts->showCfg();
updateTtsState(ui.comboTts->currentIndex());
}

View file

@ -64,9 +64,9 @@ class Config : public QDialog
void setMountpoint(QString);
void setCache(QString);
void cacheClear(void);
void browseTts(void);
void configTts(void);
void configEnc(void);
void updateTtsOpts(int);
void updateTtsState(int);
void updateEncState(int);
};

View file

@ -358,8 +358,8 @@
<attribute name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/audio-input-microphone.png</iconset>
</attribute>
<layout class="QGridLayout" >
<item row="0" column="0" >
<layout class="QVBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBox_2" >
<property name="title" >
<string>TTS Engine</string>
@ -368,66 +368,54 @@
<item row="0" column="0" >
<widget class="QLabel" name="labelTts" >
<property name="text" >
<string>&amp;Select TTS profile</string>
<string>&amp;Select TTS Engine</string>
</property>
<property name="buddy" >
<cstring>comboTts</cstring>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2" >
<item row="0" column="1" colspan="3" >
<widget class="QComboBox" name="comboTts" />
</item>
<item row="1" column="0" >
<widget class="QLabel" name="labelTtsExecutable" >
<property name="text" >
<string>TTS executable</string>
</property>
<property name="buddy" >
<cstring>ttsExecutable</cstring>
<string>Configure TTS Engine</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QLineEdit" name="ttsExecutable" />
<widget class="QLabel" name="configTTSstatus" >
<property name="text" >
<string>Configuration invalid !</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="browseTts" >
<widget class="QLabel" name="configTTSstatusimg" >
<property name="text" >
<string>&amp;Browse</string>
<string/>
</property>
<property name="pixmap" >
<pixmap resource="rbutilqt.qrc" >:/icons/icons/dialog-error.png</pixmap>
</property>
</widget>
</item>
<item row="1" column="3" >
<widget class="QPushButton" name="configTts" >
<property name="text" >
<string>Configure &amp;TTS</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/edit-find.png</iconset>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="labelTtsOptions" >
<property name="text" >
<string>TTS Options</string>
</property>
<property name="buddy" >
<cstring>ttsOptions</cstring>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2" >
<widget class="QLineEdit" name="ttsOptions" />
</item>
<item row="3" column="0" >
<widget class="QLabel" name="ttsLanguageLabel" >
<property name="text" >
<string>TTS Language</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2" >
<widget class="QLineEdit" name="ttsLanguage" />
</item>
</layout>
</widget>
</item>
<item row="1" column="0" >
<item>
<widget class="QGroupBox" name="groupBox_3" >
<property name="title" >
<string>Encoder Engine</string>
@ -454,14 +442,14 @@
</widget>
</item>
<item row="1" column="1" >
<widget class="QLabel" name="configstatus" >
<widget class="QLabel" name="configEncstatus" >
<property name="text" >
<string>Configuration invalid !</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QLabel" name="configstatusimg" >
<widget class="QLabel" name="configEncstatusimg" >
<property name="text" >
<string/>
</property>
@ -473,7 +461,7 @@
<item row="1" column="3" >
<widget class="QPushButton" name="configEncoder" >
<property name="text" >
<string>&amp;Configure</string>
<string> Configure &amp;Enc</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/edit-find.png</iconset>
@ -483,15 +471,15 @@
</layout>
</widget>
</item>
<item row="2" column="0" >
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>226</width>
<height>51</height>
<width>458</width>
<height>131</height>
</size>
</property>
</spacer>

View file

@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: talkfile.cpp 15212 2007-10-19 21:49:07Z domonoky $
* $Id: encoders.cpp 15212 2007-10-19 21:49:07Z 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.
@ -33,6 +33,9 @@ void initEncoderList()
// function to get a specific encoder
EncBase* getEncoder(QString encname)
{
// init list if its empty
if(encoderList.count() == 0) initEncoderList();
QString encoder = encoderList.key(encname);
// check cache
@ -59,6 +62,9 @@ EncBase* getEncoder(QString encname)
// get the list of encoders, nice names
QStringList getEncoderList()
{
// init list if its empty
if(encoderList.count() == 0) initEncoderList();
QStringList encList;
QMapIterator<QString, QString> i(encoderList);
while (i.hasNext()) {

View file

@ -7,7 +7,7 @@
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: talkfile.h 15212 2007-10-19 21:49:07Z domonoky $
* $Id: encoders.h 15212 2007-10-19 21:49:07Z 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.
@ -45,19 +45,19 @@ class EncBase : public QDialog
Q_OBJECT
public:
EncBase(QWidget *parent );
virtual ~EncBase(){}
virtual bool encode(QString input,QString output) = 0;
virtual bool start() = 0;
virtual bool stop() = 0;
virtual void showCfg() = 0;
virtual bool configOk()=0;
virtual bool encode(QString input,QString output){return false;}
virtual bool start(){return false;}
virtual bool stop(){return false;}
virtual void showCfg(){}
virtual bool configOk(){return false;}
void setUserCfg(QSettings *uSettings){userSettings = uSettings;}
public slots:
virtual void accept(void)=0;
virtual void reject(void)=0;
virtual void reset(void)=0;
virtual void accept(void){}
virtual void reject(void){}
virtual void reset(void){}
protected:

View file

@ -79,26 +79,7 @@ void InstallTalkWindow::accept()
connect(logger,SIGNAL(closed()),this,SLOT(close()));
QString folderToTalk = ui.lineTalkFolder->text();
// tts
QString preset = userSettings->value("ttspreset").toString();
userSettings->beginGroup(preset);
QString pathTTS = userSettings->value("binary").toString();
QString ttsOpts = userSettings->value("options").toString();
QString ttsLanguage = userSettings->value("language").toString();
QString ttsTemplate = userSettings->value("template").toString();
QString ttsType =userSettings->value("type").toString();
userSettings->endGroup();
//encoder
QString encoderPreset = userSettings->value("encpreset").toString();
userSettings->beginGroup(encoderPreset);
QString pathEncoder = userSettings->value("binary").toString();
QString encOpts = userSettings->value("options").toString();
QString encTemplate = userSettings->value("template").toString();
QString encType =userSettings->value("type").toString();
userSettings->endGroup();
if(!QFileInfo(folderToTalk).isDir())
{
logger->addItem(tr("The Folder to Talk is wrong!"),LOGERROR);
@ -106,20 +87,6 @@ void InstallTalkWindow::accept()
return;
}
if(!QFileInfo(pathEncoder).isExecutable())
{
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("last_talked_folder", folderToTalk);
userSettings->sync();
@ -127,11 +94,6 @@ void InstallTalkWindow::accept()
talkcreator->setUserSettings(userSettings);
talkcreator->setDir(QDir(folderToTalk));
talkcreator->setMountPoint(userSettings->value("mountpoint").toString());
talkcreator->setTTSexe(pathTTS);
talkcreator->setTTsOpts(ttsOpts);
talkcreator->setTTsLanguage(ttsLanguage);
talkcreator->setTTsType(ttsType);
talkcreator->setTTsTemplate(ttsTemplate);
talkcreator->setOverwriteTalk(ui.OverwriteTalk->isChecked());
talkcreator->setOverwriteWav(ui.OverwriteWav->isChecked());
@ -150,14 +112,13 @@ void InstallTalkWindow::setDeviceSettings(QSettings *dev)
devices = dev;
qDebug() << "Install::setDeviceSettings:" << devices;
QString profile;
profile = userSettings->value("ttspreset", "none").toString();
devices->beginGroup("tts");
ui.labelTtsProfile->setText(tr("TTS Profile: <b>%1</b>")
.arg(devices->value(profile, tr("Invalid TTS profile!")).toString()));
qDebug() << profile;
devices->endGroup();
QString ttsName = userSettings->value("tts", "none").toString();
TTSBase* tts = getTTS(ttsName);
tts->setUserCfg(userSettings);
if(tts->configOk())
ui.labelTtsProfile->setText(tr("Selected TTS engine : <b>%1</b>").arg(ttsName));
else
ui.labelTtsProfile->setText(tr("Selected TTS Engine: <b>%1</b>").arg("Invalid TTS configuration!"));
QString encoder = userSettings->value("encoder", "none").toString();
EncBase* enc = getEncoder(encoder);

View file

@ -31,7 +31,6 @@
#include "installthemes.h"
#include "uninstallwindow.h"
#include "browseof.h"
#include "encoders.h"
#if defined(Q_OS_LINUX)
#include <stdio.h>
@ -120,7 +119,6 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent)
initIpodpatcher();
initSansapatcher();
downloadInfo();
initEncoderList();
}

View file

@ -36,7 +36,8 @@ SOURCES += rbutilqt.cpp \
utils.cpp \
browseof.cpp \
preview.cpp \
encoders.cpp
encoders.cpp \
tts.cpp
HEADERS += rbutilqt.h \
install.h \
@ -73,7 +74,8 @@ HEADERS += rbutilqt.h \
utils.h \
browseof.h \
preview.h \
encoders.h
encoders.h \
tts.h
# Needed by QT on Win
INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex
@ -106,7 +108,9 @@ FORMS += rbutilqtfrm.ui \
browseoffrm.ui \
previewfrm.ui \
rbspeexcfgfrm.ui \
encexescfgfrm.ui
encexescfgfrm.ui \
ttsexescfgfrm.ui \
sapicfgfrm.ui
RESOURCES += rbutilqt.qrc

View file

@ -0,0 +1,168 @@
<ui version="4.0" >
<class>SapiCfgFrm</class>
<widget class="QDialog" name="SapiCfgFrm" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>511</width>
<height>242</height>
</rect>
</property>
<property name="windowTitle" >
<string>Configuration</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Configure TTS Engine</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>255</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Path to TTS Engine</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLineEdit" name="ttspath" />
</item>
<item>
<widget class="QPushButton" name="browse" >
<property name="text" >
<string>&amp;Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>TTS options</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ttsoptions" />
</item>
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Language</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ttslanguage" />
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="reset" >
<property name="text" >
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonOk" >
<property name="text" >
<string>&amp;Ok</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/go-next.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCancel" >
<property name="text" >
<string>&amp;Cancel</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/process-stop.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="rbutilqt.qrc" />
</resources>
<connections>
<connection>
<sender>buttonOk</sender>
<signal>clicked()</signal>
<receiver>SapiCfgFrm</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>253</x>
<y>147</y>
</hint>
<hint type="destinationlabel" >
<x>203</x>
<y>86</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonCancel</sender>
<signal>clicked()</signal>
<receiver>SapiCfgFrm</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>352</x>
<y>147</y>
</hint>
<hint type="destinationlabel" >
<x>203</x>
<y>86</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View file

@ -30,15 +30,9 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
m_logger = logger;
m_logger->addItem("Starting Talk file generation",LOGINFO);
if(m_curTTS == "sapi")
m_tts = new TTSSapi();
else
m_tts = new TTSExes();
m_tts->setTTSexe(m_TTSexec);
m_tts->setTTsOpts(m_TTSOpts);
m_tts->setTTsLanguage(m_TTSLanguage);
m_tts->setTTsTemplate(m_curTTSTemplate);
//tts
m_tts = getTTS(userSettings->value("tts").toString());
m_tts->setUserCfg(userSettings);
if(!m_tts->start())
{
@ -183,68 +177,3 @@ void TalkFileCreator::abort()
m_abort = true;
}
bool TTSSapi::start()
{
QFileInfo tts(m_TTSexec);
if(!tts.exists())
return false;
// create the voice process
QString execstring = m_TTSTemplate;
execstring.replace("%exe",m_TTSexec);
execstring.replace("%options",m_TTSOpts);
execstring.replace("%lang",m_TTSLanguage);
qDebug() << "init" << execstring;
voicescript = new QProcess(NULL);
voicescript->start(execstring);
if(!voicescript->waitForStarted())
return false;
return true;
}
bool TTSSapi::voice(QString text,QString wavfile)
{
QString query = "SPEAK\t"+wavfile+"\t"+text+"\r\n";
qDebug() << "voicing" << query;
voicescript->write(query.toLocal8Bit());
voicescript->write("SYNC\tbla\r\n");
voicescript->waitForReadyRead();
return true;
}
bool TTSSapi::stop()
{
QString query = "QUIT\r\n";
voicescript->write(query.toLocal8Bit());
voicescript->waitForFinished();
delete voicescript;
return true;
}
bool TTSExes::start()
{
QFileInfo tts(m_TTSexec);
qDebug() << "ttsexe init";
if(tts.exists())
{
return true;
}
else
{
return false;
}
}
bool TTSExes::voice(QString text,QString wavfile)
{
QString execstring = m_TTSTemplate;
execstring.replace("%exe",m_TTSexec);
execstring.replace("%options",m_TTSOpts);
execstring.replace("%wavfile",wavfile);
execstring.replace("%text",text);
//qDebug() << "voicing" << execstring;
QProcess::execute(execstring);
return true;
}

View file

@ -25,30 +25,7 @@
#include "progressloggerinterface.h"
#include "encoders.h"
class TTSBase : public QObject
{
Q_OBJECT
public:
TTSBase(){}
virtual ~TTSBase(){}
virtual bool voice(QString text,QString wavfile){(void)text; (void)wavfile; return false;}
virtual bool start(){return false;}
virtual bool stop(){return false;}
void setTTSexe(QString exe){m_TTSexec=exe;}
void setTTsOpts(QString opts) {m_TTSOpts=opts;}
void setTTsLanguage(QString language) {m_TTSLanguage = language;}
void setTTsTemplate(QString t) { m_TTSTemplate = t; }
protected:
QString m_TTSexec;
QString m_TTSOpts;
QString m_TTSTemplate;
QString m_TTSLanguage;
};
#include "tts.h"
class TalkFileCreator :public QObject
{
@ -61,14 +38,6 @@ public:
void setUserSettings(QSettings* setting) { userSettings = setting;}
void setTTSexe(QString exe){m_TTSexec=exe;}
void setTTsType(QString tts) { m_curTTS = tts; }
void setTTsOpts(QString opts) {m_TTSOpts=opts;}
void setTTsLanguage(QString language) {m_TTSLanguage = language;}
void setTTsTemplate(QString t) { m_curTTSTemplate = t; }
void setDir(QDir dir){m_dir = dir; }
void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; }
@ -90,12 +59,7 @@ private:
QDir m_dir;
QString m_mountpoint;
QString m_curTTS;
QString m_TTSexec;
QString m_TTSOpts;
QString m_TTSLanguage;
QString m_curTTSTemplate;
bool m_overwriteTalk;
bool m_overwriteWav;
bool m_removeWav;
@ -109,31 +73,6 @@ private:
bool m_abort;
};
class TTSSapi : public TTSBase
{
public:
TTSSapi() {};
virtual bool voice(QString text,QString wavfile);
virtual bool start();
virtual bool stop();
private:
QProcess* voicescript;
};
class TTSExes : public TTSBase
{
public:
TTSExes() {};
virtual bool voice(QString text,QString wavfile);
virtual bool start();
virtual bool stop() {return true;}
private:
};
#endif

376
rbutil/rbutilqt/tts.cpp Normal file
View file

@ -0,0 +1,376 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: tts.cpp 15212 2007-10-19 21:49:07Z 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 "tts.h"
#include "browsedirtree.h"
static QMap<QString,QString> ttsList;
static QMap<QString,TTSBase*> ttsCache;
void initTTSList()
{
ttsList["espeak"] = "Espeak TTS Engine";
ttsList["flite"] = "Flite TTS Engine";
ttsList["swift"] = "Swift TTS Engine";
#if defined(Q_OS_WIN)
ttsList["sapi"] = "Sapi 5 TTS Engine";
#endif
}
// function to get a specific encoder
TTSBase* getTTS(QString ttsname)
{
// init list if its empty
if(ttsList.count() == 0) initTTSList();
QString ttsName = ttsList.key(ttsname);
// check cache
if(ttsCache.contains(ttsName))
return ttsCache.value(ttsName);
TTSBase* tts;
if(ttsName == "sapi")
{
tts = new TTSSapi();
ttsCache[ttsName] = tts;
return tts;
}
else
{
tts = new TTSExes(ttsName);
ttsCache[ttsName] = tts;
return tts;
}
}
// get the list of encoders, nice names
QStringList getTTSList()
{
// init list if its empty
if(ttsList.count() == 0) initTTSList();
QStringList ttsNameList;
QMapIterator<QString, QString> i(ttsList);
while (i.hasNext()) {
i.next();
ttsNameList << i.value();
}
return ttsNameList;
}
/*********************************************************************
* TTS Base
**********************************************************************/
TTSBase::TTSBase(QWidget *parent): QDialog(parent)
{
}
/*********************************************************************
* General TTS Exes
**********************************************************************/
TTSExes::TTSExes(QString name,QWidget *parent) : TTSBase(parent)
{
m_name = name;
m_TemplateMap["espeak"] = "\"%exe\" \"%options\" -w \"%wavfile\" \"%text\"";
m_TemplateMap["flite"] = "\"%exe\" \"%options\" -o \"%wavfile\" \"%text\"";
m_TemplateMap["swift"] = "\"%exe\" \"%options\" -o \"%wavfile\" \"%text\"";
ui.setupUi(this);
this->hide();
connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
}
bool TTSExes::start()
{
userSettings->beginGroup(m_name);
m_TTSexec = userSettings->value("ttspath","").toString();
m_TTSOpts = userSettings->value("ttsoptions","").toString();
userSettings->endGroup();
m_TTSTemplate = m_TemplateMap.value(m_name);
QFileInfo tts(m_TTSexec);
if(tts.exists())
{
return true;
}
else
{
return false;
}
}
bool TTSExes::voice(QString text,QString wavfile)
{
QString execstring = m_TTSTemplate;
execstring.replace("%exe",m_TTSexec);
execstring.replace("%options",m_TTSOpts);
execstring.replace("%wavfile",wavfile);
execstring.replace("%text",text);
//qDebug() << "voicing" << execstring;
QProcess::execute(execstring);
return true;
}
void TTSExes::reset()
{
ui.ttspath->setText("");
ui.ttsoptions->setText("");
}
void TTSExes::showCfg()
{
// try to get config from settings
userSettings->beginGroup(m_name);
QString exepath =userSettings->value("ttspath","").toString();
ui.ttsoptions->setText(userSettings->value("ttsoptions","").toString());
userSettings->endGroup();
if(exepath == "")
{
//try autodetect tts
#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
QStringList path = QString(getenv("PATH")).split(":", QString::SkipEmptyParts);
#elif defined(Q_OS_WIN)
QStringList path = QString(getenv("PATH")).split(";", QString::SkipEmptyParts);
#endif
qDebug() << path;
for(int i = 0; i < path.size(); i++)
{
QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name;
#if defined(Q_OS_WIN)
executable += ".exe";
QStringList ex = executable.split("\"", QString::SkipEmptyParts);
executable = ex.join("");
#endif
qDebug() << executable;
if(QFileInfo(executable).isExecutable())
{
exepath= QDir::toNativeSeparators(executable);
break;
}
}
}
ui.ttspath->setText(exepath);
//show dialog
this->exec();
}
void TTSExes::accept(void)
{
if(userSettings != NULL)
{
//save settings in user config
userSettings->beginGroup(m_name);
userSettings->setValue("ttspath",ui.ttspath->text());
userSettings->setValue("ttsoptions",ui.ttsoptions->text());
userSettings->endGroup();
// sync settings
userSettings->sync();
}
this->close();
}
void TTSExes::reject(void)
{
this->close();
}
bool TTSExes::configOk()
{
userSettings->beginGroup(m_name);
QString path = userSettings->value("ttspath","").toString();
userSettings->endGroup();
if (QFileInfo(path).exists())
return true;
return false;
}
void TTSExes::browse()
{
BrowseDirtree browser(this);
browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
if(QFileInfo(ui.ttspath->text()).isDir())
{
browser.setDir(ui.ttspath->text());
}
if(browser.exec() == QDialog::Accepted)
{
qDebug() << browser.getSelected();
QString exe = browser.getSelected();
if(!QFileInfo(exe).isExecutable())
return;
ui.ttspath->setText(exe);
}
}
/*********************************************************************
* TTS Sapi
**********************************************************************/
TTSSapi::TTSSapi(QWidget *parent) : TTSBase(parent)
{
m_TTSTemplate = "cscript //nologo \"%exe\" /language:%lang \"%options\"";
defaultLanguage ="english";
ui.setupUi(this);
this->hide();
connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
}
bool TTSSapi::start()
{
userSettings->beginGroup("sapi");
m_TTSexec = userSettings->value("ttspath","").toString();
m_TTSOpts = userSettings->value("ttsoptions","").toString();
m_TTSLanguage =userSettings->value("ttslanguage","").toString();
userSettings->endGroup();
QFileInfo tts(m_TTSexec);
if(!tts.exists())
return false;
// create the voice process
QString execstring = m_TTSTemplate;
execstring.replace("%exe",m_TTSexec);
execstring.replace("%options",m_TTSOpts);
execstring.replace("%lang",m_TTSLanguage);
qDebug() << "init" << execstring;
voicescript = new QProcess(NULL);
voicescript->start(execstring);
if(!voicescript->waitForStarted())
return false;
return true;
}
bool TTSSapi::voice(QString text,QString wavfile)
{
QString query = "SPEAK\t"+wavfile+"\t"+text+"\r\n";
qDebug() << "voicing" << query;
voicescript->write(query.toLocal8Bit());
voicescript->write("SYNC\tbla\r\n");
voicescript->waitForReadyRead();
return true;
}
bool TTSSapi::stop()
{
QString query = "QUIT\r\n";
voicescript->write(query.toLocal8Bit());
voicescript->waitForFinished();
delete voicescript;
return true;
}
void TTSSapi::reset()
{
ui.ttspath->setText("");
ui.ttsoptions->setText("");
ui.ttslanguage->setText(defaultLanguage);
}
void TTSSapi::showCfg()
{
// try to get config from settings
userSettings->beginGroup("sapi");
QString exepath =userSettings->value("ttspath","").toString();
ui.ttsoptions->setText(userSettings->value("ttsoptions","").toString());
ui.ttslanguage->setText(userSettings->value("ttsoptions",defaultLanguage).toString());
userSettings->endGroup();
ui.ttspath->setText(exepath);
//show dialog
this->exec();
}
void TTSSapi::accept(void)
{
if(userSettings != NULL)
{
//save settings in user config
userSettings->beginGroup("sapi");
userSettings->setValue("ttspath",ui.ttspath->text());
userSettings->setValue("ttsoptions",ui.ttsoptions->text());
userSettings->setValue("ttslanguage",ui.ttslanguage->text());
userSettings->endGroup();
// sync settings
userSettings->sync();
}
this->close();
}
void TTSSapi::reject(void)
{
this->close();
}
bool TTSSapi::configOk()
{
userSettings->beginGroup("sapi");
QString path = userSettings->value("ttspath","").toString();
userSettings->endGroup();
if (QFileInfo(path).exists())
return true;
return false;
}
void TTSSapi::browse()
{
BrowseDirtree browser(this);
browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
if(QFileInfo(ui.ttspath->text()).isDir())
{
browser.setDir(ui.ttspath->text());
}
if(browser.exec() == QDialog::Accepted)
{
qDebug() << browser.getSelected();
QString exe = browser.getSelected();
if(!QFileInfo(exe).isExecutable())
return;
ui.ttspath->setText(exe);
}
}

116
rbutil/rbutilqt/tts.h Normal file
View file

@ -0,0 +1,116 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id: tts.h 15212 2007-10-19 21:49:07Z 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 TTS_H
#define TTS_H
#include "ui_ttsexescfgfrm.h"
#include "ui_sapicfgfrm.h"
#include <QtGui>
class TTSBase;
//inits the tts List
void initTTSList();
// function to get a specific tts
TTSBase* getTTS(QString ttsname);
// get the list of tts, nice names
QStringList getTTSList();
class TTSBase : public QDialog
{
Q_OBJECT
public:
TTSBase(QWidget *parent );
virtual bool voice(QString text,QString wavfile) {return false;}
virtual bool start(){return false;}
virtual bool stop(){return false;}
virtual void showCfg(){}
virtual bool configOk(){return false;}
void setUserCfg(QSettings *uSettings){userSettings = uSettings;}
public slots:
virtual void accept(void){}
virtual void reject(void){}
virtual void reset(void){}
protected:
QSettings *userSettings;
};
class TTSSapi : public TTSBase
{
Q_OBJECT
public:
TTSSapi(QWidget *parent = NULL);
virtual bool voice(QString text,QString wavfile);
virtual bool start();
virtual bool stop();
virtual void showCfg();
virtual bool configOk();
public slots:
virtual void accept(void);
virtual void reject(void);
virtual void reset(void);
void browse(void);
private:
Ui::SapiCfgFrm ui;
QProcess* voicescript;
QString defaultLanguage;
QString m_TTSexec;
QString m_TTSOpts;
QString m_TTSTemplate;
QString m_TTSLanguage;
};
class TTSExes : public TTSBase
{
Q_OBJECT
public:
TTSExes(QString name,QWidget *parent = NULL);
virtual bool voice(QString text,QString wavfile);
virtual bool start();
virtual bool stop() {return true;}
virtual void showCfg();
virtual bool configOk();
public slots:
virtual void accept(void);
virtual void reject(void);
virtual void reset(void);
void browse(void);
private:
Ui::TTSExesCfgFrm ui;
QString m_name;
QString m_TTSexec;
QString m_TTSOpts;
QString m_TTSTemplate;
QMap<QString,QString> m_TemplateMap;
};
#endif

View file

@ -0,0 +1,158 @@
<ui version="4.0" >
<class>TTSExesCfgFrm</class>
<widget class="QDialog" name="TTSExesCfgFrm" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>463</width>
<height>214</height>
</rect>
</property>
<property name="windowTitle" >
<string>Configuration</string>
</property>
<layout class="QHBoxLayout" >
<item>
<widget class="QGroupBox" name="groupBox" >
<property name="title" >
<string>Configure TTS Engine</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QLabel" name="label" >
<property name="sizePolicy" >
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
<horstretch>0</horstretch>
<verstretch>255</verstretch>
</sizepolicy>
</property>
<property name="text" >
<string>Path to TTS Engine</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QLineEdit" name="ttspath" />
</item>
<item>
<widget class="QPushButton" name="browse" >
<property name="text" >
<string>&amp;Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>TTS options</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ttsoptions" />
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="reset" >
<property name="text" >
<string>Reset</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonOk" >
<property name="text" >
<string>&amp;Ok</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/go-next.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonCancel" >
<property name="text" >
<string>&amp;Cancel</string>
</property>
<property name="icon" >
<iconset resource="rbutilqt.qrc" >:/icons/icons/process-stop.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="rbutilqt.qrc" />
</resources>
<connections>
<connection>
<sender>buttonOk</sender>
<signal>clicked()</signal>
<receiver>TTSExesCfgFrm</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel" >
<x>253</x>
<y>147</y>
</hint>
<hint type="destinationlabel" >
<x>203</x>
<y>86</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonCancel</sender>
<signal>clicked()</signal>
<receiver>TTSExesCfgFrm</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel" >
<x>352</x>
<y>147</y>
</hint>
<hint type="destinationlabel" >
<x>203</x>
<y>86</y>
</hint>
</hints>
</connection>
</connections>
</ui>