summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/tts.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-09 21:46:05 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-06-09 21:46:05 +0000
commit86041b1d330dfe933b9114ea0d0e252f27b1be59 (patch)
treec0ea83fe2bd2d1c2ee8af36ca20dcec99daf00a1 /rbutil/rbutilqt/base/tts.cpp
parent0711190db13cebeb526246840d7160551cbfea45 (diff)
downloadrockbox-86041b1d330dfe933b9114ea0d0e252f27b1be59.tar.gz
rockbox-86041b1d330dfe933b9114ea0d0e252f27b1be59.tar.bz2
rockbox-86041b1d330dfe933b9114ea0d0e252f27b1be59.zip
Make labels in generated TTS / Encoder setting dialogs translatable.
Code police: break some long lines, remove trailing spaces. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21237 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/base/tts.cpp')
-rw-r--r--rbutil/rbutilqt/base/tts.cpp483
1 files changed, 246 insertions, 237 deletions
diff --git a/rbutil/rbutilqt/base/tts.cpp b/rbutil/rbutilqt/base/tts.cpp
index 5bc4c058c8..4b0727f78c 100644
--- a/rbutil/rbutilqt/base/tts.cpp
+++ b/rbutil/rbutilqt/base/tts.cpp
@@ -47,7 +47,7 @@ void TTSBase::initTTSList()
// function to get a specific encoder
TTSBase* TTSBase::getTTS(QObject* parent,QString ttsName)
{
-
+
TTSBase* tts;
#if defined(Q_OS_WIN)
if(ttsName == "sapi")
@@ -55,13 +55,13 @@ TTSBase* TTSBase::getTTS(QObject* parent,QString ttsName)
tts = new TTSSapi(parent);
return tts;
}
- else
+ else
#endif
#if defined(Q_OS_LINUX)
if (ttsName == "festival")
{
tts = new TTSFestival(parent);
- return tts;
+ return tts;
}
else
#endif
@@ -97,20 +97,22 @@ QString TTSBase::getTTSName(QString tts)
TTSExes::TTSExes(QString name,QObject* parent) : TTSBase(parent)
{
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::generateSettings()
{
QString exepath =RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
if(exepath == "") exepath = findExecutable(m_name);
-
- insertSetting(eEXEPATH,new EncTtsSetting(this,EncTtsSetting::eSTRING,"Path to TTS engine:",exepath,EncTtsSetting::eBROWSEBTN));
- insertSetting(eOPTIONS,new EncTtsSetting(this,EncTtsSetting::eSTRING,"TTS engine options:",RbSettings::subValue(m_name,RbSettings::TtsOptions)));
+
+ insertSetting(eEXEPATH,new EncTtsSetting(this,EncTtsSetting::eSTRING,
+ tr("Path to TTS engine:"),exepath,EncTtsSetting::eBROWSEBTN));
+ insertSetting(eOPTIONS,new EncTtsSetting(this,EncTtsSetting::eSTRING,
+ tr("TTS engine options:"),RbSettings::subValue(m_name,RbSettings::TtsOptions)));
}
void TTSExes::saveSettings()
@@ -124,7 +126,7 @@ bool TTSExes::start(QString *errStr)
{
m_TTSexec = RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
m_TTSOpts = RbSettings::subValue(m_name,RbSettings::TtsOptions).toString();
-
+
m_TTSTemplate = m_TemplateMap.value(m_name);
QFileInfo tts(m_TTSexec);
@@ -141,7 +143,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);
@@ -157,10 +159,10 @@ TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr)
bool TTSExes::configOk()
{
QString path = RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
-
+
if (QFileInfo(path).exists())
return true;
-
+
return false;
}
@@ -178,18 +180,22 @@ void TTSSapi::generateSettings()
{
// language
QStringList languages = RbSettings::languages();
- languages.sort();
- EncTtsSetting* setting =new EncTtsSetting(this,EncTtsSetting::eSTRINGLIST,"Language:",RbSettings::subValue("sapi",RbSettings::TtsLanguage),languages);
+ languages.sort();
+ EncTtsSetting* setting =new EncTtsSetting(this,EncTtsSetting::eSTRINGLIST,
+ tr("Language:"),RbSettings::subValue("sapi",RbSettings::TtsLanguage),languages);
connect(setting,SIGNAL(dataChanged()),this,SLOT(updateVoiceList()));
- insertSetting(eLANGUAGE,setting);
+ insertSetting(eLANGUAGE,setting);
// voice
- setting = new EncTtsSetting(this,EncTtsSetting::eSTRINGLIST,"Voice:",RbSettings::subValue("sapi",RbSettings::TtsVoice),getVoiceList(RbSettings::subValue("sapi",RbSettings::TtsLanguage).toString()),EncTtsSetting::eREFRESHBTN);
+ setting = new EncTtsSetting(this,EncTtsSetting::eSTRINGLIST,
+ tr("Voice:"),RbSettings::subValue("sapi",RbSettings::TtsVoice),getVoiceList(RbSettings::subValue("sapi",RbSettings::TtsLanguage).toString()),EncTtsSetting::eREFRESHBTN);
connect(setting,SIGNAL(refresh()),this,SLOT(updateVoiceList()));
insertSetting(eVOICE,setting);
- //speed
- insertSetting(eSPEED,new EncTtsSetting(this,EncTtsSetting::eINT,"Speed:",RbSettings::subValue("sapi",RbSettings::TtsSpeed),-10,10));
+ //speed
+ insertSetting(eSPEED,new EncTtsSetting(this,EncTtsSetting::eINT,
+ tr("Speed:"),RbSettings::subValue("sapi",RbSettings::TtsSpeed),-10,10));
// options
- insertSetting(eOPTIONS,new EncTtsSetting(this,EncTtsSetting::eSTRING,"Options:",RbSettings::subValue("sapi",RbSettings::TtsOptions)));
+ insertSetting(eOPTIONS,new EncTtsSetting(this,EncTtsSetting::eSTRING,
+ tr("Options:"),RbSettings::subValue("sapi",RbSettings::TtsOptions)));
}
@@ -200,7 +206,7 @@ void TTSSapi::saveSettings()
RbSettings::setSubValue("sapi",RbSettings::TtsVoice,getSetting(eVOICE)->current().toString());
RbSettings::setSubValue("sapi",RbSettings::TtsSpeed,getSetting(eSPEED)->current().toInt());
RbSettings::setSubValue("sapi",RbSettings::TtsOptions,getSetting(eOPTIONS)->current().toString());
-
+
RbSettings::sync();
}
@@ -210,28 +216,28 @@ void TTSSapi::updateVoiceList()
QStringList voiceList = getVoiceList(getSetting(eLANGUAGE)->current().toString());
getSetting(eVOICE)->setList(voiceList);
if(voiceList.size() > 0) getSetting(eVOICE)->setCurrent(voiceList.at(0));
- else getSetting(eVOICE)->setCurrent("");
+ else getSetting(eVOICE)->setCurrent("");
}
bool TTSSapi::start(QString *errStr)
-{
+{
m_TTSOpts = RbSettings::subValue("sapi",RbSettings::TtsOptions).toString();
m_TTSLanguage =RbSettings::subValue("sapi",RbSettings::TtsLanguage).toString();
m_TTSVoice=RbSettings::subValue("sapi",RbSettings::TtsVoice).toString();
m_TTSSpeed=RbSettings::subValue("sapi",RbSettings::TtsSpeed).toString();
m_sapi4 = RbSettings::subValue("sapi",RbSettings::TtsUseSapi4).toBool();
-
+
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);
@@ -239,31 +245,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;
}
@@ -271,31 +277,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(RbSettings::value(RbSettings::TtsUseSapi4).toBool())
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);
if(result.size() > 0)
@@ -306,13 +312,13 @@ 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::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::ReadGroup |QFile::WriteGroup |QFile::ExeGroup
+ |QFile::ReadOther |QFile::WriteOther |QFile::ExeOther );
QFile::remove(QDir::tempPath() +"/sapi_voice.vbs");
return result;
}
@@ -321,7 +327,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 +338,17 @@ 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::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::ReadGroup |QFile::WriteGroup |QFile::ExeGroup
+ |QFile::ReadOther |QFile::WriteOther |QFile::ExeOther );
QFile::remove(QDir::tempPath() +"/sapi_voice.vbs");
return true;
}
@@ -358,7 +364,7 @@ bool TTSSapi::configOk()
**********************************************************************/
TTSFestival::~TTSFestival()
{
- stop();
+ stop();
}
void TTSFestival::generateSettings()
@@ -366,21 +372,24 @@ void TTSFestival::generateSettings()
// server path
QString exepath = RbSettings::subValue("festival-server",RbSettings::TtsPath).toString();
if(exepath == "" ) exepath = findExecutable("festival");
- insertSetting(eSERVERPATH,new EncTtsSetting(this,EncTtsSetting::eSTRING,"Path to Festival server:",exepath,EncTtsSetting::eBROWSEBTN));
-
+ insertSetting(eSERVERPATH,new EncTtsSetting(this,EncTtsSetting::eSTRING,"Path to Festival server:",exepath,EncTtsSetting::eBROWSEBTN));
+
// client path
- QString clientpath = RbSettings::subValue("festival-client",RbSettings::TtsPath).toString();
+ QString clientpath = RbSettings::subValue("festival-client",RbSettings::TtsPath).toString();
if(clientpath == "" ) clientpath = findExecutable("festival_client");
- insertSetting(eCLIENTPATH,new EncTtsSetting(this,EncTtsSetting::eSTRING,"Path to Festival client:",clientpath,EncTtsSetting::eBROWSEBTN));
-
+ insertSetting(eCLIENTPATH,new EncTtsSetting(this,EncTtsSetting::eSTRING,
+ tr("Path to Festival client:"),clientpath,EncTtsSetting::eBROWSEBTN));
+
// voice
- EncTtsSetting* setting = new EncTtsSetting(this,EncTtsSetting::eSTRINGLIST,"Voice:",RbSettings::subValue("festival",RbSettings::TtsVoice),getVoiceList(exepath),EncTtsSetting::eREFRESHBTN);
+ EncTtsSetting* setting = new EncTtsSetting(this,EncTtsSetting::eSTRINGLIST,
+ tr("Voice:"),RbSettings::subValue("festival",RbSettings::TtsVoice),getVoiceList(exepath),EncTtsSetting::eREFRESHBTN);
connect(setting,SIGNAL(refresh()),this,SLOT(updateVoiceList()));
connect(setting,SIGNAL(dataChanged()),this,SLOT(clearVoiceDescription()));
insertSetting(eVOICE,setting);
-
+
//voice description
- setting = new EncTtsSetting(this,EncTtsSetting::eREADONLYSTRING,"Voice description:","",EncTtsSetting::eREFRESHBTN);
+ setting = new EncTtsSetting(this,EncTtsSetting::eREADONLYSTRING,
+ tr("Voice description:"),"",EncTtsSetting::eREFRESHBTN);
connect(setting,SIGNAL(refresh()),this,SLOT(updateVoiceDescription()));
insertSetting(eVOICEDESC,setting);
}
@@ -391,13 +400,13 @@ void TTSFestival::saveSettings()
RbSettings::setSubValue("festival-server",RbSettings::TtsPath,getSetting(eSERVERPATH)->current().toString());
RbSettings::setSubValue("festival-client",RbSettings::TtsPath,getSetting(eCLIENTPATH)->current().toString());
RbSettings::setSubValue("festival",RbSettings::TtsVoice,getSetting(eVOICE)->current().toString());
-
+
RbSettings::sync();
}
void TTSFestival::updateVoiceDescription()
{
- // get voice Info with current voice and path
+ // get voice Info with current voice and path
QString info = getVoiceInfo(getSetting(eVOICE)->current().toString(),getSetting(eSERVERPATH)->current().toString());
getSetting(eVOICEDESC)->setCurrent(info);
}
@@ -417,241 +426,241 @@ void TTSFestival::updateVoiceList()
void TTSFestival::startServer(QString path)
{
- if(!configOk())
- return;
+ if(!configOk())
+ return;
- if(path == "")
+ if(path == "")
path = RbSettings::subValue("festival-server",RbSettings::TtsPath).toString();
- serverProcess.start(QString("%1 --server").arg(path));
- serverProcess.waitForStarted();
+ serverProcess.start(QString("%1 --server").arg(path));
+ serverProcess.waitForStarted();
- queryServer("(getpid)",300,path);
- if(serverProcess.state() == QProcess::Running)
- qDebug() << "Festival is up and running";
- else
- qDebug() << "Festival failed to start";
+ queryServer("(getpid)",300,path);
+ if(serverProcess.state() == QProcess::Running)
+ qDebug() << "Festival is up and running";
+ else
+ qDebug() << "Festival failed to start";
}
void TTSFestival::ensureServerRunning(QString path)
{
- if(serverProcess.state() != QProcess::Running)
- {
- startServer(path);
+ if(serverProcess.state() != QProcess::Running)
+ {
+ startServer(path);
}
}
bool TTSFestival::start(QString* errStr)
{
- (void) errStr;
- ensureServerRunning();
- if (!RbSettings::subValue("festival",RbSettings::TtsVoice).toString().isEmpty())
+ (void) errStr;
+ ensureServerRunning();
+ if (!RbSettings::subValue("festival",RbSettings::TtsVoice).toString().isEmpty())
queryServer(QString("(voice.select '%1)")
.arg(RbSettings::subValue("festival", RbSettings::TtsVoice).toString()));
- 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;
-
- QString path = RbSettings::subValue("festival-client",RbSettings::TtsPath).toString();
- QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(path).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;
+
+ QString path = RbSettings::subValue("festival-client",RbSettings::TtsPath).toString();
+ QString cmd = QString("%1 --server localhost --otype riff --ttw --withlisp --output \"%2\" - ").arg(path).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()
{
- QString serverPath = RbSettings::subValue("festival-server",RbSettings::TtsPath).toString();
+ QString serverPath = RbSettings::subValue("festival-server",RbSettings::TtsPath).toString();
QString clientPath = RbSettings::subValue("festival-client",RbSettings::TtsVoice).toString();
-
- bool ret = QFileInfo(serverPath).isExecutable() &&
- QFileInfo(clientPath).isExecutable();
- if(RbSettings::subValue("festival",RbSettings::TtsVoice).toString().size() > 0 && voices.size() > 0)
- ret = ret && (voices.indexOf(RbSettings::subValue("festival",RbSettings::TtsVoice).toString()) != -1);
- return ret;
+
+ bool ret = QFileInfo(serverPath).isExecutable() &&
+ QFileInfo(clientPath).isExecutable();
+ if(RbSettings::subValue("festival",RbSettings::TtsVoice).toString().size() > 0 && voices.size() > 0)
+ ret = ret && (voices.indexOf(RbSettings::subValue("festival",RbSettings::TtsVoice).toString()) != -1);
+ return ret;
}
QStringList TTSFestival::getVoiceList(QString path)
{
- if(!configOk())
- return QStringList();
+ if(!configOk())
+ return QStringList();
- if(voices.size() > 0)
- {
- qDebug() << "Using voice cache";
- return voices;
- }
-
- QString response = queryServer("(voice.list)",3000,path);
+ if(voices.size() > 0)
+ {
+ qDebug() << "Using voice cache";
+ return voices;
+ }
- // get the 2nd line. It should be (<voice_name>, <voice_name>)
- response = response.mid(response.indexOf('\n') + 1, -1);
- response = response.left(response.indexOf('\n')).trimmed();
+ QString response = queryServer("(voice.list)",3000,path);
- voices = response.mid(1, response.size()-2).split(' ');
+ // get the 2nd line. It should be (<voice_name>, <voice_name>)
+ response = response.mid(response.indexOf('\n') + 1, -1);
+ response = response.left(response.indexOf('\n')).trimmed();
- 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;
+ 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,QString path)
{
- 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,path);
-
- 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,path);
+
+ 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,QString path)
{
- if(!configOk())
- return "";
+ if(!configOk())
+ return "";
// this operation could take some time
- emit busy();
-
+ emit busy();
+
ensureServerRunning(path);
- qDebug() << "queryServer with " << query;
- QString response;
+ qDebug() << "queryServer with " << query;
+ QString response;
- QDateTime endTime;
- if(timeout > 0)
- endTime = QDateTime::currentDateTime().addMSecs(timeout);
+ 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)
- {
- QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
- QTcpSocket socket;
+ /* 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)
+ {
+ QCoreApplication::processEvents(QEventLoop::AllEvents, 50);
+ QTcpSocket socket;
- socket.connectToHost("localhost", 1314);
- socket.waitForConnected();
+ socket.connectToHost("localhost", 1314);
+ socket.waitForConnected();
- if(socket.state() == QAbstractSocket::ConnectedState)
- {
- socket.write(QString("%1\n").arg(query).toAscii());
- socket.waitForBytesWritten();
- socket.waitForReadyRead();
+ if(socket.state() == QAbstractSocket::ConnectedState)
+ {
+ socket.write(QString("%1\n").arg(query).toAscii());
+ socket.waitForBytesWritten();
+ socket.waitForReadyRead();
- response = socket.readAll().trimmed();
+ response = socket.readAll().trimmed();
- if (response != "LP" && response != "")
- break;
- }
- socket.abort();
- socket.disconnectFromHost();
+ if (response != "LP" && response != "")
+ break;
+ }
+ socket.abort();
+ socket.disconnectFromHost();
- if(timeout > 0 && QDateTime::currentDateTime() >= endTime)
+ if(timeout > 0 && QDateTime::currentDateTime() >= endTime)
{
- emit busyEnd();
- return "";
+ emit busyEnd();
+ 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)
- QCoreApplication::processEvents(QEventLoop::AllEvents);
- }
- if(response == "nil")
+ /* 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)
+ QCoreApplication::processEvents(QEventLoop::AllEvents);
+ }
+ if(response == "nil")
{
emit busyEnd();
- return "";
+ return "";
}
-
- QStringList lines = response.split('\n');
- if(lines.size() > 2)
- {
- lines.removeFirst();
- lines.removeLast();
- }
- else
- qDebug() << "Response too short: " << response;
-
- emit busyEnd();
+
+ QStringList lines = response.split('\n');
+ if(lines.size() > 2)
+ {
+ lines.removeFirst();
+ lines.removeLast();
+ }
+ else
+ qDebug() << "Response too short: " << response;
+
+ emit busyEnd();
return lines.join("\n");
-
+
}