From baef133f5f2aa4032af777b83ef837ab2db8b8c9 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 5 Apr 2009 12:46:41 +0000 Subject: Code police: - kill trailing whitespace - replace tabs by spaces git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20623 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/rbutilqt/tts.cpp | 494 +++++++++++++++++++++--------------------- rbutil/rbutilqt/tts.h | 56 ++--- rbutil/rbutilqt/ttsgui.cpp | 235 ++++++++++---------- rbutil/rbutilqt/ttsgui.h | 115 +++++----- rbutil/rbutilqt/voicefile.cpp | 110 +++++----- rbutil/rbutilqt/voicefile.h | 19 +- 6 files changed, 517 insertions(+), 512 deletions(-) diff --git a/rbutil/rbutilqt/tts.cpp b/rbutil/rbutilqt/tts.cpp index 48555cc114..68f169e875 100644 --- a/rbutil/rbutilqt/tts.cpp +++ b/rbutil/rbutilqt/tts.cpp @@ -50,17 +50,17 @@ TTSBase* TTSBase::getTTS(QString ttsName) if(ttsName == "sapi") { tts = new TTSSapi(); - ttsCache[ttsName] = tts; + ttsCache[ttsName] = tts; return tts; } - else + else #endif #if defined(Q_OS_LINUX) if (ttsName == "festival") { - tts = new TTSFestival(); - ttsCache[ttsName] = tts; - return tts; + tts = new TTSFestival(); + ttsCache[ttsName] = tts; + return tts; } else #endif @@ -104,30 +104,30 @@ TTSBase::TTSBase(): QObject() TTSExes::TTSExes(QString name) : TTSBase() { m_name = name; - + m_TemplateMap["espeak"] = "\"%exe\" %options -w \"%wavfile\" \"%text\""; m_TemplateMap["flite"] = "\"%exe\" %options -o \"%wavfile\" -t \"%text\""; m_TemplateMap["swift"] = "\"%exe\" %options -o \"%wavfile\" \"%text\""; - + } void TTSExes::setCfg(RbSettings* sett) { // call function of base class TTSBase::setCfg(sett); - + // if the config isnt OK, try to autodetect if(!configOk()) { QString exepath; - //try autodetect tts + //try autodetect tts #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) 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++) + for(int i = 0; i < path.size(); i++) { QString executable = QDir::fromNativeSeparators(path.at(i)) + "/" + m_name; #if defined(Q_OS_WIN) @@ -145,14 +145,14 @@ void TTSExes::setCfg(RbSettings* sett) settings->setTTSPath(m_name,exepath); settings->sync(); } - + } bool TTSExes::start(QString *errStr) { m_TTSexec = settings->ttsPath(m_name); m_TTSOpts = settings->ttsOptions(m_name); - + m_TTSTemplate = m_TemplateMap.value(m_name); QFileInfo tts(m_TTSexec); @@ -169,7 +169,7 @@ bool TTSExes::start(QString *errStr) TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr) { - (void) errStr; + (void) errStr; QString execstring = m_TTSTemplate; execstring.replace("%exe",m_TTSexec); @@ -187,7 +187,7 @@ void TTSExes::showCfg() #ifndef CONSOLE TTSExesGui gui; #else - TTSExesGuiCli gui; + TTSExesGuiCli gui; #endif gui.setCfg(settings); gui.showCfg(m_name); @@ -196,10 +196,10 @@ void TTSExes::showCfg() bool TTSExes::configOk() { QString path = settings->ttsPath(m_name); - + if (QFileInfo(path).exists()) return true; - + return false; } @@ -215,24 +215,24 @@ TTSSapi::TTSSapi() : TTSBase() bool TTSSapi::start(QString *errStr) -{ +{ m_TTSOpts = settings->ttsOptions("sapi"); m_TTSLanguage =settings->ttsLang("sapi"); m_TTSVoice=settings->ttsVoice("sapi"); m_TTSSpeed=QString("%1").arg(settings->ttsSpeed("sapi")); m_sapi4 = settings->ttsUseSapi4(); - + QFile::remove(QDir::tempPath() +"/sapi_voice.vbs"); 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()) { *errStr = tr("Could not copy the Sapi-script"); return false; - } + } // create the voice process QString execstring = m_TTSTemplate; execstring.replace("%exe",m_TTSexec); @@ -240,31 +240,31 @@ bool TTSSapi::start(QString *errStr) execstring.replace("%lang",m_TTSLanguage); execstring.replace("%voice",m_TTSVoice); execstring.replace("%speed",m_TTSSpeed); - + if(m_sapi4) execstring.append(" /sapi4 "); - - qDebug() << "init" << execstring; + + 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(300)) + + if(!voicescript->waitForReadyRead(300)) { *errStr = voicescript->readAllStandardError(); if(*errStr != "") - return false; + return false; } - + voicestream = new QTextStream(voicescript); voicestream->setCodec("UTF16-LE"); - + return true; } @@ -272,31 +272,31 @@ bool TTSSapi::start(QString *errStr) 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); - + if(settings->ttsUseSapi4()) execstring.append(" /sapi4 "); - - qDebug() << "init" << execstring; + + qDebug() << "init" << execstring; voicescript = new QProcess(NULL); voicescript->start(execstring); - qDebug() << "wait for started"; + qDebug() << "wait for started"; if(!voicescript->waitForStarted()) return result; voicescript->closeWriteChannel(); voicescript->waitForReadyRead(); - + QString dataRaw = voicescript->readAllStandardError().data(); result = dataRaw.split(",",QString::SkipEmptyParts); result.sort(); @@ -305,15 +305,16 @@ QStringList TTSSapi::getVoiceList(QString language) { result[i] = result.at(i).simplified(); } - - + + 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::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; } @@ -321,7 +322,7 @@ QStringList TTSSapi::getVoiceList(QString language) TTSStatus TTSSapi::voice(QString text,QString wavfile, QString *errStr) { - (void) errStr; + (void) errStr; QString query = "SPEAK\t"+wavfile+"\t"+text+"\r\n"; qDebug() << "voicing" << query; *voicestream << query; @@ -332,17 +333,18 @@ TTSStatus TTSSapi::voice(QString text,QString wavfile, QString *errStr) } bool TTSSapi::stop() -{ - +{ + *voicestream << "QUIT\r\n"; voicestream->flush(); voicescript->waitForFinished(); delete voicestream; 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::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; } @@ -353,7 +355,7 @@ void TTSSapi::showCfg() #ifndef CONSOLE TTSSapiGui gui(this); #else - TTSSapiGuiCli gui(this); + TTSSapiGuiCli gui(this); #endif gui.setCfg(settings); gui.showCfg(); @@ -370,104 +372,104 @@ bool TTSSapi::configOk() **********************************************************************/ TTSFestival::~TTSFestival() { - stop(); + stop(); } void TTSFestival::startServer() { - if(!configOk()) - return; + if(!configOk()) + return; - QStringList paths = settings->ttsPath("festival").split(":"); + QStringList paths = settings->ttsPath("festival").split(":"); - serverProcess.start(QString("%1 --server").arg(paths[0])); - serverProcess.waitForStarted(); + serverProcess.start(QString("%1 --server").arg(paths[0])); + serverProcess.waitForStarted(); - queryServer("(getpid)"); - if(serverProcess.state() == QProcess::Running) - qDebug() << "Festival is up and running"; - else - qDebug() << "Festival failed to start"; + queryServer("(getpid)"); + if(serverProcess.state() == QProcess::Running) + qDebug() << "Festival is up and running"; + else + qDebug() << "Festival failed to start"; } void TTSFestival::ensureServerRunning() { - if(serverProcess.state() != QProcess::Running) - { - // least common denominator for all the server startup code paths - QProgressDialog progressDialog(tr(""), tr(""), 0, 0); - progressDialog.setWindowTitle(tr("Starting festival")); - progressDialog.setModal(true); - progressDialog.setLabel(0); - progressDialog.setCancelButton(0); - progressDialog.show(); - - QApplication::processEvents(); // actually show the dialog - - startServer(); - } + if(serverProcess.state() != QProcess::Running) + { + // least common denominator for all the server startup code paths + QProgressDialog progressDialog(tr(""), tr(""), 0, 0); + progressDialog.setWindowTitle(tr("Starting festival")); + progressDialog.setModal(true); + progressDialog.setLabel(0); + progressDialog.setCancelButton(0); + progressDialog.show(); + + QApplication::processEvents(); // actually show the dialog + + startServer(); + } } bool TTSFestival::start(QString* errStr) { - (void) errStr; - ensureServerRunning(); - if (!settings->ttsVoice("festival").isEmpty()) - queryServer(QString("(voice.select '%1)").arg(settings->ttsVoice("festival"))); + (void) errStr; + ensureServerRunning(); + if (!settings->ttsVoice("festival").isEmpty()) + queryServer(QString("(voice.select '%1)").arg(settings->ttsVoice("festival"))); - return true; + return true; } bool TTSFestival::stop() { - serverProcess.terminate(); - serverProcess.kill(); + serverProcess.terminate(); + serverProcess.kill(); - return true; + return true; } TTSStatus TTSFestival::voice(QString text, QString wavfile, QString* errStr) { - qDebug() << text << "->" << wavfile; - - QStringList paths = settings->ttsPath("festival").split(":"); - QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(paths[1]).arg(wavfile); - qDebug() << cmd; - - QProcess clientProcess; - clientProcess.start(cmd); - clientProcess.write(QString("%1.\n").arg(text).toAscii()); - clientProcess.waitForBytesWritten(); - clientProcess.closeWriteChannel(); - clientProcess.waitForReadyRead(); - QString response = clientProcess.readAll(); - response = response.trimmed(); - if(!response.contains("Utterance")) - { - qDebug() << "Could not voice string: " << response; - *errStr = tr("engine could not voice string"); - return Warning; - /* do not stop the voicing process because of a single string - TODO: needs proper settings */ - } - clientProcess.closeReadChannel(QProcess::StandardError); - clientProcess.closeReadChannel(QProcess::StandardOutput); - clientProcess.terminate(); - clientProcess.kill(); - - return NoError; + qDebug() << text << "->" << wavfile; + + QStringList paths = settings->ttsPath("festival").split(":"); + QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(paths[1]).arg(wavfile); + qDebug() << cmd; + + QProcess clientProcess; + clientProcess.start(cmd); + clientProcess.write(QString("%1.\n").arg(text).toAscii()); + clientProcess.waitForBytesWritten(); + clientProcess.closeWriteChannel(); + clientProcess.waitForReadyRead(); + QString response = clientProcess.readAll(); + response = response.trimmed(); + if(!response.contains("Utterance")) + { + qDebug() << "Could not voice string: " << response; + *errStr = tr("engine could not voice string"); + return Warning; + /* do not stop the voicing process because of a single string + TODO: needs proper settings */ + } + clientProcess.closeReadChannel(QProcess::StandardError); + clientProcess.closeReadChannel(QProcess::StandardOutput); + clientProcess.terminate(); + clientProcess.kill(); + + return NoError; } bool TTSFestival::configOk() { - QStringList paths = settings->ttsPath("festival").split(":"); - if(paths.size() != 2) - return false; - bool ret = QFileInfo(paths[0]).isExecutable() && - QFileInfo(paths[1]).isExecutable(); - if(settings->ttsVoice("festival").size() > 0 && voices.size() > 0) - ret = ret && (voices.indexOf(settings->ttsVoice("festival")) != -1); - return ret; + QStringList paths = settings->ttsPath("festival").split(":"); + if(paths.size() != 2) + return false; + bool ret = QFileInfo(paths[0]).isExecutable() && + QFileInfo(paths[1]).isExecutable(); + if(settings->ttsVoice("festival").size() > 0 && voices.size() > 0) + ret = ret && (voices.indexOf(settings->ttsVoice("festival")) != -1); + return ret; } void TTSFestival::showCfg() @@ -481,138 +483,138 @@ void TTSFestival::showCfg() QStringList TTSFestival::getVoiceList() { - if(!configOk()) - return QStringList(); - - if(voices.size() > 0) - { - qDebug() << "Using voice cache"; - return voices; - } - QString response = queryServer("(voice.list)"); - - // get the 2nd line. It should be (, ) - response = response.mid(response.indexOf('\n') + 1, -1); - response = response.left(response.indexOf('\n')).trimmed(); - - voices = response.mid(1, response.size()-2).split(' '); - - voices.sort(); - if (voices.size() == 1 && voices[0].size() == 0) - voices.removeAt(0); - if (voices.size() > 0) - qDebug() << "Voices: " << voices; - else - qDebug() << "No voices."; - return voices; + if(!configOk()) + return QStringList(); + + if(voices.size() > 0) + { + qDebug() << "Using voice cache"; + return voices; + } + QString response = queryServer("(voice.list)"); + + // get the 2nd line. It should be (, ) + response = response.mid(response.indexOf('\n') + 1, -1); + response = response.left(response.indexOf('\n')).trimmed(); + + voices = response.mid(1, response.size()-2).split(' '); + + voices.sort(); + if (voices.size() == 1 && voices[0].size() == 0) + voices.removeAt(0); + if (voices.size() > 0) + qDebug() << "Voices: " << voices; + else + qDebug() << "No voices."; + return voices; } QString TTSFestival::getVoiceInfo(QString voice) { - if(!configOk()) - return ""; - - if(!getVoiceList().contains(voice)) - return ""; - - if(voiceDescriptions.contains(voice)) - return voiceDescriptions[voice]; - - QString response = queryServer(QString("(voice.description '%1)").arg(voice), 3000); - - if (response == "") - { - voiceDescriptions[voice]=tr("No description available"); - } - else - { - response = response.remove(QRegExp("(description \"*\")", Qt::CaseInsensitive, QRegExp::Wildcard)); - qDebug() << "voiceInfo w/o descr: " << response; - response = response.remove(')'); - QStringList responseLines = response.split('(', QString::SkipEmptyParts); - responseLines.removeAt(0); // the voice name itself - - QString description; - foreach(QString line, responseLines) - { - line = line.remove('('); - line = line.simplified(); - - line[0] = line[0].toUpper(); // capitalize the key - - int firstSpace = line.indexOf(' '); - if (firstSpace > 0) - { - line = line.insert(firstSpace, ':'); // add a colon between the key and the value - line[firstSpace+2] = line[firstSpace+2].toUpper(); // capitalize the value - } - - description += line + "\n"; - } - voiceDescriptions[voice] = description.trimmed(); - } - return voiceDescriptions[voice]; + if(!configOk()) + return ""; + + if(!getVoiceList().contains(voice)) + return ""; + + if(voiceDescriptions.contains(voice)) + return voiceDescriptions[voice]; + + QString response = queryServer(QString("(voice.description '%1)").arg(voice), 3000); + + if (response == "") + { + voiceDescriptions[voice]=tr("No description available"); + } + else + { + response = response.remove(QRegExp("(description \"*\")", Qt::CaseInsensitive, QRegExp::Wildcard)); + qDebug() << "voiceInfo w/o descr: " << response; + response = response.remove(')'); + QStringList responseLines = response.split('(', QString::SkipEmptyParts); + responseLines.removeAt(0); // the voice name itself + + QString description; + foreach(QString line, responseLines) + { + line = line.remove('('); + line = line.simplified(); + + line[0] = line[0].toUpper(); // capitalize the key + + int firstSpace = line.indexOf(' '); + if (firstSpace > 0) + { + line = line.insert(firstSpace, ':'); // add a colon between the key and the value + line[firstSpace+2] = line[firstSpace+2].toUpper(); // capitalize the value + } + + description += line + "\n"; + } + voiceDescriptions[voice] = description.trimmed(); + } + return voiceDescriptions[voice]; } QString TTSFestival::queryServer(QString query, int timeout) { - if(!configOk()) - return ""; - - ensureServerRunning(); - - qDebug() << "queryServer with " << query; - QString response; - - QDateTime endTime; - if(timeout > 0) - endTime = QDateTime::currentDateTime().addMSecs(timeout); - - /* Festival is *extremely* unreliable. Although at this - * point we are sure that SIOD is accepting commands, - * we might end up with an empty response. Hence, the loop. - */ - while(true) - { - QApplication::processEvents(QEventLoop::AllEvents, 50); - QTcpSocket socket; - - socket.connectToHost("localhost", 1314); - socket.waitForConnected(); - - if(socket.state() == QAbstractSocket::ConnectedState) - { - socket.write(QString("%1\n").arg(query).toAscii()); - socket.waitForBytesWritten(); - socket.waitForReadyRead(); - - response = socket.readAll().trimmed(); - - if (response != "LP" && response != "") - break; - } - socket.abort(); - socket.disconnectFromHost(); - - if(timeout > 0 && QDateTime::currentDateTime() >= endTime) - return ""; - - /* make sure we wait a little as we don't want to flood the server with requests */ - QDateTime tmpEndTime = QDateTime::currentDateTime().addMSecs(500); - while(QDateTime::currentDateTime() < tmpEndTime) - QApplication::processEvents(QEventLoop::AllEvents); - } - if(response == "nil") - return ""; - - QStringList lines = response.split('\n'); - if(lines.size() > 2) - { - lines.removeFirst(); - lines.removeLast(); - } - else - qDebug() << "Response too short: " << response; - return lines.join("\n"); + if(!configOk()) + return ""; + + ensureServerRunning(); + + qDebug() << "queryServer with " << query; + QString response; + + QDateTime endTime; + if(timeout > 0) + endTime = QDateTime::currentDateTime().addMSecs(timeout); + + /* Festival is *extremely* unreliable. Although at this + * point we are sure that SIOD is accepting commands, + * we might end up with an empty response. Hence, the loop. + */ + while(true) + { + QApplication::processEvents(QEventLoop::AllEvents, 50); + QTcpSocket socket; + + socket.connectToHost("localhost", 1314); + socket.waitForConnected(); + + if(socket.state() == QAbstractSocket::ConnectedState) + { + socket.write(QString("%1\n").arg(query).toAscii()); + socket.waitForBytesWritten(); + socket.waitForReadyRead(); + + response = socket.readAll().trimmed(); + + if (response != "LP" && response != "") + break; + } + socket.abort(); + socket.disconnectFromHost(); + + if(timeout > 0 && QDateTime::currentDateTime() >= endTime) + return ""; + + /* make sure we wait a little as we don't want to flood the server with requests */ + QDateTime tmpEndTime = QDateTime::currentDateTime().addMSecs(500); + while(QDateTime::currentDateTime() < tmpEndTime) + QApplication::processEvents(QEventLoop::AllEvents); + } + if(response == "nil") + return ""; + + QStringList lines = response.split('\n'); + if(lines.size() > 2) + { + lines.removeFirst(); + lines.removeLast(); + } + else + qDebug() << "Response too short: " << response; + return lines.join("\n"); } diff --git a/rbutil/rbutilqt/tts.h b/rbutil/rbutilqt/tts.h index d225d46853..c9262b74c6 100644 --- a/rbutil/rbutilqt/tts.h +++ b/rbutil/rbutilqt/tts.h @@ -19,7 +19,7 @@ * ****************************************************************************/ - + #ifndef TTS_H #define TTS_H @@ -55,16 +55,16 @@ class TTSBase : public QObject virtual bool configOk() { return false; } virtual void setCfg(RbSettings* sett) { settings = sett; } - + static TTSBase* getTTS(QString ttsname); static QStringList getTTSList(); static QString getTTSName(QString tts); - - public slots: - virtual void accept(void){} + + public slots: + virtual void accept(void){} virtual void reject(void){} virtual void reset(void){} - + private: //inits the tts List static void initTTSList(); @@ -77,7 +77,7 @@ class TTSBase : public QObject class TTSSapi : public TTSBase { - Q_OBJECT + Q_OBJECT public: TTSSapi(); virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); @@ -85,13 +85,13 @@ class TTSSapi : public TTSBase virtual bool stop(); virtual void showCfg(); virtual bool configOk(); - + QStringList getVoiceList(QString language); private: QProcess* voicescript; QTextStream* voicestream; QString defaultLanguage; - + QString m_TTSexec; QString m_TTSOpts; QString m_TTSTemplate; @@ -114,7 +114,7 @@ class TTSExes : public TTSBase virtual bool configOk(); virtual void setCfg(RbSettings* sett); - + private: QString m_name; QString m_TTSexec; @@ -125,24 +125,24 @@ class TTSExes : public TTSBase class TTSFestival : public TTSBase { - Q_OBJECT -public: - ~TTSFestival(); - virtual bool configOk(); - virtual bool start(QString *errStr); - virtual bool stop(); - virtual void showCfg(); - virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); - - QStringList getVoiceList(); - QString getVoiceInfo(QString voice); -private: - inline void startServer(); - inline void ensureServerRunning(); - QString queryServer(QString query, int timeout = -1); - QProcess serverProcess; - QStringList voices; - QMap voiceDescriptions; + Q_OBJECT + public: + ~TTSFestival(); + virtual bool configOk(); + virtual bool start(QString *errStr); + virtual bool stop(); + virtual void showCfg(); + virtual TTSStatus voice(QString text,QString wavfile, QString *errStr); + + QStringList getVoiceList(); + QString getVoiceInfo(QString voice); + private: + inline void startServer(); + inline void ensureServerRunning(); + QString queryServer(QString query, int timeout = -1); + QProcess serverProcess; + QStringList voices; + QMap voiceDescriptions; }; #endif diff --git a/rbutil/rbutilqt/ttsgui.cpp b/rbutil/rbutilqt/ttsgui.cpp index 45dd3a86ef..cd4dab1fcf 100644 --- a/rbutil/rbutilqt/ttsgui.cpp +++ b/rbutil/rbutilqt/ttsgui.cpp @@ -16,13 +16,13 @@ * KIND, either express or implied. * ****************************************************************************/ - + #include "ttsgui.h" #include "rbsettings.h" #include "tts.h" #include "browsedirtree.h" - + TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent) { m_sapi= sapi; @@ -31,46 +31,46 @@ TTSSapiGui::TTSSapiGui(TTSSapi* sapi,QDialog* parent) : QDialog(parent) connect(ui.reset,SIGNAL(clicked()),this,SLOT(reset())); connect(ui.languagecombo,SIGNAL(currentIndexChanged(QString)),this,SLOT(updateVoices(QString))); connect(ui.usesapi4,SIGNAL(stateChanged(int)),this,SLOT(useSapi4Changed(int))); -} +} void TTSSapiGui::showCfg() { // try to get config from settings - ui.ttsoptions->setText(settings->ttsOptions("sapi")); + ui.ttsoptions->setText(settings->ttsOptions("sapi")); QString selLang = settings->ttsLang("sapi"); - QString selVoice = settings->ttsVoice("sapi"); + QString selVoice = settings->ttsVoice("sapi"); ui.speed->setValue(settings->ttsSpeed("sapi")); if(settings->ttsUseSapi4()) ui.usesapi4->setCheckState(Qt::Checked); else ui.usesapi4->setCheckState(Qt::Unchecked); - + // fill in language combobox QStringList languages = settings->allLanguages(); - + languages.sort(); ui.languagecombo->clear(); ui.languagecombo->addItems(languages); - + // set saved lang ui.languagecombo->setCurrentIndex(ui.languagecombo->findText(selLang)); - // fill in voice combobox + // fill in voice combobox updateVoices(selLang); - + // set saved lang - ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice)); - + ui.voicecombo->setCurrentIndex(ui.voicecombo->findText(selVoice)); + //show dialog this->exec(); - + } void TTSSapiGui::reset() { - ui.ttsoptions->setText(""); - ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english")); + ui.ttsoptions->setText(""); + ui.languagecombo->setCurrentIndex(ui.languagecombo->findText("english")); } @@ -101,7 +101,7 @@ void TTSSapiGui::updateVoices(QString language) { QStringList Voices = m_sapi->getVoiceList(language); ui.voicecombo->clear(); - ui.voicecombo->addItems(Voices); + ui.voicecombo->addItems(Voices); } @@ -114,7 +114,7 @@ void TTSSapiGui::useSapi4Changed(int) // sync settings settings->sync(); updateVoices(ui.languagecombo->currentText()); - + } TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent) @@ -129,7 +129,7 @@ TTSExesGui::TTSExesGui(QDialog* parent) : QDialog(parent) void TTSExesGui::reset() { ui.ttspath->setText(""); - ui.ttsoptions->setText(""); + ui.ttsoptions->setText(""); } void TTSExesGui::showCfg(QString name) @@ -137,12 +137,12 @@ void TTSExesGui::showCfg(QString name) m_name = name; // try to get config from settings QString exepath =settings->ttsPath(m_name); - ui.ttsoptions->setText(settings->ttsOptions(m_name)); + ui.ttsoptions->setText(settings->ttsOptions(m_name)); ui.ttspath->setText(exepath); - + //show dialog this->exec(); - + } void TTSExesGui::accept(void) @@ -152,7 +152,7 @@ void TTSExesGui::accept(void) settings->setTTSOptions(m_name,ui.ttsoptions->text()); // sync settings settings->sync(); - + this->done(0); } @@ -182,7 +182,7 @@ void TTSExesGui::browse() } TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) : - QDialog(parent), festival(api) + QDialog(parent), festival(api) { ui.setupUi(this); this->setModal(true); @@ -199,31 +199,31 @@ TTSFestivalGui::TTSFestivalGui(TTSFestival* api, QDialog* parent) : void TTSFestivalGui::showCfg() { - qDebug() << "show\tpaths: " << settings->ttsPath("festival") << "\n" - << "\tvoice: " << settings->ttsVoice("festival"); - - // will populate the voices if the paths are correct, - // otherwise, it will require the user to press Refresh - updateVoices(); - - // try to get config from settings - QStringList paths = settings->ttsPath("festival").split(":"); - if(paths.size() == 2) - { - ui.serverPath->setText(paths[0]); - ui.clientPath->setText(paths[1]); - } - - this->setEnabled(true); + qDebug() << "show\tpaths: " << settings->ttsPath("festival") << "\n" + << "\tvoice: " << settings->ttsVoice("festival"); + + // will populate the voices if the paths are correct, + // otherwise, it will require the user to press Refresh + updateVoices(); + + // try to get config from settings + QStringList paths = settings->ttsPath("festival").split(":"); + if(paths.size() == 2) + { + ui.serverPath->setText(paths[0]); + ui.clientPath->setText(paths[1]); + } + + this->setEnabled(true); this->exec(); } void TTSFestivalGui::accept(void) { //save settings in user config - QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); - qDebug() << "set\tpaths: " << newPath << "\n\tvoice: " << ui.voicesBox->currentText(); - settings->setTTSPath("festival", newPath); + QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); + qDebug() << "set\tpaths: " << newPath << "\n\tvoice: " << ui.voicesBox->currentText(); + settings->setTTSPath("festival", newPath); settings->setTTSVoice("festival", ui.voicesBox->currentText()); settings->sync(); @@ -238,102 +238,103 @@ void TTSFestivalGui::reject(void) void TTSFestivalGui::onBrowseClient() { - BrowseDirtree browser(this); - browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - - QFileInfo currentPath(ui.clientPath->text().trimmed()); - if(currentPath.isDir()) - { - browser.setDir(ui.clientPath->text()); - } - else if (currentPath.isFile()) - { - browser.setDir(currentPath.dir().absolutePath()); - } - if(browser.exec() == QDialog::Accepted) - { - qDebug() << browser.getSelected(); - QString exe = browser.getSelected(); - if(!QFileInfo(exe).isExecutable()) - return; - ui.clientPath->setText(exe); - } + BrowseDirtree browser(this); + browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + + QFileInfo currentPath(ui.clientPath->text().trimmed()); + if(currentPath.isDir()) + { + browser.setDir(ui.clientPath->text()); + } + else if (currentPath.isFile()) + { + browser.setDir(currentPath.dir().absolutePath()); + } + if(browser.exec() == QDialog::Accepted) + { + qDebug() << browser.getSelected(); + QString exe = browser.getSelected(); + if(!QFileInfo(exe).isExecutable()) + return; + ui.clientPath->setText(exe); + } } void TTSFestivalGui::onBrowseServer() { - BrowseDirtree browser(this); - browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); - - QFileInfo currentPath(ui.serverPath->text().trimmed()); - if(currentPath.isDir()) - { - browser.setDir(ui.serverPath->text()); - } - else if (currentPath.isFile()) - { - browser.setDir(currentPath.dir().absolutePath()); - } - if(browser.exec() == QDialog::Accepted) - { - qDebug() << browser.getSelected(); - QString exe = browser.getSelected(); - if(!QFileInfo(exe).isExecutable()) - return; - ui.serverPath->setText(exe); - } + BrowseDirtree browser(this); + browser.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); + + QFileInfo currentPath(ui.serverPath->text().trimmed()); + if(currentPath.isDir()) + { + browser.setDir(ui.serverPath->text()); + } + else if (currentPath.isFile()) + { + browser.setDir(currentPath.dir().absolutePath()); + } + if(browser.exec() == QDialog::Accepted) + { + qDebug() << browser.getSelected(); + QString exe = browser.getSelected(); + if(!QFileInfo(exe).isExecutable()) + return; + ui.serverPath->setText(exe); + } } void TTSFestivalGui::onRefreshButton() { - /* Temporarily commit the settings so that we get the new path when we check for voices */ - QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); - QString oldPath = settings->ttsPath("festival"); - qDebug() << "new path: " << newPath << "\n" << "old path: " << oldPath << "\nuse new: " << (newPath != oldPath); - - if(newPath != oldPath) - { - qDebug() << "Using new paths for getVoiceList"; - settings->setTTSPath("festival", newPath); - settings->sync(); - } - - updateVoices(); - - if(newPath != oldPath) - { - settings->setTTSPath("festival", oldPath); - settings->sync(); - } + /* Temporarily commit the settings so that we get the new path when we check for voices */ + QString newPath = QString("%1:%2").arg(ui.serverPath->text().trimmed()).arg(ui.clientPath->text().trimmed()); + QString oldPath = settings->ttsPath("festival"); + qDebug() << "new path: " << newPath << "\n" << "old path: " << oldPath << "\nuse new: " << (newPath != oldPath); + + if(newPath != oldPath) + { + qDebug() << "Using new paths for getVoiceList"; + settings->setTTSPath("festival", newPath); + settings->sync(); + } + + updateVoices(); + + if(newPath != oldPath) + { + settings->setTTSPath("festival", oldPath); + settings->sync(); + } } void TTSFestivalGui::onShowDescription(int state) { - if(state == Qt::Unchecked) - ui.descriptionLabel->setText(""); - else - updateDescription(ui.voicesBox->currentText()); + if(state == Qt::Unchecked) + ui.descriptionLabel->setText(""); + else + updateDescription(ui.voicesBox->currentText()); } void TTSFestivalGui::updateVoices() { - ui.voicesBox->clear(); - ui.voicesBox->addItem(tr("Loading..")); + ui.voicesBox->clear(); + ui.voicesBox->addItem(tr("Loading..")); - QStringList voiceList = festival->getVoiceList(); - ui.voicesBox->clear(); - ui.voicesBox->addItems(voiceList); + QStringList voiceList = festival->getVoiceList(); + ui.voicesBox->clear(); + ui.voicesBox->addItems(voiceList); - ui.voicesBox->setCurrentIndex(ui.voicesBox->findText(settings->ttsVoice("festival"))); + ui.voicesBox->setCurrentIndex(ui.voicesBox->findText(settings->ttsVoice("festival"))); - updateDescription(settings->ttsVoice("festival")); + updateDescription(settings->ttsVoice("festival")); } void TTSFestivalGui::updateDescription(QString value) { - if(ui.showDescriptionCheckbox->checkState() == Qt::Checked) - { - ui.descriptionLabel->setText(tr("Querying festival")); - ui.descriptionLabel->setText(festival->getVoiceInfo(value)); - } + if(ui.showDescriptionCheckbox->checkState() == Qt::Checked) + { + ui.descriptionLabel->setText(tr("Querying festival")); + ui.descriptionLabel->setText(festival->getVoiceInfo(value)); + } } + diff --git a/rbutil/rbutilqt/ttsgui.h b/rbutil/rbutilqt/ttsgui.h index ce7be408ad..693555cb6c 100644 --- a/rbutil/rbutilqt/ttsgui.h +++ b/rbutil/rbutilqt/ttsgui.h @@ -34,71 +34,72 @@ class TTSFestival; class TTSSapiGui : public QDialog { - Q_OBJECT -public: - TTSSapiGui(TTSSapi* sapi,QDialog* parent = NULL); - - void showCfg(); - void setCfg(RbSettings* sett){settings = sett;} -public slots: - - virtual void accept(void); - virtual void reject(void); - virtual void reset(void); - void updateVoices(QString language); - void useSapi4Changed(int); -private: - Ui::SapiCfgFrm ui; - RbSettings* settings; - TTSSapi* m_sapi; + Q_OBJECT + public: + TTSSapiGui(TTSSapi* sapi,QDialog* parent = NULL); + + void showCfg(); + void setCfg(RbSettings* sett){settings = sett;} + public slots: + + virtual void accept(void); + virtual void reject(void); + virtual void reset(void); + void updateVoices(QString language); + void useSapi4Changed(int); + private: + Ui::SapiCfgFrm ui; + RbSettings* settings; + TTSSapi* m_sapi; }; class TTSExesGui : public QDialog { - Q_OBJECT -public: - TTSExesGui(QDialog* parent = NULL); - - void showCfg(QString m_name); - void setCfg(RbSettings* sett){settings = sett;} - -public slots: - virtual void accept(void); - virtual void reject(void); - virtual void reset(void); - void browse(void); -private: - Ui::TTSExesCfgFrm ui; - RbSettings* settings; - QString m_name; + Q_OBJECT + public: + TTSExesGui(QDialog* parent = NULL); + + void showCfg(QString m_name); + void setCfg(RbSettings* sett){settings = sett;} + + public slots: + virtual void accept(void); + virtual void reject(void); + virtual void reset(void); + void browse(void); + private: + Ui::TTSExesCfgFrm ui; + RbSettings* settings; + QString m_name; }; class TTSFestivalGui : public QDialog { - Q_OBJECT -public: - TTSFestivalGui(TTSFestival* festival, QDialog* parent = NULL); - - void showCfg(); - void setCfg(RbSettings* sett){settings = sett;} - -public slots: - virtual void accept(void); - virtual void reject(void); - //virtual void reset(void); - - void onRefreshButton(); - void onShowDescription(int state); - void onBrowseServer(); - void onBrowseClient(); -private: - Ui::TTSFestivalCfgFrm ui; - RbSettings* settings; - TTSFestival* festival; - - void updateVoices(); -private slots: - void updateDescription(QString value); + Q_OBJECT + public: + TTSFestivalGui(TTSFestival* festival, QDialog* parent = NULL); + + void showCfg(); + void setCfg(RbSettings* sett){settings = sett;} + + public slots: + virtual void accept(void); + virtual void reject(void); + //virtual void reset(void); + + void onRefreshButton(); + void onShowDescription(int state); + void onBrowseServer(); + void onBrowseClient(); + private: + Ui::TTSFestivalCfgFrm ui; + RbSettings* settings; + TTSFestival* festival; + + void updateVoices(); + private slots: + void updateDescription(QString value); }; #endif + diff --git a/rbutil/rbutilqt/voicefile.cpp b/rbutil/rbutilqt/voicefile.cpp index 6a04107cea..873329a47b 100644 --- a/rbutil/rbutilqt/voicefile.cpp +++ b/rbutil/rbutilqt/voicefile.cpp @@ -40,15 +40,15 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger) m_abort = false; m_logger = logger; m_logger->addItem(tr("Starting Voicefile generation"),LOGINFO); - + // test if tempdir exists if(!QDir(QDir::tempPath()+"/rbvoice/").exists()) { QDir(QDir::tempPath()).mkdir("rbvoice"); } - - m_path = QDir::tempPath() + "/rbvoice/"; - + + m_path = QDir::tempPath() + "/rbvoice/"; + // read rockbox-info.txt RockboxInfo info(m_mountpoint); if(!info.open()) @@ -58,18 +58,18 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger) emit done(false); return false; } - + QString target = info.target(); QString features = info.features(); QString version = info.version(); version = version.left(version.indexOf("-")).remove(0,1); - + //prepare download url QUrl genlangUrl = settings->genlangUrl() +"?lang=" +m_lang+"&t="+target+"&rev="+version+"&f="+features; - + qDebug() << "downloading " << genlangUrl; - - //download the correct genlang output + + //download the correct genlang output QTemporaryFile *downloadFile = new QTemporaryFile(this); downloadFile->open(); filename = downloadFile->fileName(); @@ -77,11 +77,11 @@ bool VoiceFileCreator::createVoiceFile(ProgressloggerInterface* logger) // get the real file. getter = new HttpGet(this); getter->setFile(downloadFile); - + connect(getter, SIGNAL(done(bool)), this, SLOT(downloadDone(bool))); connect(getter, SIGNAL(dataReadProgress(int, int)), this, SLOT(updateDataReadProgress(int, int))); connect(m_logger, SIGNAL(aborted()), getter, SLOT(abort())); - + getter->getFile(genlangUrl); return true; } @@ -113,9 +113,9 @@ void VoiceFileCreator::downloadDone(bool error) } else m_logger->addItem(tr("Download finished."),LOGOK); QCoreApplication::processEvents(); - - - m_logger->setProgressMax(0); + + + m_logger->setProgressMax(0); //open downloaded file QFile genlang(filename); if(!genlang.open(QIODevice::ReadOnly)) @@ -124,12 +124,12 @@ void VoiceFileCreator::downloadDone(bool error) m_logger->abort(); emit done(false); return; - } + } //tts - m_tts = TTSBase::getTTS(settings->curTTS()); + m_tts = TTSBase::getTTS(settings->curTTS()); m_tts->setCfg(settings); - + QString errStr; if(!m_tts->start(&errStr)) { @@ -141,9 +141,9 @@ void VoiceFileCreator::downloadDone(bool error) } // Encoder - m_enc = EncBase::getEncoder(settings->curEncoder()); + m_enc = EncBase::getEncoder(settings->curEncoder()); m_enc->setCfg(settings); - + if(!m_enc->start()) { m_logger->addItem(tr("Init of Encoder engine failed"),LOGERROR); @@ -155,15 +155,15 @@ void VoiceFileCreator::downloadDone(bool error) QCoreApplication::processEvents(); connect(m_logger,SIGNAL(aborted()),this,SLOT(abort())); - + //read in downloaded file - QList > voicepairs; + QList > voicepairs; QTextStream in(&genlang); in.setCodec("UTF-8"); QString id, voice; bool idfound = false; bool voicefound=false; - while (!in.atEnd()) + while (!in.atEnd()) { QString line = in.readLine(); if(line.contains("id:")) //ID found @@ -176,58 +176,58 @@ void VoiceFileCreator::downloadDone(bool error) voice = line.remove("voice:").remove('"').trimmed(); voicefound=true; } - + if(idfound && voicefound) { voicepairs.append(QPair(id,voice)); idfound=false; voicefound=false; - } + } } genlang.close(); - + // check for empty list if(voicepairs.size() == 0) { - m_logger->addItem(tr("The downloaded file was empty!"),LOGERROR); + m_logger->addItem(tr("The downloaded file was empty!"),LOGERROR); m_logger->abort(); m_tts->stop(); emit done(false); return; } - + m_logger->setProgressMax(voicepairs.size()); m_logger->setProgressValue(0); - + // create voice clips QStringList mp3files; for(int i=0; i< voicepairs.size(); i++) - { + { if(m_abort) { - m_logger->addItem("aborted.",LOGERROR); + m_logger->addItem("aborted.",LOGERROR); m_logger->abort(); m_tts->stop(); emit done(false); return; - } - + } + m_logger->setProgressValue(i); - + QString wavname = m_path + "/" + voicepairs.at(i).first + ".wav"; QString toSpeak = voicepairs.at(i).second; QString encodedname = m_path + "/" + voicepairs.at(i).first +".mp3"; - + // todo PAUSE if(voicepairs.at(i).first == "VOICE_PAUSE") { QFile::copy(":/builtin/builtin/VOICE_PAUSE.wav",m_path + "/VOICE_PAUSE.wav"); - + } else - { + { if(toSpeak == "") continue; - + m_logger->addItem(tr("creating ")+toSpeak,LOGINFO); QCoreApplication::processEvents(); @@ -235,26 +235,26 @@ void VoiceFileCreator::downloadDone(bool error) QString errStr; m_tts->voice(toSpeak,wavname, &errStr); // generate wav } - + // todo strip char buffer[255]; - + wavtrim((char*)qPrintable(wavname),m_wavtrimThreshold,buffer,255); - - // encode wav + + // encode wav m_enc->encode(wavname,encodedname); - // remove the wav file + // remove the wav file QFile::remove(wavname); // remember the mp3 file for later removing mp3files << encodedname; } - - - //make voicefile + + + //make voicefile FILE* ids2 = fopen(filename.toUtf8(), "r"); if (ids2 == NULL) { - m_logger->addItem(tr("Error opening downloaded file"),LOGERROR); + m_logger->addItem(tr("Error opening downloaded file"),LOGERROR); m_logger->abort(); emit done(false); return; @@ -263,32 +263,32 @@ void VoiceFileCreator::downloadDone(bool error) FILE* output = fopen(QString(m_mountpoint + "/.rockbox/langs/" + m_lang + ".voice").toUtf8(), "wb"); if (output == NULL) { - m_logger->addItem(tr("Error opening output file"),LOGERROR); - emit done(false); + m_logger->addItem(tr("Error opening output file"),LOGERROR); + emit done(false); return; } - + voicefont(ids2,m_targetid,(char*)(const char*)m_path.toUtf8(), output); - + //remove .mp3 files for(int i=0;i< mp3files.size(); i++) { QFile::remove(mp3files.at(i)); - } + } // Add Voice file to the install log QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0); - installlog.beginGroup("selfcreated Voice"); + installlog.beginGroup("selfcreated Voice"); installlog.setValue("/.rockbox/langs/" + m_lang + ".voice",QDate::currentDate().toString("yyyyMMdd")); installlog.endGroup(); installlog.sync(); m_logger->setProgressMax(100); m_logger->setProgressValue(100); - m_logger->addItem(tr("successfully created."),LOGOK); - m_logger->abort(); + m_logger->addItem(tr("successfully created."),LOGOK); + m_logger->abort(); - emit done(true); + emit done(true); } void VoiceFileCreator::updateDataReadProgress(int read, int total) diff --git a/rbutil/rbutilqt/voicefile.h b/rbutil/rbutilqt/voicefile.h index df4ebaccfd..39205db756 100644 --- a/rbutil/rbutilqt/voicefile.h +++ b/rbutil/rbutilqt/voicefile.h @@ -45,39 +45,40 @@ public: // set infos void setSettings(RbSettings* sett) { settings = sett;} - + void setMountPoint(QString mountpoint) {m_mountpoint =mountpoint; } void setTargetId(int id){m_targetid = id;} void setLang(QString name){m_lang =name;} void setWavtrimThreshold(int th){m_wavtrimThreshold = th;} - + signals: void done(bool error); - + private slots: void abort(); void downloadDone(bool error); void updateDataReadProgress(int read, int total); - + private: - + // ptr to encoder, tts and settings TTSBase* m_tts; EncBase* m_enc; RbSettings* settings; HttpGet *getter; - + QString filename; //the temporary file - + QString m_mountpoint; //mountpoint of the device QString m_path; //path where the wav and mp3 files are stored to int m_targetid; //the target id QString m_lang; // the language which will be spoken int m_wavtrimThreshold; - + ProgressloggerInterface* m_logger; bool m_abort; }; - + #endif + -- cgit v1.2.3