summaryrefslogtreecommitdiff
path: root/rbutil
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
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')
-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
-rw-r--r--rbutil/rbutilqt/rbutilqt.pri3
8 files changed, 182 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 @@
16 * 16 *
17 ****************************************************************************/ 17 ****************************************************************************/
18 18
19#include <QtCore>
19#include "ttsbase.h" 20#include "ttsbase.h"
20 21
21#include "ttsfestival.h" 22#include "ttsfestival.h"
@@ -23,6 +24,9 @@
23#include "ttssapi4.h" 24#include "ttssapi4.h"
24#include "ttsmssp.h" 25#include "ttsmssp.h"
25#include "ttsexes.h" 26#include "ttsexes.h"
27#include "ttsespeak.h"
28#include "ttsflite.h"
29#include "ttsswift.h"
26#if defined(Q_OS_MACX) 30#if defined(Q_OS_MACX)
27#include "ttscarbon.h" 31#include "ttscarbon.h"
28#endif 32#endif
@@ -32,7 +36,6 @@ QMap<QString,QString> TTSBase::ttsList;
32 36
33TTSBase::TTSBase(QObject* parent): EncTtsSettingInterface(parent) 37TTSBase::TTSBase(QObject* parent): EncTtsSettingInterface(parent)
34{ 38{
35
36} 39}
37 40
38// static functions 41// static functions
@@ -80,9 +83,15 @@ TTSBase* TTSBase::getTTS(QObject* parent,QString ttsName)
80 tts = new TTSCarbon(parent); 83 tts = new TTSCarbon(parent);
81 else 84 else
82#endif 85#endif
83 // fix for OS other than WIN or LINUX 86 if(ttsName == "espeak")
84 if (true) 87 tts = new TTSEspeak(parent);
85 tts = new TTSExes(ttsName, parent); 88 else if(ttsName == "flite")
89 tts = new TTSFlite(parent);
90 else if(ttsName == "swift")
91 tts = new TTSSwift(parent);
92 else if(ttsName == "user")
93 tts = new TTSExes(parent);
94
86 return tts; 95 return tts;
87} 96}
88 97
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
39 TTSCarbon(QObject *parent = NULL); 39 TTSCarbon(QObject *parent = NULL);
40 40
41 //! Child class should generate a clip 41 //! Child class should generate a clip
42 TTSStatus voice(QString text,QString wavfile, QString* errStr); 42 TTSStatus voice(QString text, QString wavfile, QString* errStr);
43 //! Child class should do startup 43 //! Child class should do startup
44 bool start(QString *errStr); 44 bool start(QString *errStr);
45 //! child class should stop 45 //! child class should stop
@@ -51,7 +51,7 @@ class TTSCarbon : public TTSBase
51 bool configOk(); 51 bool configOk();
52 //! Child class should generate and insertSetting(..) its settings 52 //! Child class should generate and insertSetting(..) its settings
53 void generateSettings(); 53 void generateSettings();
54 //! Chlid class should commit the Settings to permanent storage 54 //! Child class should commit the Settings to permanent storage
55 void saveSettings(); 55 void saveSettings();
56 56
57 Capabilities capabilities(); 57 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 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8*
9* Copyright (C) 2012 by Dominik Riebeling
10*
11* This program is free software; you can redistribute it and/or
12* modify it under the terms of the GNU General Public License
13* as published by the Free Software Foundation; either version 2
14* of the License, or (at your option) any later version.
15*
16* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17* KIND, either express or implied.
18*
19****************************************************************************/
20
21#ifndef TTSESPEAK_H
22#define TTSESPEAK_H
23
24#include <QtCore>
25#include "ttsexes.h"
26
27class TTSEspeak : public TTSExes
28{
29 Q_OBJECT
30 public:
31 TTSEspeak(QObject* parent=NULL) : TTSExes(parent)
32 {
33 m_name = "espeak";
34
35 /* default to espeak */
36 m_TTSTemplate = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
37 m_TTSSpeakTemplate = "\"%exe\" %options -- \"%text\"";
38 m_capabilities = TTSBase::CanSpeak;
39 }
40};
41
42#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 @@
16* 16*
17****************************************************************************/ 17****************************************************************************/
18 18
19#include <QtCore>
19#include "ttsexes.h" 20#include "ttsexes.h"
20#include "utils.h" 21#include "utils.h"
21#include "rbsettings.h" 22#include "rbsettings.h"
22 23
23TTSExes::TTSExes(QString name,QObject* parent) : TTSBase(parent) 24TTSExes::TTSExes(QObject* parent) : TTSBase(parent)
24{ 25{
25 m_name = name; 26 /* default to espeak */
26 27 m_name = "espeak";
27 m_TemplateMap["espeak"] = "\"%exe\" %options -w \"%wavfile\" -- \"%text\""; 28 m_capabilities = TTSBase::CanSpeak;
28 m_TemplateMap["flite"] = "\"%exe\" %options -o \"%wavfile\" -t \"%text\""; 29 m_TTSTemplate = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
29 m_TemplateMap["swift"] = "\"%exe\" %options -o \"%wavfile\" -- \"%text\""; 30 m_TTSSpeakTemplate = "\"%exe\" %options -- \"%text\"";
30
31} 31}
32 32
33
33TTSBase::Capabilities TTSExes::capabilities() 34TTSBase::Capabilities TTSExes::capabilities()
34{ 35{
35 return RunInParallel; 36 return m_capabilities;
36} 37}
37 38
38void TTSExes::generateSettings() 39void TTSExes::generateSettings()
@@ -46,9 +47,9 @@ void TTSExes::generateSettings()
46 47
47void TTSExes::saveSettings() 48void TTSExes::saveSettings()
48{ 49{
49 RbSettings::setSubValue(m_name,RbSettings::TtsPath, 50 RbSettings::setSubValue(m_name, RbSettings::TtsPath,
50 getSetting(eEXEPATH)->current().toString()); 51 getSetting(eEXEPATH)->current().toString());
51 RbSettings::setSubValue(m_name,RbSettings::TtsOptions, 52 RbSettings::setSubValue(m_name, RbSettings::TtsOptions,
52 getSetting(eOPTIONS)->current().toString()); 53 getSetting(eOPTIONS)->current().toString());
53 RbSettings::sync(); 54 RbSettings::sync();
54} 55}
@@ -56,16 +57,15 @@ void TTSExes::saveSettings()
56 57
57void TTSExes::loadSettings(void) 58void TTSExes::loadSettings(void)
58{ 59{
59 m_TTSexec = RbSettings::subValue(m_name,RbSettings::TtsPath).toString(); 60 m_TTSexec = RbSettings::subValue(m_name, RbSettings::TtsPath).toString();
60 if(m_TTSexec.isEmpty()) m_TTSexec = Utils::findExecutable(m_name); 61 if(m_TTSexec.isEmpty()) m_TTSexec = Utils::findExecutable(m_name);
61 m_TTSOpts = RbSettings::subValue(m_name,RbSettings::TtsOptions).toString(); 62 m_TTSOpts = RbSettings::subValue(m_name, RbSettings::TtsOptions).toString();
62} 63}
63 64
64 65
65bool TTSExes::start(QString *errStr) 66bool TTSExes::start(QString *errStr)
66{ 67{
67 loadSettings(); 68 loadSettings();
68 m_TTSTemplate = m_TemplateMap.value(m_name);
69 69
70 QFileInfo tts(m_TTSexec); 70 QFileInfo tts(m_TTSexec);
71 if(tts.exists()) 71 if(tts.exists())
@@ -79,10 +79,26 @@ bool TTSExes::start(QString *errStr)
79 } 79 }
80} 80}
81 81
82TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr) 82TTSStatus TTSExes::voice(QString text, QString wavfile, QString *errStr)
83{ 83{
84 (void) errStr; 84 (void) errStr;
85 QString execstring = m_TTSTemplate; 85 QString execstring;
86 if(wavfile.isEmpty() && m_capabilities & TTSBase::CanSpeak) {
87 if(m_TTSSpeakTemplate.isEmpty()) {
88 qDebug() << "[TTSExes] internal error: TTS announces CanSpeak "
89 "but template empty!";
90 return FatalError;
91 }
92 execstring = m_TTSSpeakTemplate;
93 }
94 else if(wavfile.isEmpty()) {
95 qDebug() << "[TTSExes] no output file passed to voice() "
96 "but TTS can't speak directly.";
97 return FatalError;
98 }
99 else {
100 execstring = m_TTSTemplate;
101 }
86 102
87 execstring.replace("%exe",m_TTSexec); 103 execstring.replace("%exe",m_TTSexec);
88 execstring.replace("%options",m_TTSOpts); 104 execstring.replace("%options",m_TTSOpts);
@@ -91,7 +107,7 @@ TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr)
91 107
92 QProcess::execute(execstring); 108 QProcess::execute(execstring);
93 109
94 if(!QFileInfo(wavfile).isFile()) { 110 if(!wavfile.isEmpty() && !QFileInfo(wavfile).isFile()) {
95 qDebug() << "[TTSExes] output file does not exist:" << wavfile; 111 qDebug() << "[TTSExes] output file does not exist:" << wavfile;
96 return FatalError; 112 return FatalError;
97 } 113 }
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 @@
21#ifndef TTSEXES_H 21#ifndef TTSEXES_H
22#define TTSEXES_H 22#define TTSEXES_H
23 23
24#include <QtCore>
24#include "ttsbase.h" 25#include "ttsbase.h"
25 26
26class TTSExes : public TTSBase 27class TTSExes : public TTSBase
@@ -33,7 +34,7 @@ class TTSExes : public TTSBase
33 34
34 Q_OBJECT 35 Q_OBJECT
35 public: 36 public:
36 TTSExes(QString name,QObject* parent=NULL); 37 TTSExes(QObject* parent=NULL);
37 TTSStatus voice(QString text, QString wavfile, QString *errStr); 38 TTSStatus voice(QString text, QString wavfile, QString *errStr);
38 bool start(QString *errStr); 39 bool start(QString *errStr);
39 bool stop() {return true;} 40 bool stop() {return true;}
@@ -47,11 +48,14 @@ class TTSExes : public TTSBase
47 48
48 private: 49 private:
49 void loadSettings(void); 50 void loadSettings(void);
51
52 protected:
53 QString m_TTSTemplate;
54 QString m_TTSSpeakTemplate;
50 QString m_name; 55 QString m_name;
51 QString m_TTSexec; 56 QString m_TTSexec;
52 QString m_TTSOpts; 57 QString m_TTSOpts;
53 QString m_TTSTemplate; 58 TTSBase::Capabilities m_capabilities;
54 QMap<QString,QString> m_TemplateMap;
55}; 59};
56 60
57#endif 61#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 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8*
9* Copyright (C) 2012 by Dominik Riebeling
10*
11* This program is free software; you can redistribute it and/or
12* modify it under the terms of the GNU General Public License
13* as published by the Free Software Foundation; either version 2
14* of the License, or (at your option) any later version.
15*
16* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17* KIND, either express or implied.
18*
19****************************************************************************/
20
21#ifndef TTSFLITE_H
22#define TTSFLITE_H
23
24#include <QtCore>
25#include "ttsexes.h"
26
27class TTSFlite : public TTSExes
28{
29 Q_OBJECT
30 public:
31 TTSFlite(QObject* parent=NULL) : TTSExes(parent)
32 {
33 m_name = "flite";
34
35 /* default to espeak */
36 m_TTSTemplate = "\"%exe\" %options -o \"%wavfile\" -t \"%text\"";
37 m_TTSSpeakTemplate = "";
38 m_capabilities = TTSBase::None;
39
40 }
41};
42
43#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 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8*
9* Copyright (C) 2012 by Dominik Riebeling
10*
11* This program is free software; you can redistribute it and/or
12* modify it under the terms of the GNU General Public License
13* as published by the Free Software Foundation; either version 2
14* of the License, or (at your option) any later version.
15*
16* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17* KIND, either express or implied.
18*
19****************************************************************************/
20
21#ifndef TTSSWIFT_H
22#define TTSSWIFT_H
23
24#include <QtCore>
25#include "ttsexes.h"
26
27class TTSSwift : public TTSExes
28{
29 Q_OBJECT
30 public:
31 TTSSwift(QObject* parent=NULL) : TTSExes(parent)
32 {
33 m_name = "swift";
34 m_TTSTemplate = "\"%exe\" %options -o \"%wavfile\" -- \"%text\"";
35 m_TTSSpeakTemplate = "";
36 m_capabilities = TTSBase::None;
37 }
38};
39
40#endif
diff --git a/rbutil/rbutilqt/rbutilqt.pri b/rbutil/rbutilqt/rbutilqt.pri
index 5ee1f7b9d2..13f7ebc042 100644
--- a/rbutil/rbutilqt/rbutilqt.pri
+++ b/rbutil/rbutilqt/rbutilqt.pri
@@ -111,7 +111,10 @@ HEADERS += \
111 base/encttssettings.h \ 111 base/encttssettings.h \
112 base/ttsbase.h \ 112 base/ttsbase.h \
113 base/ttsexes.h \ 113 base/ttsexes.h \
114 base/ttsespeak.h \
115 base/ttsflite.h \
114 base/ttsfestival.h \ 116 base/ttsfestival.h \
117 base/ttsswift.h \
115 base/ttssapi.h \ 118 base/ttssapi.h \
116 base/ttssapi4.h \ 119 base/ttssapi4.h \
117 base/ttsmssp.h \ 120 base/ttsmssp.h \