2009-10-13 19:54:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Wenger
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-10-06 11:44:39 +00:00
|
|
|
#include <QtCore>
|
2009-10-13 19:54:27 +00:00
|
|
|
#include "ttsexes.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "rbsettings.h"
|
2013-11-03 10:08:18 +00:00
|
|
|
#include "Logger.h"
|
2009-10-13 19:54:27 +00:00
|
|
|
|
2012-10-06 11:44:39 +00:00
|
|
|
TTSExes::TTSExes(QObject* parent) : TTSBase(parent)
|
2009-10-13 19:54:27 +00:00
|
|
|
{
|
2012-10-06 11:44:39 +00:00
|
|
|
/* default to espeak */
|
|
|
|
m_name = "espeak";
|
|
|
|
m_capabilities = TTSBase::CanSpeak;
|
|
|
|
m_TTSTemplate = "\"%exe\" %options -w \"%wavfile\" -- \"%text\"";
|
|
|
|
m_TTSSpeakTemplate = "\"%exe\" %options -- \"%text\"";
|
2009-10-13 19:54:27 +00:00
|
|
|
}
|
|
|
|
|
2012-10-06 11:44:39 +00:00
|
|
|
|
2010-06-04 21:22:25 +00:00
|
|
|
TTSBase::Capabilities TTSExes::capabilities()
|
|
|
|
{
|
2012-10-06 11:44:39 +00:00
|
|
|
return m_capabilities;
|
2010-06-04 21:22:25 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 19:54:27 +00:00
|
|
|
void TTSExes::generateSettings()
|
|
|
|
{
|
2012-01-29 14:36:52 +00:00
|
|
|
loadSettings();
|
|
|
|
insertSetting(eEXEPATH, new EncTtsSetting(this, EncTtsSetting::eSTRING,
|
|
|
|
tr("Path to TTS engine:"), m_TTSexec, EncTtsSetting::eBROWSEBTN));
|
|
|
|
insertSetting(eOPTIONS, new EncTtsSetting(this, EncTtsSetting::eSTRING,
|
|
|
|
tr("TTS engine options:"), m_TTSOpts));
|
2009-10-13 19:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TTSExes::saveSettings()
|
|
|
|
{
|
2012-10-06 11:44:39 +00:00
|
|
|
RbSettings::setSubValue(m_name, RbSettings::TtsPath,
|
2010-03-03 22:26:00 +00:00
|
|
|
getSetting(eEXEPATH)->current().toString());
|
2012-10-06 11:44:39 +00:00
|
|
|
RbSettings::setSubValue(m_name, RbSettings::TtsOptions,
|
2010-03-03 22:26:00 +00:00
|
|
|
getSetting(eOPTIONS)->current().toString());
|
2009-10-13 19:54:27 +00:00
|
|
|
RbSettings::sync();
|
|
|
|
}
|
|
|
|
|
2012-01-29 14:36:52 +00:00
|
|
|
|
|
|
|
void TTSExes::loadSettings(void)
|
2009-10-13 19:54:27 +00:00
|
|
|
{
|
2012-10-06 11:44:39 +00:00
|
|
|
m_TTSexec = RbSettings::subValue(m_name, RbSettings::TtsPath).toString();
|
2012-01-29 14:36:52 +00:00
|
|
|
if(m_TTSexec.isEmpty()) m_TTSexec = Utils::findExecutable(m_name);
|
2012-10-06 11:44:39 +00:00
|
|
|
m_TTSOpts = RbSettings::subValue(m_name, RbSettings::TtsOptions).toString();
|
2012-01-29 14:36:52 +00:00
|
|
|
}
|
|
|
|
|
2009-10-13 19:54:27 +00:00
|
|
|
|
2012-01-29 14:36:52 +00:00
|
|
|
bool TTSExes::start(QString *errStr)
|
|
|
|
{
|
|
|
|
loadSettings();
|
2009-10-13 19:54:27 +00:00
|
|
|
|
|
|
|
QFileInfo tts(m_TTSexec);
|
|
|
|
if(tts.exists())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*errStr = tr("TTS executable not found");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-06 11:44:39 +00:00
|
|
|
TTSStatus TTSExes::voice(QString text, QString wavfile, QString *errStr)
|
2009-10-13 19:54:27 +00:00
|
|
|
{
|
|
|
|
(void) errStr;
|
2012-10-06 11:44:39 +00:00
|
|
|
QString execstring;
|
|
|
|
if(wavfile.isEmpty() && m_capabilities & TTSBase::CanSpeak) {
|
|
|
|
if(m_TTSSpeakTemplate.isEmpty()) {
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_ERROR() << "internal error: TTS announces CanSpeak "
|
|
|
|
"but template empty!";
|
2012-10-06 11:44:39 +00:00
|
|
|
return FatalError;
|
|
|
|
}
|
|
|
|
execstring = m_TTSSpeakTemplate;
|
|
|
|
}
|
|
|
|
else if(wavfile.isEmpty()) {
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_ERROR() << "no output file passed to voice() "
|
|
|
|
"but TTS can't speak directly.";
|
2012-10-06 11:44:39 +00:00
|
|
|
return FatalError;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
execstring = m_TTSTemplate;
|
|
|
|
}
|
2009-10-13 19:54:27 +00:00
|
|
|
|
|
|
|
execstring.replace("%exe",m_TTSexec);
|
|
|
|
execstring.replace("%options",m_TTSOpts);
|
|
|
|
execstring.replace("%wavfile",wavfile);
|
|
|
|
execstring.replace("%text",text);
|
2012-01-17 19:18:47 +00:00
|
|
|
|
2009-10-13 19:54:27 +00:00
|
|
|
QProcess::execute(execstring);
|
2012-01-17 19:18:47 +00:00
|
|
|
|
2012-10-06 11:44:39 +00:00
|
|
|
if(!wavfile.isEmpty() && !QFileInfo(wavfile).isFile()) {
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_ERROR() << "output file does not exist:" << wavfile;
|
2012-01-17 19:18:47 +00:00
|
|
|
return FatalError;
|
|
|
|
}
|
2009-10-13 19:54:27 +00:00
|
|
|
return NoError;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TTSExes::configOk()
|
|
|
|
{
|
2012-01-29 14:36:52 +00:00
|
|
|
loadSettings();
|
2020-08-21 18:45:59 +00:00
|
|
|
if (QFileInfo::exists(m_TTSexec))
|
2009-10-13 19:54:27 +00:00
|
|
|
return true;
|
2012-01-29 14:36:52 +00:00
|
|
|
else
|
|
|
|
return false;
|
2009-10-13 19:54:27 +00:00
|
|
|
}
|
2012-01-29 14:36:52 +00:00
|
|
|
|