summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/ttsexes.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-10-06 13:44:39 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-10-06 13:53:09 +0200
commit2c3b8bd1e2887b8c5c825fa42cced6f8490493b5 (patch)
tree151bbca70fac0f0e90b99f436a60a422f0903091 /rbutil/rbutilqt/base/ttsexes.cpp
parent7f76bb48b352984c4de8f40509618763e39f181f (diff)
downloadrockbox-2c3b8bd1e2887b8c5c825fa42cced6f8490493b5.tar.gz
rockbox-2c3b8bd1e2887b8c5c825fa42cced6f8490493b5.tar.bz2
rockbox-2c3b8bd1e2887b8c5c825fa42cced6f8490493b5.zip
Factor out executable based TTS engines to separate subclasses.
Similar as done with SAPI / MSSP make the current implementation for executable based TTS engines a base class and create derived classes for each supported TTS. Removes the need for the implementation to know about the individual TTS engines. Add support for speaking directly (i.e. without going through a temporary wave file, currently only used by espeak). Change-Id: I59bbbd6ee4c2c009b2a8d8e0ab4a9b39ea723d6e
Diffstat (limited to 'rbutil/rbutilqt/base/ttsexes.cpp')
-rw-r--r--rbutil/rbutilqt/base/ttsexes.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/rbutil/rbutilqt/base/ttsexes.cpp b/rbutil/rbutilqt/base/ttsexes.cpp
index 5d06d6c1e6..348db103bc 100644
--- a/rbutil/rbutilqt/base/ttsexes.cpp
+++ b/rbutil/rbutilqt/base/ttsexes.cpp
@@ -16,23 +16,24 @@
*
****************************************************************************/
+#include <QtCore>
#include "ttsexes.h"
#include "utils.h"
#include "rbsettings.h"
-TTSExes::TTSExes(QString name,QObject* parent) : TTSBase(parent)
+TTSExes::TTSExes(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\"";
-
+ /* default to espeak */
+ m_name = "espeak";
+ m_capabilities = TTSBase::CanSpeak;
+ m_TTSTemplate = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
+ m_TTSSpeakTemplate = "\"%exe\" %options -- \"%text\"";
}
+
TTSBase::Capabilities TTSExes::capabilities()
{
- return RunInParallel;
+ return m_capabilities;
}
void TTSExes::generateSettings()
@@ -46,9 +47,9 @@ void TTSExes::generateSettings()
void TTSExes::saveSettings()
{
- RbSettings::setSubValue(m_name,RbSettings::TtsPath,
+ RbSettings::setSubValue(m_name, RbSettings::TtsPath,
getSetting(eEXEPATH)->current().toString());
- RbSettings::setSubValue(m_name,RbSettings::TtsOptions,
+ RbSettings::setSubValue(m_name, RbSettings::TtsOptions,
getSetting(eOPTIONS)->current().toString());
RbSettings::sync();
}
@@ -56,16 +57,15 @@ void TTSExes::saveSettings()
void TTSExes::loadSettings(void)
{
- m_TTSexec = RbSettings::subValue(m_name,RbSettings::TtsPath).toString();
+ m_TTSexec = RbSettings::subValue(m_name, RbSettings::TtsPath).toString();
if(m_TTSexec.isEmpty()) m_TTSexec = Utils::findExecutable(m_name);
- m_TTSOpts = RbSettings::subValue(m_name,RbSettings::TtsOptions).toString();
+ m_TTSOpts = RbSettings::subValue(m_name, RbSettings::TtsOptions).toString();
}
bool TTSExes::start(QString *errStr)
{
loadSettings();
- m_TTSTemplate = m_TemplateMap.value(m_name);
QFileInfo tts(m_TTSexec);
if(tts.exists())
@@ -79,10 +79,26 @@ bool TTSExes::start(QString *errStr)
}
}
-TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr)
+TTSStatus TTSExes::voice(QString text, QString wavfile, QString *errStr)
{
(void) errStr;
- QString execstring = m_TTSTemplate;
+ QString execstring;
+ if(wavfile.isEmpty() && m_capabilities & TTSBase::CanSpeak) {
+ if(m_TTSSpeakTemplate.isEmpty()) {
+ qDebug() << "[TTSExes] internal error: TTS announces CanSpeak "
+ "but template empty!";
+ return FatalError;
+ }
+ execstring = m_TTSSpeakTemplate;
+ }
+ else if(wavfile.isEmpty()) {
+ qDebug() << "[TTSExes] no output file passed to voice() "
+ "but TTS can't speak directly.";
+ return FatalError;
+ }
+ else {
+ execstring = m_TTSTemplate;
+ }
execstring.replace("%exe",m_TTSexec);
execstring.replace("%options",m_TTSOpts);
@@ -91,7 +107,7 @@ TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr)
QProcess::execute(execstring);
- if(!QFileInfo(wavfile).isFile()) {
+ if(!wavfile.isEmpty() && !QFileInfo(wavfile).isFile()) {
qDebug() << "[TTSExes] output file does not exist:" << wavfile;
return FatalError;
}