summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base
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
parent7f76bb48b352984c4de8f40509618763e39f181f (diff)
downloadrockbox-2c3b8bd1e2887b8c5c825fa42cced6f8490493b5.tar.gz
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')
-rw-r--r--rbutil/rbutilqt/base/ttsbase.cpp17
-rw-r--r--rbutil/rbutilqt/base/ttscarbon.h4
-rw-r--r--rbutil/rbutilqt/base/ttsespeak.h42
-rw-r--r--rbutil/rbutilqt/base/ttsexes.cpp48
-rw-r--r--rbutil/rbutilqt/base/ttsexes.h10
-rw-r--r--rbutil/rbutilqt/base/ttsflite.h43
-rw-r--r--rbutil/rbutilqt/base/ttsswift.h40
7 files changed, 179 insertions, 25 deletions
diff --git a/rbutil/rbutilqt/base/ttsbase.cpp b/rbutil/rbutilqt/base/ttsbase.cpp
index ae2a78f606..3b8384f534 100644
--- a/rbutil/rbutilqt/base/ttsbase.cpp
+++ b/rbutil/rbutilqt/base/ttsbase.cpp
@@ -16,6 +16,7 @@
*
****************************************************************************/
+#include <QtCore>
#include "ttsbase.h"
#include "ttsfestival.h"
@@ -23,6 +24,9 @@
#include "ttssapi4.h"
#include "ttsmssp.h"
#include "ttsexes.h"
+#include "ttsespeak.h"
+#include "ttsflite.h"
+#include "ttsswift.h"
#if defined(Q_OS_MACX)
#include "ttscarbon.h"
#endif
@@ -32,7 +36,6 @@ QMap<QString,QString> TTSBase::ttsList;
TTSBase::TTSBase(QObject* parent): EncTtsSettingInterface(parent)
{
-
}
// static functions
@@ -80,9 +83,15 @@ TTSBase* TTSBase::getTTS(QObject* parent,QString ttsName)
tts = new TTSCarbon(parent);
else
#endif
- // fix for OS other than WIN or LINUX
- if (true)
- tts = new TTSExes(ttsName, parent);
+ if(ttsName == "espeak")
+ tts = new TTSEspeak(parent);
+ else if(ttsName == "flite")
+ tts = new TTSFlite(parent);
+ else if(ttsName == "swift")
+ tts = new TTSSwift(parent);
+ else if(ttsName == "user")
+ tts = new TTSExes(parent);
+
return tts;
}
diff --git a/rbutil/rbutilqt/base/ttscarbon.h b/rbutil/rbutilqt/base/ttscarbon.h
index 4d7cef24d8..2e9e84aa7d 100644
--- a/rbutil/rbutilqt/base/ttscarbon.h
+++ b/rbutil/rbutilqt/base/ttscarbon.h
@@ -39,7 +39,7 @@ class TTSCarbon : public TTSBase
TTSCarbon(QObject *parent = NULL);
//! Child class should generate a clip
- TTSStatus voice(QString text,QString wavfile, QString* errStr);
+ TTSStatus voice(QString text, QString wavfile, QString* errStr);
//! Child class should do startup
bool start(QString *errStr);
//! child class should stop
@@ -51,7 +51,7 @@ class TTSCarbon : public TTSBase
bool configOk();
//! Child class should generate and insertSetting(..) its settings
void generateSettings();
- //! Chlid class should commit the Settings to permanent storage
+ //! Child class should commit the Settings to permanent storage
void saveSettings();
Capabilities capabilities();
diff --git a/rbutil/rbutilqt/base/ttsespeak.h b/rbutil/rbutilqt/base/ttsespeak.h
new file mode 100644
index 0000000000..85d126e94f
--- /dev/null
+++ b/rbutil/rbutilqt/base/ttsespeak.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+*
+* Copyright (C) 2012 by Dominik Riebeling
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef TTSESPEAK_H
+#define TTSESPEAK_H
+
+#include <QtCore>
+#include "ttsexes.h"
+
+class TTSEspeak : public TTSExes
+{
+ Q_OBJECT
+ public:
+ TTSEspeak(QObject* parent=NULL) : TTSExes(parent)
+ {
+ m_name = "espeak";
+
+ /* default to espeak */
+ m_TTSTemplate = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
+ m_TTSSpeakTemplate = "\"%exe\" %options -- \"%text\"";
+ m_capabilities = TTSBase::CanSpeak;
+ }
+};
+
+#endif
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;
}
diff --git a/rbutil/rbutilqt/base/ttsexes.h b/rbutil/rbutilqt/base/ttsexes.h
index 6f9152ef4b..03252cdc92 100644
--- a/rbutil/rbutilqt/base/ttsexes.h
+++ b/rbutil/rbutilqt/base/ttsexes.h
@@ -21,6 +21,7 @@
#ifndef TTSEXES_H
#define TTSEXES_H
+#include <QtCore>
#include "ttsbase.h"
class TTSExes : public TTSBase
@@ -33,7 +34,7 @@ class TTSExes : public TTSBase
Q_OBJECT
public:
- TTSExes(QString name,QObject* parent=NULL);
+ TTSExes(QObject* parent=NULL);
TTSStatus voice(QString text, QString wavfile, QString *errStr);
bool start(QString *errStr);
bool stop() {return true;}
@@ -47,11 +48,14 @@ class TTSExes : public TTSBase
private:
void loadSettings(void);
+
+ protected:
+ QString m_TTSTemplate;
+ QString m_TTSSpeakTemplate;
QString m_name;
QString m_TTSexec;
QString m_TTSOpts;
- QString m_TTSTemplate;
- QMap<QString,QString> m_TemplateMap;
+ TTSBase::Capabilities m_capabilities;
};
#endif
diff --git a/rbutil/rbutilqt/base/ttsflite.h b/rbutil/rbutilqt/base/ttsflite.h
new file mode 100644
index 0000000000..1d9021108e
--- /dev/null
+++ b/rbutil/rbutilqt/base/ttsflite.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+*
+* Copyright (C) 2012 by Dominik Riebeling
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef TTSFLITE_H
+#define TTSFLITE_H
+
+#include <QtCore>
+#include "ttsexes.h"
+
+class TTSFlite : public TTSExes
+{
+ Q_OBJECT
+ public:
+ TTSFlite(QObject* parent=NULL) : TTSExes(parent)
+ {
+ m_name = "flite";
+
+ /* default to espeak */
+ m_TTSTemplate = "\"%exe\" %options -o \"%wavfile\" -t \"%text\"";
+ m_TTSSpeakTemplate = "";
+ m_capabilities = TTSBase::None;
+
+ }
+};
+
+#endif
diff --git a/rbutil/rbutilqt/base/ttsswift.h b/rbutil/rbutilqt/base/ttsswift.h
new file mode 100644
index 0000000000..9d678a6d92
--- /dev/null
+++ b/rbutil/rbutilqt/base/ttsswift.h
@@ -0,0 +1,40 @@
+/***************************************************************************
+* __________ __ ___.
+* Open \______ \ ____ ____ | | _\_ |__ _______ ___
+* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+* \/ \/ \/ \/ \/
+*
+* Copyright (C) 2012 by Dominik Riebeling
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+* KIND, either express or implied.
+*
+****************************************************************************/
+
+#ifndef TTSSWIFT_H
+#define TTSSWIFT_H
+
+#include <QtCore>
+#include "ttsexes.h"
+
+class TTSSwift : public TTSExes
+{
+ Q_OBJECT
+ public:
+ TTSSwift(QObject* parent=NULL) : TTSExes(parent)
+ {
+ m_name = "swift";
+ m_TTSTemplate = "\"%exe\" %options -o \"%wavfile\" -- \"%text\"";
+ m_TTSSpeakTemplate = "";
+ m_capabilities = TTSBase::None;
+ }
+};
+
+#endif