1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Dominik Riebeling 2012-10-06 13:44:39 +02:00
parent 7f76bb48b3
commit 2c3b8bd1e2
8 changed files with 182 additions and 25 deletions

View file

@ -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;
}

View file

@ -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();

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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