1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2007 by Dominik Wenger
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "talkgenerator.h"
21 #include "rbsettings.h"
22 #include "systeminfo.h"
25 TalkGenerator::TalkGenerator(QObject
* parent
): QObject(parent
)
30 //! \brief Creates Talkfiles.
32 TalkGenerator::Status
TalkGenerator::process(QList
<TalkEntry
>* list
,int wavtrimth
)
36 bool warnings
= false;
39 emit
logItem(tr("Starting TTS Engine"),LOGINFO
);
40 m_tts
= TTSBase::getTTS(this,RbSettings::value(RbSettings::Tts
).toString());
41 if(!m_tts
->start(&errStr
))
43 emit
logItem(errStr
.trimmed(),LOGERROR
);
44 emit
logItem(tr("Init of TTS engine failed"),LOGERROR
);
48 QCoreApplication::processEvents();
51 emit
logItem(tr("Starting Encoder Engine"),LOGINFO
);
52 m_enc
= EncBase::getEncoder(this,SystemInfo::value(SystemInfo::CurEncoder
).toString());
55 emit
logItem(tr("Init of Encoder engine failed"),LOGERROR
);
60 QCoreApplication::processEvents();
62 emit
logProgress(0,0);
65 emit
logItem(tr("Voicing entries..."),LOGINFO
);
66 Status voiceStatus
= voiceList(list
,wavtrimth
);
67 if(voiceStatus
== eERROR
)
74 else if( voiceStatus
== eWARNING
)
77 QCoreApplication::processEvents();
80 emit
logItem(tr("Encoding files..."),LOGINFO
);
81 Status encoderStatus
= encodeList(list
);
82 if( encoderStatus
== eERROR
)
89 else if( voiceStatus
== eWARNING
)
92 QCoreApplication::processEvents();
96 emit
logProgress(1,1);
103 //! \brief Voices a List of string
105 TalkGenerator::Status
TalkGenerator::voiceList(QList
<TalkEntry
>* list
,int wavtrimth
)
107 int progressMax
= list
->size();
109 emit
logProgress(m_progress
,progressMax
);
112 QStringList dublicates
;
114 bool warnings
= false;
115 for(int i
=0; i
< list
->size(); i
++)
119 emit
logItem(tr("Voicing aborted"), LOGERROR
);
123 // skip dublicated wav entrys
124 if(!dublicates
.contains(list
->at(i
).wavfilename
))
125 dublicates
.append(list
->at(i
).wavfilename
);
128 qDebug() << "dublicate skipped";
129 (*list
)[i
].voiced
= true;
130 emit
logProgress(++m_progress
,progressMax
);
134 // skip already voiced entrys
135 if(list
->at(i
).voiced
== true)
137 emit
logProgress(++m_progress
,progressMax
);
140 // skip entry whith empty text
141 if(list
->at(i
).toSpeak
== "")
143 emit
logProgress(++m_progress
,progressMax
);
149 qDebug() << "voicing: " << list
->at(i
).toSpeak
<< "to" << list
->at(i
).wavfilename
;
150 TTSStatus status
= m_tts
->voice(list
->at(i
).toSpeak
,list
->at(i
).wavfilename
, &error
);
151 if(status
== Warning
)
154 emit
logItem(tr("Voicing of %1 failed: %2").arg(list
->at(i
).toSpeak
).arg(error
),
157 else if (status
== FatalError
)
159 emit
logItem(tr("Voicing of %1 failed: %2").arg(list
->at(i
).toSpeak
).arg(error
),
164 (*list
)[i
].voiced
= true;
170 wavtrim(list
->at(i
).wavfilename
.toLocal8Bit().data(),wavtrimth
,buffer
,255);
173 emit
logProgress(++m_progress
,progressMax
);
174 QCoreApplication::processEvents();
183 //! \brief Encodes a List of strings
185 TalkGenerator::Status
TalkGenerator::encodeList(QList
<TalkEntry
>* list
)
187 QStringList dublicates
;
189 int progressMax
= list
->size();
191 emit
logProgress(m_progress
,progressMax
);
193 for(int i
=0; i
< list
->size(); i
++)
197 emit
logItem(tr("Encoding aborted"), LOGERROR
);
201 //skip non-voiced entrys
202 if(list
->at(i
).voiced
== false)
204 qDebug() << "non voiced entry" << list
->at(i
).toSpeak
<<"detected";
205 emit
logProgress(++m_progress
,progressMax
);
209 if(!dublicates
.contains(list
->at(i
).talkfilename
))
210 dublicates
.append(list
->at(i
).talkfilename
);
213 qDebug() << "dublicate skipped";
214 (*list
)[i
].encoded
= true;
215 emit
logProgress(++m_progress
,progressMax
);
220 qDebug() << "encoding " << list
->at(i
).wavfilename
<< "to" << list
->at(i
).talkfilename
;
221 if(!m_enc
->encode(list
->at(i
).wavfilename
,list
->at(i
).talkfilename
))
223 emit
logItem(tr("Encoding of %1 failed").arg(list
->at(i
).wavfilename
), LOGERROR
);
226 (*list
)[i
].encoded
= true;
227 emit
logProgress(++m_progress
,progressMax
);
228 QCoreApplication::processEvents();
233 //! \brief slot, which is connected to the abort of the Logger. Sets a flag, so Creating Talkfiles ends at the next possible position
235 void TalkGenerator::abort()