summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/talkfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/talkfile.cpp')
-rw-r--r--rbutil/rbutilqt/talkfile.cpp110
1 files changed, 81 insertions, 29 deletions
diff --git a/rbutil/rbutilqt/talkfile.cpp b/rbutil/rbutilqt/talkfile.cpp
index 2096c8150b..d3e3a24781 100644
--- a/rbutil/rbutilqt/talkfile.cpp
+++ b/rbutil/rbutilqt/talkfile.cpp
@@ -38,26 +38,24 @@ bool TalkFileCreator::initEncoder()
}
}
-bool TalkFileCreator::initTTS()
-{
- QFileInfo tts(m_TTSexec);
-
- if(tts.exists())
- {
- return true;
- }
- else
- {
- return false;
- }
-}
bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
{
m_abort = false;
m_logger = logger;
m_logger->addItem("Starting Talkfile generation",LOGINFO);
- if(!initTTS())
+
+ if(m_curTTS == "sapi")
+ m_tts = new TTSSapi();
+ else
+ m_tts = new TTSExes();
+
+ m_tts->setTTSexe(m_TTSexec);
+ m_tts->setTTsOpts(m_TTSOpts);
+ m_tts->setTTsLanguage(m_TTSLanguage);
+ m_tts->setTTsTemplate(m_curTTSTemplate);
+
+ if(!m_tts->start())
{
m_logger->addItem("Init of TTS engine failed",LOGERROR);
return false;
@@ -65,6 +63,7 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
if(!initEncoder())
{
m_logger->addItem("Init of encoder failed",LOGERROR);
+ m_tts->stop();
return false;
}
QApplication::processEvents();
@@ -80,6 +79,7 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
if(m_abort)
{
m_logger->addItem("Talkfile creation aborted",LOGERROR);
+ m_tts->stop();
return false;
}
@@ -117,10 +117,11 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
if(!wavfilenameInf.exists() || m_overwriteWav)
{
m_logger->addItem("Voicing of " + toSpeak,LOGINFO);
- if(!voice(toSpeak,wavfilename))
+ if(!m_tts->voice(toSpeak,wavfilename))
{
m_logger->addItem("Voicing of " + toSpeak + " failed",LOGERROR);
m_logger->abort();
+ m_tts->stop();
return false;
}
}
@@ -129,6 +130,7 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
{
m_logger->addItem("Encoding of " + wavfilename + " failed",LOGERROR);
m_logger->abort();
+ m_tts->stop();
return false;
}
}
@@ -148,6 +150,7 @@ bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
}
installlog.endGroup();
+ m_tts->stop();
m_logger->addItem("Finished creating Talkfiles",LOGOK);
m_logger->setProgressMax(1);
m_logger->setProgressValue(1);
@@ -162,33 +165,82 @@ void TalkFileCreator::abort()
m_abort = true;
}
-bool TalkFileCreator::voice(QString text,QString wavfile)
+bool TalkFileCreator::encode(QString input,QString output)
{
+ qDebug() << "encoding..";
+ QString execstring = m_curEncTemplate;
- QString execstring = m_curTTSTemplate;
+ execstring.replace("%exe",m_EncExec);
+ execstring.replace("%options",m_EncOpts);
+ execstring.replace("%input",input);
+ execstring.replace("%output",output);
+ qDebug() << execstring;
+ QProcess::execute(execstring);
+ return true;
+
+}
+bool TTSSapi::start()
+{
+ QFileInfo tts(m_TTSexec);
+ if(!tts.exists())
+ return false;
+
+ // create the voice process
+ QString execstring = m_TTSTemplate;
execstring.replace("%exe",m_TTSexec);
execstring.replace("%options",m_TTSOpts);
- execstring.replace("%wavfile",wavfile);
- execstring.replace("%text",text);
+ qDebug() << "init" << execstring;
+ voicescript = new QProcess(NULL);
+ voicescript->start(execstring);
+ if(!voicescript->waitForStarted())
+ return false;
+ return true;
+}
- QProcess::execute(execstring);
+bool TTSSapi::voice(QString text,QString wavfile)
+{
+ QString query = "SPEAK\t"+wavfile+"\t"+text+"\r\n";
+ qDebug() << "voicing" << query;
+ voicescript->write(query.toLocal8Bit());
+ voicescript->write("SYNC\tbla\r\n");
+ voicescript->waitForReadyRead();
return true;
+}
+bool TTSSapi::stop()
+{
+ QString query = "QUIT\r\n";
+ voicescript->write(query.toLocal8Bit());
+ voicescript->waitForFinished();
+ delete voicescript;
+ return true;
}
-bool TalkFileCreator::encode(QString input,QString output)
+bool TTSExes::start()
{
- QString execstring = m_curEncTemplate;
+ QFileInfo tts(m_TTSexec);
+ qDebug() << "ttsexe init";
+ if(tts.exists())
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
- execstring.replace("%exe",m_EncExec);
- execstring.replace("%options",m_EncOpts);
- execstring.replace("%input",input);
- execstring.replace("%output",output);
+bool TTSExes::voice(QString text,QString wavfile)
+{
+ QString execstring = m_TTSTemplate;
+ execstring.replace("%exe",m_TTSexec);
+ execstring.replace("%options",m_TTSOpts);
+ execstring.replace("%wavfile",wavfile);
+ execstring.replace("%text",text);
+ qDebug() << "voicing" << execstring;
QProcess::execute(execstring);
return true;
-}
-
-
+} \ No newline at end of file