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"
24 TalkGenerator::TalkGenerator(QObject
* parent
): QObject(parent
)
29 //! \brief Creates Talkfiles.
31 TalkGenerator::Status
TalkGenerator::process(QList
<TalkEntry
>* list
,int wavtrimth
)
35 bool warnings
= false;
38 emit
logItem(tr("Starting TTS Engine"),LOGINFO
);
39 m_tts
= TTSBase::getTTS(this,RbSettings::value(RbSettings::Tts
).toString());
40 if(!m_tts
->start(&errStr
))
42 emit
logItem(errStr
.trimmed(),LOGERROR
);
43 emit
logItem(tr("Init of TTS engine failed"),LOGERROR
);
47 QCoreApplication::processEvents();
50 emit
logItem(tr("Starting Encoder Engine"),LOGINFO
);
51 m_enc
= EncBase::getEncoder(this,RbSettings::value(RbSettings::CurEncoder
).toString());
54 emit
logItem(tr("Init of Encoder engine failed"),LOGERROR
);
59 QCoreApplication::processEvents();
61 emit
logProgress(0,0);
64 emit
logItem(tr("Voicing entries..."),LOGINFO
);
65 Status voiceStatus
= voiceList(list
,wavtrimth
);
66 if(voiceStatus
== eERROR
)
73 else if( voiceStatus
== eWARNING
)
76 QCoreApplication::processEvents();
79 emit
logItem(tr("Encoding files..."),LOGINFO
);
80 Status encoderStatus
= encodeList(list
);
81 if( encoderStatus
== eERROR
)
88 else if( voiceStatus
== eWARNING
)
91 QCoreApplication::processEvents();
95 emit
logProgress(1,1);
102 //! \brief Voices a List of string
104 TalkGenerator::Status
TalkGenerator::voiceList(QList
<TalkEntry
>* list
,int wavtrimth
)
106 int progressMax
= list
->size();
108 emit
logProgress(m_progress
,progressMax
);
111 QStringList dublicates
;
113 bool warnings
= false;
114 for(int i
=0; i
< list
->size(); i
++)
118 emit
logItem(tr("Voicing aborted"), LOGERROR
);
122 // skip dublicated wav entrys
123 if(!dublicates
.contains(list
->at(i
).wavfilename
))
124 dublicates
.append(list
->at(i
).wavfilename
);
127 qDebug() << "dublicate skipped";
128 (*list
)[i
].voiced
= true;
129 emit
logProgress(++m_progress
,progressMax
);
133 // skip already voiced entrys
134 if(list
->at(i
).voiced
== true)
136 emit
logProgress(++m_progress
,progressMax
);
139 // skip entry whith empty text
140 if(list
->at(i
).toSpeak
== "")
142 emit
logProgress(++m_progress
,progressMax
);
148 qDebug() << "voicing: " << list
->at(i
).toSpeak
<< "to" << list
->at(i
).wavfilename
;
149 TTSStatus status
= m_tts
->voice(list
->at(i
).toSpeak
,list
->at(i
).wavfilename
, &error
);
150 if(status
== Warning
)
153 emit
logItem(tr("Voicing of %1 failed: %2").arg(list
->at(i
).toSpeak
).arg(error
),
156 else if (status
== FatalError
)
158 emit
logItem(tr("Voicing of %1 failed: %2").arg(list
->at(i
).toSpeak
).arg(error
),
163 (*list
)[i
].voiced
= true;
169 wavtrim(list
->at(i
).wavfilename
.toLocal8Bit().data(),wavtrimth
,buffer
,255);
172 emit
logProgress(++m_progress
,progressMax
);
173 QCoreApplication::processEvents();
182 //! \brief Encodes a List of strings
184 TalkGenerator::Status
TalkGenerator::encodeList(QList
<TalkEntry
>* list
)
186 QStringList dublicates
;
188 int progressMax
= list
->size();
190 emit
logProgress(m_progress
,progressMax
);
192 for(int i
=0; i
< list
->size(); i
++)
196 emit
logItem(tr("Encoding aborted"), LOGERROR
);
200 //skip non-voiced entrys
201 if(list
->at(i
).voiced
== false)
203 qDebug() << "non voiced entry" << list
->at(i
).toSpeak
<<"detected";
204 emit
logProgress(++m_progress
,progressMax
);
208 if(!dublicates
.contains(list
->at(i
).talkfilename
))
209 dublicates
.append(list
->at(i
).talkfilename
);
212 qDebug() << "dublicate skipped";
213 (*list
)[i
].encoded
= true;
214 emit
logProgress(++m_progress
,progressMax
);
219 qDebug() << "encoding " << list
->at(i
).wavfilename
<< "to" << list
->at(i
).talkfilename
;
220 if(!m_enc
->encode(list
->at(i
).wavfilename
,list
->at(i
).talkfilename
))
222 emit
logItem(tr("Encoding of %1 failed").arg(list
->at(i
).wavfilename
), LOGERROR
);
225 (*list
)[i
].encoded
= true;
226 emit
logProgress(++m_progress
,progressMax
);
227 QCoreApplication::processEvents();
232 //! \brief slot, which is connected to the abort of the Logger. Sets a flag, so Creating Talkfiles ends at the next possible position
234 void TalkGenerator::abort()