diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2012-10-06 13:44:39 +0200 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2012-10-06 13:53:09 +0200 |
commit | 2c3b8bd1e2887b8c5c825fa42cced6f8490493b5 (patch) | |
tree | 151bbca70fac0f0e90b99f436a60a422f0903091 /rbutil/rbutilqt/base/ttsexes.cpp | |
parent | 7f76bb48b352984c4de8f40509618763e39f181f (diff) | |
download | rockbox-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/ttsexes.cpp')
-rw-r--r-- | rbutil/rbutilqt/base/ttsexes.cpp | 48 |
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 @@ | |||
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 | ||
23 | TTSExes::TTSExes(QString name,QObject* parent) : TTSBase(parent) | 24 | TTSExes::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 | |||
33 | TTSBase::Capabilities TTSExes::capabilities() | 34 | TTSBase::Capabilities TTSExes::capabilities() |
34 | { | 35 | { |
35 | return RunInParallel; | 36 | return m_capabilities; |
36 | } | 37 | } |
37 | 38 | ||
38 | void TTSExes::generateSettings() | 39 | void TTSExes::generateSettings() |
@@ -46,9 +47,9 @@ void TTSExes::generateSettings() | |||
46 | 47 | ||
47 | void TTSExes::saveSettings() | 48 | void 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 | ||
57 | void TTSExes::loadSettings(void) | 58 | void 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 | ||
65 | bool TTSExes::start(QString *errStr) | 66 | bool 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 | ||
82 | TTSStatus TTSExes::voice(QString text,QString wavfile, QString *errStr) | 82 | TTSStatus 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 | } |