1
0
Fork 0
forked from len0rd/rockbox

rbutilqt: made the sapi TTS more configurable, you can now select a specific voice in the config dialog. Also reworked some setSetting functions, to remove depencies.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16111 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Wenger 2008-01-19 18:33:33 +00:00
parent 2cffb1bf3d
commit 6b5780dae3
16 changed files with 269 additions and 97 deletions

View file

@ -150,10 +150,17 @@ void Config::abort()
this->close(); this->close();
} }
void Config::setSettings(QSettings* user,QSettings* device)
void Config::setUserSettings(QSettings *user)
{ {
userSettings = user; userSettings = user;
devices = device;
setUserSettings();
setDevices();
}
void Config::setUserSettings()
{
// set proxy // set proxy
proxy = userSettings->value("proxy").toString(); proxy = userSettings->value("proxy").toString();
@ -214,9 +221,9 @@ void Config::updateCacheInfo(QString path)
} }
void Config::setDevices(QSettings *dev) void Config::setDevices()
{ {
devices = dev;
// setup devices table // setup devices table
qDebug() << "Config::setDevices()"; qDebug() << "Config::setDevices()";
devices->beginGroup("platforms"); devices->beginGroup("platforms");
@ -320,7 +327,7 @@ void Config::updateTtsState(int index)
{ {
QString ttsName = ui.comboTts->itemText(index); QString ttsName = ui.comboTts->itemText(index);
TTSBase* tts = getTTS(ttsName); TTSBase* tts = getTTS(ttsName);
tts->setUserCfg(userSettings); tts->setCfg(userSettings,devices);
if(tts->configOk()) if(tts->configOk())
{ {
@ -624,7 +631,7 @@ void Config::configTts()
{ {
TTSBase* tts =getTTS(ui.comboTts->currentText()); TTSBase* tts =getTTS(ui.comboTts->currentText());
tts->setUserCfg(userSettings); tts->setCfg(userSettings,devices);
tts->showCfg(); tts->showCfg();
updateTtsState(ui.comboTts->currentIndex()); updateTtsState(ui.comboTts->currentIndex());
} }

View file

@ -29,9 +29,8 @@ class Config : public QDialog
Q_OBJECT Q_OBJECT
public: public:
Config(QWidget *parent = 0,int index=0); Config(QWidget *parent = 0,int index=0);
void setUserSettings(QSettings*); void setSettings(QSettings* user,QSettings* device);
void setDevices(QSettings*);
signals: signals:
void settingsUpdated(void); void settingsUpdated(void);
@ -40,6 +39,9 @@ class Config : public QDialog
void abort(void); void abort(void);
private: private:
void setUserSettings();
void setDevices();
Ui::ConfigForm ui; Ui::ConfigForm ui;
QSettings *userSettings; QSettings *userSettings;
QSettings *devices; QSettings *devices;

View file

@ -8,8 +8,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>637</width> <width>659</width>
<height>421</height> <height>482</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
@ -94,7 +94,7 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="1" > <item row="4" column="1" >
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -107,7 +107,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="4" column="1" > <item row="5" column="1" >
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -120,7 +120,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="4" column="2" > <item row="5" column="2" >
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<item> <item>
<widget class="QPushButton" name="buttonOk" > <widget class="QPushButton" name="buttonOk" >
@ -144,6 +144,27 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="3" column="1" colspan="2" >
<layout class="QHBoxLayout" >
<item>
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Wavtrim Threshold</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="wavtrimthreshold" >
<property name="maximum" >
<number>5000</number>
</property>
<property name="value" >
<number>500</number>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>

View file

@ -34,8 +34,7 @@ CreateVoiceWindow::CreateVoiceWindow(QWidget *parent) : QDialog(parent)
void CreateVoiceWindow::change() void CreateVoiceWindow::change()
{ {
Config *cw = new Config(this,4); Config *cw = new Config(this,4);
cw->setUserSettings(userSettings); cw->setSettings(userSettings,devices);
cw->setDevices(devices);
cw->show(); cw->show();
connect(cw, SIGNAL(settingsUpdated()), this, SIGNAL(settingsUpdated())); connect(cw, SIGNAL(settingsUpdated()), this, SIGNAL(settingsUpdated()));
} }
@ -47,19 +46,21 @@ void CreateVoiceWindow::accept()
connect(logger,SIGNAL(closed()),this,SLOT(close())); connect(logger,SIGNAL(closed()),this,SLOT(close()));
QString platform = userSettings->value("platform").toString(); QString platform = userSettings->value("platform").toString();
QString lang = ui.comboLanguage->currentText(); QString lang = ui.comboLanguage->currentText();
int wvThreshold = ui.wavtrimthreshold->value();
//safe selected language //safe selected language
userSettings->setValue("voicelanguage",lang); userSettings->setValue("voicelanguage",lang);
userSettings->setValue("wavtrimthreshold",wvThreshold);
userSettings->sync(); userSettings->sync();
//configure voicecreator //configure voicecreator
voicecreator->setUserSettings(userSettings); voicecreator->setSettings(userSettings,devices);
voicecreator->setDeviceSettings(devices);
voicecreator->setMountPoint(userSettings->value("mountpoint").toString()); voicecreator->setMountPoint(userSettings->value("mountpoint").toString());
voicecreator->setTargetId(devices->value(platform + "/targetid").toInt()); voicecreator->setTargetId(devices->value(platform + "/targetid").toInt());
voicecreator->setLang(lang); voicecreator->setLang(lang);
voicecreator->setProxy(m_proxy); voicecreator->setProxy(m_proxy);
voicecreator->setWavtrimThreshold(wvThreshold);
//start creating //start creating
voicecreator->createVoiceFile(logger); voicecreator->createVoiceFile(logger);
@ -67,9 +68,10 @@ void CreateVoiceWindow::accept()
void CreateVoiceWindow::setDeviceSettings(QSettings *dev) void CreateVoiceWindow::setSettings(QSettings *user,QSettings *dev)
{ {
devices = dev; devices = dev;
userSettings = user;
qDebug() << "Install::setDeviceSettings:" << devices; qDebug() << "Install::setDeviceSettings:" << devices;
// fill in language combobox // fill in language combobox
@ -86,15 +88,10 @@ void CreateVoiceWindow::setDeviceSettings(QSettings *dev)
ui.comboLanguage->addItems(languages); ui.comboLanguage->addItems(languages);
// set saved lang // set saved lang
ui.comboLanguage->setCurrentIndex(ui.comboLanguage->findText(userSettings->value("voicelanguage").toString())); ui.comboLanguage->setCurrentIndex(ui.comboLanguage->findText(userSettings->value("voicelanguage").toString()));
}
void CreateVoiceWindow::setUserSettings(QSettings *user)
{
userSettings = user;
QString ttsName = userSettings->value("tts", "none").toString(); QString ttsName = userSettings->value("tts", "none").toString();
TTSBase* tts = getTTS(ttsName); TTSBase* tts = getTTS(ttsName);
tts->setUserCfg(userSettings); tts->setCfg(userSettings,devices);
if(tts->configOk()) if(tts->configOk())
ui.labelTtsProfile->setText(tr("Selected TTS engine : <b>%1</b>").arg(ttsName)); ui.labelTtsProfile->setText(tr("Selected TTS engine : <b>%1</b>").arg(ttsName));
else else
@ -107,8 +104,12 @@ void CreateVoiceWindow::setUserSettings(QSettings *user)
ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg(encoder)); ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg(encoder));
else else
ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg("Invalid encoder configuration!")); ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg("Invalid encoder configuration!"));
ui.wavtrimthreshold->setValue(userSettings->value("wavtrimthreshold", 500).toInt());
} }

View file

@ -33,8 +33,7 @@ class CreateVoiceWindow : public QDialog
Q_OBJECT Q_OBJECT
public: public:
CreateVoiceWindow(QWidget *parent = 0); CreateVoiceWindow(QWidget *parent = 0);
void setUserSettings(QSettings*); void setSettings(QSettings* user,QSettings* device);
void setDeviceSettings(QSettings*);
void setProxy(QUrl proxy){m_proxy = proxy;} void setProxy(QUrl proxy){m_proxy = proxy;}
signals: signals:

View file

@ -66,8 +66,7 @@ void InstallTalkWindow::setTalkFolder(QString folder)
void InstallTalkWindow::change() void InstallTalkWindow::change()
{ {
Config *cw = new Config(this,4); Config *cw = new Config(this,4);
cw->setUserSettings(userSettings); cw->setSettings(userSettings,devices);
cw->setDevices(devices);
cw->show(); cw->show();
connect(cw, SIGNAL(settingsUpdated()), this, SIGNAL(settingsUpdated())); connect(cw, SIGNAL(settingsUpdated()), this, SIGNAL(settingsUpdated()));
} }
@ -91,7 +90,7 @@ void InstallTalkWindow::accept()
userSettings->sync(); userSettings->sync();
talkcreator->setUserSettings(userSettings); talkcreator->setSettings(userSettings,devices);
talkcreator->setDir(QDir(folderToTalk)); talkcreator->setDir(QDir(folderToTalk));
talkcreator->setMountPoint(userSettings->value("mountpoint").toString()); talkcreator->setMountPoint(userSettings->value("mountpoint").toString());
@ -107,14 +106,15 @@ void InstallTalkWindow::accept()
} }
void InstallTalkWindow::setDeviceSettings(QSettings *dev) void InstallTalkWindow::setSettings(QSettings *user,QSettings *dev)
{ {
devices = dev; devices = dev;
userSettings = user;
qDebug() << "Install::setDeviceSettings:" << devices; qDebug() << "Install::setDeviceSettings:" << devices;
QString ttsName = userSettings->value("tts", "none").toString(); QString ttsName = userSettings->value("tts", "none").toString();
TTSBase* tts = getTTS(ttsName); TTSBase* tts = getTTS(ttsName);
tts->setUserCfg(userSettings); tts->setCfg(userSettings,devices);
if(tts->configOk()) if(tts->configOk())
ui.labelTtsProfile->setText(tr("Selected TTS engine : <b>%1</b>").arg(ttsName)); ui.labelTtsProfile->setText(tr("Selected TTS engine : <b>%1</b>").arg(ttsName));
else else
@ -127,12 +127,8 @@ void InstallTalkWindow::setDeviceSettings(QSettings *dev)
ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg(encoder)); ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg(encoder));
else else
ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg("Invalid encoder configuration!")); ui.labelEncProfile->setText(tr("Selected Encoder: <b>%1</b>").arg("Invalid encoder configuration!"));
}
void InstallTalkWindow::setUserSettings(QSettings *user)
{
userSettings = user;
setTalkFolder(userSettings->value("last_talked_folder").toString()); setTalkFolder(userSettings->value("last_talked_folder").toString());
} }

View file

@ -33,8 +33,7 @@ class InstallTalkWindow : public QDialog
Q_OBJECT Q_OBJECT
public: public:
InstallTalkWindow(QWidget *parent = 0); InstallTalkWindow(QWidget *parent = 0);
void setUserSettings(QSettings*); void setSettings(QSettings* user,QSettings* device);
void setDeviceSettings(QSettings*);
signals: signals:
void settingsUpdated(void); void settingsUpdated(void);

View file

@ -253,8 +253,7 @@ void RbUtilQt::help()
void RbUtilQt::configDialog() void RbUtilQt::configDialog()
{ {
Config *cw = new Config(this); Config *cw = new Config(this);
cw->setUserSettings(userSettings); cw->setSettings(userSettings,devices);
cw->setDevices(devices);
cw->show(); cw->show();
connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo())); connect(cw, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings())); connect(cw, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
@ -748,8 +747,7 @@ void RbUtilQt::createTalkFiles(void)
{ {
if(chkConfig(true)) return; if(chkConfig(true)) return;
InstallTalkWindow *installWindow = new InstallTalkWindow(this); InstallTalkWindow *installWindow = new InstallTalkWindow(this);
installWindow->setUserSettings(userSettings); installWindow->setSettings(userSettings,devices);
installWindow->setDeviceSettings(devices);
installWindow->show(); installWindow->show();
connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo())); connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(downloadInfo()));
connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings())); connect(installWindow, SIGNAL(settingsUpdated()), this, SLOT(updateSettings()));
@ -760,8 +758,7 @@ void RbUtilQt::createVoiceFile(void)
{ {
if(chkConfig(true)) return; if(chkConfig(true)) return;
CreateVoiceWindow *installWindow = new CreateVoiceWindow(this); CreateVoiceWindow *installWindow = new CreateVoiceWindow(this);
installWindow->setUserSettings(userSettings); installWindow->setSettings(userSettings,devices);
installWindow->setDeviceSettings(devices);
installWindow->setProxy(proxy()); installWindow->setProxy(proxy());
installWindow->show(); installWindow->show();

View file

@ -17,6 +17,12 @@ rbspeex.commands = @$(MAKE) -C ../../tools/rbspeex librbspeex.a
QMAKE_EXTRA_TARGETS = rbspeex QMAKE_EXTRA_TARGETS = rbspeex
PRE_TARGETDEPS = rbspeex PRE_TARGETDEPS = rbspeex
# add a custom rule for makeing the translations
lrelease.commands = lrelease rbutilqt.pro
QMAKE_EXTRA_TARGETS += lrelease
PRE_TARGETDEPS = lrelease
SOURCES += rbutilqt.cpp \ SOURCES += rbutilqt.cpp \
main.cpp \ main.cpp \
install.cpp \ install.cpp \

View file

@ -18,41 +18,68 @@
<property name="title" > <property name="title" >
<string>Configure TTS Engine</string> <string>Configure TTS Engine</string>
</property> </property>
<layout class="QVBoxLayout" > <layout class="QGridLayout" >
<item> <item row="0" column="0" >
<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" > <widget class="QLabel" name="label_3" >
<property name="text" > <property name="text" >
<string>Language</string> <string>Language</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1" >
<widget class="QLineEdit" name="ttslanguage" /> <widget class="QComboBox" name="languagecombo" />
</item> </item>
<item> <item row="1" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string>Voice</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QComboBox" name="voicecombo" />
</item>
<item row="2" column="0" >
<widget class="QLabel" name="label_4" >
<property name="text" >
<string>Speed</string>
</property>
</widget>
</item>
<item row="2" column="1" >
<widget class="QSpinBox" name="speed" >
<property name="minimum" >
<number>-10</number>
</property>
<property name="maximum" >
<number>10</number>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>TTS options</string>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="ttsoptions" />
</item>
<item row="4" column="0" colspan="2" >
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" >
<size> <size>
<width>20</width> <width>473</width>
<height>40</height> <height>21</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item row="5" column="0" colspan="2" >
<layout class="QHBoxLayout" > <layout class="QHBoxLayout" >
<item> <item>
<widget class="QPushButton" name="reset" > <widget class="QPushButton" name="reset" >

View file

@ -28,15 +28,17 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
{ {
m_abort = false; m_abort = false;
m_logger = logger; m_logger = logger;
m_logger->addItem("Starting Talk file generation",LOGINFO); m_logger->addItem(tr("Starting Talk file generation"),LOGINFO);
//tts //tts
m_tts = getTTS(userSettings->value("tts").toString()); m_tts = getTTS(userSettings->value("tts").toString());
m_tts->setUserCfg(userSettings); m_tts->setCfg(userSettings,deviceSettings);
if(!m_tts->start()) QString errStr;
if(!m_tts->start(&errStr))
{ {
m_logger->addItem("Init of TTS engine failed",LOGERROR); m_logger->addItem(errStr,LOGERROR);
m_logger->addItem(tr("Init of TTS engine failed"),LOGERROR);
m_logger->abort(); m_logger->abort();
return false; return false;
} }
@ -47,7 +49,7 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
if(!m_enc->start()) if(!m_enc->start())
{ {
m_logger->addItem("Init of Encoder engine failed",LOGERROR); m_logger->addItem(tr("Init of Encoder engine failed"),LOGERROR);
m_logger->abort(); m_logger->abort();
m_tts->stop(); m_tts->stop();
return false; return false;
@ -65,7 +67,7 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
{ {
if(m_abort) if(m_abort)
{ {
m_logger->addItem("Talk file creation aborted",LOGERROR); m_logger->addItem(tr("Talk file creation aborted"),LOGERROR);
m_logger->abort(); m_logger->abort();
m_tts->stop(); m_tts->stop();
return false; return false;
@ -127,10 +129,10 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
{ {
if(!wavfilenameInf.exists() || m_overwriteWav) if(!wavfilenameInf.exists() || m_overwriteWav)
{ {
m_logger->addItem("Voicing of " + toSpeak,LOGINFO); m_logger->addItem(tr("Voicing of %1").arg(toSpeak),LOGINFO);
if(!m_tts->voice(toSpeak,wavfilename)) if(!m_tts->voice(toSpeak,wavfilename))
{ {
m_logger->addItem("Voicing of " + toSpeak + " failed",LOGERROR); m_logger->addItem(tr("Voicing of %s failed").arg(toSpeak),LOGERROR);
m_logger->abort(); m_logger->abort();
m_tts->stop(); m_tts->stop();
m_enc->stop(); m_enc->stop();
@ -138,10 +140,10 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
} }
QApplication::processEvents(); QApplication::processEvents();
} }
m_logger->addItem("Encoding of " + toSpeak,LOGINFO); m_logger->addItem(tr("Encoding of %1").arg(toSpeak),LOGINFO);
if(!m_enc->encode(wavfilename,filename)) if(!m_enc->encode(wavfilename,filename))
{ {
m_logger->addItem("Encoding of " + wavfilename + " failed",LOGERROR); m_logger->addItem(tr("Encoding of %1 failed").arg(wavfilename),LOGERROR);
m_logger->abort(); m_logger->abort();
m_tts->stop(); m_tts->stop();
m_enc->stop(); m_enc->stop();
@ -168,7 +170,7 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
installlog.endGroup(); installlog.endGroup();
m_tts->stop(); m_tts->stop();
m_logger->addItem("Finished creating Talk files",LOGOK); m_logger->addItem(tr("Finished creating Talk files"),LOGOK);
m_logger->setProgressMax(1); m_logger->setProgressMax(1);
m_logger->setProgressValue(1); m_logger->setProgressValue(1);
m_logger->abort(); m_logger->abort();

View file

@ -36,7 +36,7 @@ public:
bool createTalkFiles(ProgressloggerInterface* logger); bool createTalkFiles(ProgressloggerInterface* logger);
void setUserSettings(QSettings* setting) { userSettings = setting;} void setSettings(QSettings* uSettings,QSettings* dSettings) { userSettings = uSettings; deviceSettings = dSettings;}
void setDir(QDir dir){m_dir = dir; } void setDir(QDir dir){m_dir = dir; }
void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; } void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; }
@ -56,6 +56,7 @@ private:
TTSBase* m_tts; TTSBase* m_tts;
EncBase* m_enc; EncBase* m_enc;
QSettings *userSettings; QSettings *userSettings;
QSettings *deviceSettings;
QDir m_dir; QDir m_dir;
QString m_mountpoint; QString m_mountpoint;

View file

@ -104,7 +104,7 @@ TTSExes::TTSExes(QString name,QWidget *parent) : TTSBase(parent)
connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse())); connect(ui.browse,SIGNAL(clicked()),this,SLOT(browse()));
} }
bool TTSExes::start() bool TTSExes::start(QString *errStr)
{ {
userSettings->beginGroup(m_name); userSettings->beginGroup(m_name);
m_TTSexec = userSettings->value("ttspath","").toString(); m_TTSexec = userSettings->value("ttspath","").toString();
@ -120,6 +120,7 @@ bool TTSExes::start()
} }
else else
{ {
*errStr = tr("TTS executable not found");
return false; return false;
} }
} }
@ -244,40 +245,109 @@ void TTSExes::browse()
**********************************************************************/ **********************************************************************/
TTSSapi::TTSSapi(QWidget *parent) : TTSBase(parent) TTSSapi::TTSSapi(QWidget *parent) : TTSBase(parent)
{ {
m_TTSTemplate = "cscript //nologo \"%exe\" /language:%lang \"%options\""; m_TTSTemplate = "cscript //nologo \"%exe\" /language:%lang /voice:\"%voice\" /speed:%speed \"%options\"";
defaultLanguage ="english"; defaultLanguage ="english";
ui.setupUi(this); ui.setupUi(this);
this->hide(); this->hide();
connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset()));
connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString)));
} }
bool TTSSapi::start() bool TTSSapi::start(QString *errStr)
{ {
userSettings->beginGroup("sapi"); userSettings->beginGroup("sapi");
m_TTSOpts = userSettings->value("ttsoptions","").toString(); m_TTSOpts = userSettings->value("ttsoptions","").toString();
m_TTSLanguage =userSettings->value("ttslanguage","").toString(); m_TTSLanguage =userSettings->value("ttslanguage","").toString();
m_TTSVoice=userSettings->value("ttsvoice","").toString();
m_TTSSpeed=userSettings->value("ttsspeed","").toString();
userSettings->endGroup(); userSettings->endGroup();
QFile::remove(QDir::tempPath() +"/sapi_voice.vbs");
QFile::copy(":/builtin/sapi_voice.vbs",QDir::tempPath() + "/sapi_voice.vbs"); QFile::copy(":/builtin/sapi_voice.vbs",QDir::tempPath() + "/sapi_voice.vbs");
m_TTSexec = QDir::tempPath() +"/sapi_voice.vbs"; m_TTSexec = QDir::tempPath() +"/sapi_voice.vbs";
QFileInfo tts(m_TTSexec); QFileInfo tts(m_TTSexec);
if(!tts.exists()) if(!tts.exists())
{
*errStr = tr("Could not copy the Sapi-script");
return false; return false;
}
// create the voice process // create the voice process
QString execstring = m_TTSTemplate; QString execstring = m_TTSTemplate;
execstring.replace("%exe",m_TTSexec); execstring.replace("%exe",m_TTSexec);
execstring.replace("%options",m_TTSOpts); execstring.replace("%options",m_TTSOpts);
execstring.replace("%lang",m_TTSLanguage); execstring.replace("%lang",m_TTSLanguage);
execstring.replace("%voice",m_TTSVoice);
execstring.replace("%speed",m_TTSSpeed);
qDebug() << "init" << execstring;
voicescript = new QProcess(NULL);
//connect(voicescript,SIGNAL(readyReadStandardError()),this,SLOT(error()));
voicescript->start(execstring);
if(!voicescript->waitForStarted())
{
*errStr = tr("Could not start the Sapi-script");
return false;
}
if(!voicescript->waitForReadyRead(100))
{
*errStr = voicescript->readAllStandardError();
if(*errStr != "")
return false;
}
return true;
}
QStringList TTSSapi::getVoiceList(QString language)
{
QStringList result;
QFile::copy(":/builtin/sapi_voice.vbs",QDir::tempPath() + "/sapi_voice.vbs");
m_TTSexec = QDir::tempPath() +"/sapi_voice.vbs";
QFileInfo tts(m_TTSexec);
if(!tts.exists())
return result;
// create the voice process
QString execstring = "cscript //nologo \"%exe\" /language:%lang /listvoices";;
execstring.replace("%exe",m_TTSexec);
execstring.replace("%lang",language);
qDebug() << "init" << execstring; qDebug() << "init" << execstring;
voicescript = new QProcess(NULL); voicescript = new QProcess(NULL);
voicescript->start(execstring); voicescript->start(execstring);
if(!voicescript->waitForStarted()) if(!voicescript->waitForStarted())
return false; return result;
return true;
voicescript->waitForReadyRead();
QString dataRaw = voicescript->readAllStandardError().data();
result = dataRaw.split(",",QString::SkipEmptyParts);
result.sort();
result.removeFirst();
delete voicescript;
QFile::setPermissions(QDir::tempPath() +"/sapi_voice.vbs",QFile::ReadOwner |QFile::WriteOwner|QFile::ExeOwner
|QFile::ReadUser| QFile::WriteUser| QFile::ExeUser
|QFile::ReadGroup |QFile::WriteGroup |QFile::ExeGroup
|QFile::ReadOther |QFile::WriteOther |QFile::ExeOther );
QFile::remove(QDir::tempPath() +"/sapi_voice.vbs");
return result;
}
void TTSSapi::updateVoices(QString language)
{
QStringList Voices = getVoiceList(language);
ui.voicecombo->clear();
ui.voicecombo->addItems(Voices);
} }
bool TTSSapi::voice(QString text,QString wavfile) bool TTSSapi::voice(QString text,QString wavfile)
@ -296,6 +366,11 @@ bool TTSSapi::stop()
voicescript->write(query.toUtf8()); voicescript->write(query.toUtf8());
voicescript->waitForFinished(); voicescript->waitForFinished();
delete voicescript; delete voicescript;
QFile::setPermissions(QDir::tempPath() +"/sapi_voice.vbs",QFile::ReadOwner |QFile::WriteOwner|QFile::ExeOwner
|QFile::ReadUser| QFile::WriteUser| QFile::ExeUser
|QFile::ReadGroup |QFile::WriteGroup |QFile::ExeGroup
|QFile::ReadOther |QFile::WriteOther |QFile::ExeOther );
QFile::remove(QDir::tempPath() +"/sapi_voice.vbs");
return true; return true;
} }
@ -303,7 +378,7 @@ bool TTSSapi::stop()
void TTSSapi::reset() void TTSSapi::reset()
{ {
ui.ttsoptions->setText(""); ui.ttsoptions->setText("");
ui.ttslanguage->setText(defaultLanguage); ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(defaultLanguage));
} }
void TTSSapi::showCfg() void TTSSapi::showCfg()
@ -311,9 +386,35 @@ void TTSSapi::showCfg()
// try to get config from settings // try to get config from settings
userSettings->beginGroup("sapi"); userSettings->beginGroup("sapi");
ui.ttsoptions->setText(userSettings->value("ttsoptions","").toString()); ui.ttsoptions->setText(userSettings->value("ttsoptions","").toString());
ui.ttslanguage->setText(userSettings->value("ttslanguage",defaultLanguage).toString()); QString selLang = userSettings->value("ttslanguage",defaultLanguage).toString();
QString selVoice = userSettings->value("ttsvoice","").toString();
ui.speed->setValue(userSettings->value("ttsspeed",0).toInt());
userSettings->endGroup(); userSettings->endGroup();
// fill in language combobox
deviceSettings->beginGroup("languages");
QStringList keys = deviceSettings->allKeys();
QStringList languages;
for(int i =0 ; i < keys.size();i++)
{
languages << deviceSettings->value(keys.at(i)).toString();
}
deviceSettings->endGroup();
languages.sort();
ui.languagecombo->clear();
ui.languagecombo->addItems(languages);
// set saved lang
ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang));
// fill in voice combobox
updateVoices(selLang);
// set saved lang
ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice));
//show dialog //show dialog
this->exec(); this->exec();
@ -326,7 +427,9 @@ void TTSSapi::accept(void)
//save settings in user config //save settings in user config
userSettings->beginGroup("sapi"); userSettings->beginGroup("sapi");
userSettings->setValue("ttsoptions",ui.ttsoptions->text()); userSettings->setValue("ttsoptions",ui.ttsoptions->text());
userSettings->setValue("ttslanguage",ui.ttslanguage->text()); userSettings->setValue("ttslanguage",ui.languagecombo->currentText());
userSettings->setValue("ttsvoice",ui.voicecombo->currentText());
userSettings->setValue("ttsspeed",QString("%1").arg(ui.speed->value()));
userSettings->endGroup(); userSettings->endGroup();
// sync settings // sync settings
userSettings->sync(); userSettings->sync();

View file

@ -42,12 +42,12 @@ class TTSBase : public QDialog
public: public:
TTSBase(QWidget *parent ); TTSBase(QWidget *parent );
virtual bool voice(QString text,QString wavfile) {return false;} virtual bool voice(QString text,QString wavfile) {return false;}
virtual bool start(){return false;} virtual bool start(QString *errStr){return false;}
virtual bool stop(){return false;} virtual bool stop(){return false;}
virtual void showCfg(){} virtual void showCfg(){}
virtual bool configOk(){return false;} virtual bool configOk(){return false;}
void setUserCfg(QSettings *uSettings){userSettings = uSettings;} void setCfg(QSettings *uSettings, QSettings *dSettings){userSettings = uSettings;deviceSettings = dSettings;}
public slots: public slots:
virtual void accept(void){} virtual void accept(void){}
@ -56,6 +56,8 @@ public slots:
protected: protected:
QSettings *userSettings; QSettings *userSettings;
QSettings *deviceSettings;
}; };
class TTSSapi : public TTSBase class TTSSapi : public TTSBase
@ -64,7 +66,7 @@ class TTSSapi : public TTSBase
public: public:
TTSSapi(QWidget *parent = NULL); TTSSapi(QWidget *parent = NULL);
virtual bool voice(QString text,QString wavfile); virtual bool voice(QString text,QString wavfile);
virtual bool start(); virtual bool start(QString *errStr);
virtual bool stop(); virtual bool stop();
virtual void showCfg(); virtual void showCfg();
virtual bool configOk(); virtual bool configOk();
@ -74,7 +76,10 @@ public slots:
virtual void reject(void); virtual void reject(void);
virtual void reset(void); virtual void reset(void);
void updateVoices(QString language);
private: private:
QStringList getVoiceList(QString language);
Ui::SapiCfgFrm ui; Ui::SapiCfgFrm ui;
QProcess* voicescript; QProcess* voicescript;
@ -84,6 +89,9 @@ private:
QString m_TTSOpts; QString m_TTSOpts;
QString m_TTSTemplate; QString m_TTSTemplate;
QString m_TTSLanguage; QString m_TTSLanguage;
QString m_TTSVoice;
QString m_TTSSpeed;
}; };
class TTSExes : public TTSBase class TTSExes : public TTSBase
@ -92,7 +100,7 @@ class TTSExes : public TTSBase
public: public:
TTSExes(QString name,QWidget *parent = NULL); TTSExes(QString name,QWidget *parent = NULL);
virtual bool voice(QString text,QString wavfile); virtual bool voice(QString text,QString wavfile);
virtual bool start(); virtual bool start(QString *errStr);
virtual bool stop() {return true;} virtual bool stop() {return true;}
virtual void showCfg(); virtual void showCfg();
virtual bool configOk(); virtual bool configOk();

View file

@ -26,7 +26,7 @@
VoiceFileCreator::VoiceFileCreator(QObject* parent) :QObject(parent) VoiceFileCreator::VoiceFileCreator(QObject* parent) :QObject(parent)
{ {
m_wavtrimThreshold=500;
} }
void VoiceFileCreator::abort() void VoiceFileCreator::abort()
@ -147,10 +147,12 @@ void VoiceFileCreator::downloadDone(bool error)
//tts //tts
m_tts = getTTS(userSettings->value("tts").toString()); m_tts = getTTS(userSettings->value("tts").toString());
m_tts->setUserCfg(userSettings); m_tts->setCfg(userSettings,deviceSettings);
if(!m_tts->start()) QString errStr;
if(!m_tts->start(&errStr))
{ {
m_logger->addItem(errStr,LOGERROR);
m_logger->addItem(tr("Init of TTS engine failed"),LOGERROR); m_logger->addItem(tr("Init of TTS engine failed"),LOGERROR);
m_logger->abort(); m_logger->abort();
return; return;
@ -249,7 +251,7 @@ void VoiceFileCreator::downloadDone(bool error)
// todo strip // todo strip
char buffer[255]; char buffer[255];
wavtrim((char*)qPrintable(wavname),500,buffer,255); wavtrim((char*)qPrintable(wavname),m_wavtrimThreshold,buffer,255);
// encode wav // encode wav
m_enc->encode(wavname,encodedname); m_enc->encode(wavname,encodedname);

View file

@ -44,12 +44,12 @@ public:
bool createVoiceFile(ProgressloggerInterface* logger); bool createVoiceFile(ProgressloggerInterface* logger);
// set infos // set infos
void setUserSettings(QSettings* setting) { userSettings = setting;} void setSettings(QSettings* uSettings,QSettings* dSettings) { userSettings = uSettings;deviceSettings = dSettings;}
void setDeviceSettings(QSettings* setting) { deviceSettings = setting;}
void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; } void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; }
void setTargetId(int id){m_targetid = id;} void setTargetId(int id){m_targetid = id;}
void setLang(QString name){m_lang =name;} void setLang(QString name){m_lang =name;}
void setWavtrimThreshold(int th){m_wavtrimThreshold = th;}
void setProxy(QUrl proxy){m_proxy = proxy;} void setProxy(QUrl proxy){m_proxy = proxy;}
private slots: private slots:
@ -75,6 +75,7 @@ private:
QString m_path; //path where the wav and mp3 files are stored to QString m_path; //path where the wav and mp3 files are stored to
int m_targetid; //the target id int m_targetid; //the target id
QString m_lang; // the language which will be spoken QString m_lang; // the language which will be spoken
int m_wavtrimThreshold;
ProgressloggerInterface* m_logger; ProgressloggerInterface* m_logger;