1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
*
* Copyright (C) 2007 by Dominik Wenger
* $Id$
*
* 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.
*
****************************************************************************/
#include "talkfile.h"
TalkFileCreator::TalkFileCreator(QObject* parent): QObject(parent)
{
}
bool TalkFileCreator::createTalkFiles(ProgressloggerInterface* logger)
{
m_abort = false;
m_logger = logger;
m_logger->addItem(tr("Starting Talk file generation"),LOGINFO);
//tts
m_tts = TTSBase::getTTS(settings->curTTS());
m_tts->setCfg(settings);
QString errStr;
if(!m_tts->start(&errStr))
{
m_logger->addItem(errStr,LOGERROR);
m_logger->addItem(tr("Init of TTS engine failed"),LOGERROR);
m_logger->abort();
return false;
}
// Encoder
m_enc = EncBase::getEncoder(settings->curEncoder());
m_enc->setCfg(settings);
if(!m_enc->start())
{
m_logger->addItem(tr("Init of Encoder engine failed"),LOGERROR);
m_logger->abort();
m_tts->stop();
return false;
}
QCoreApplication::processEvents();
connect(logger,SIGNAL(aborted()),this,SLOT(abort()));
m_logger->setProgressMax(0);
QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
if(m_recursive)
flags = QDirIterator::Subdirectories;
QDirIterator it(m_dir,flags);
QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, 0);
installlog.beginGroup("talkfiles");
// iterate over all entrys
while (it.hasNext())
{
if(m_abort)
{
m_logger->addItem(tr("Talk file creation aborted"),LOGERROR);
m_logger->abort();
m_tts->stop();
return false;
}
QCoreApplication::processEvents();
QFileInfo fileInf = it.fileInfo();
QString toSpeak;
QString filename;
QString wavfilename;
QString path = fileInf.filePath();
qDebug() << path;
if( path.endsWith("..") || path.endsWith(".talk") )
{
it.next();
continue;
}
//! if it is a dir
if(fileInf.isDir())
{
// skip entry if folder talking isnt enabled
if(m_talkFolders == false)
{
it.next();
continue;
}
int index1 = path.lastIndexOf("/");
int index2 = path.lastIndexOf("/",index1-1);
toSpeak = path.mid(index2+1,(index1-index2)-1);
filename = path.left(index1) + "/_dirname.talk";
qDebug() << "toSpeak: " << toSpeak << "filename: " << filename;
}
else // if it is a file
{
// skip entry if file talking isnt enabled
if(m_talkFiles == false)
{
it.next();
continue;
}
if(m_stripExtensions)
toSpeak = fileInf.baseName();
else
toSpeak = fileInf.fileName();
filename = fileInf.absoluteFilePath() + ".talk";
}
wavfilename = filename + ".wav";
QFileInfo filenameInf(filename);
QFileInfo wavfilenameInf(wavfilename);
//! the actual generation of the .talk files
if(!filenameInf.exists() || m_overwriteTalk)
{
if(!wavfilenameInf.exists() || m_overwriteWav)
{
m_logger->addItem(tr("Voicing of %1").arg(toSpeak),LOGINFO);
if(!m_tts->voice(toSpeak,wavfilename))
{
m_logger->addItem(tr("Voicing of %s failed").arg(toSpeak),LOGERROR);
m_logger->abort();
m_tts->stop();
m_enc->stop();
return false;
}
QCoreApplication::processEvents();
}
m_logger->addItem(tr("Encoding of %1").arg(toSpeak),LOGINFO);
if(!m_enc->encode(wavfilename,filename))
{
m_logger->addItem(tr("Encoding of %1 failed").arg(wavfilename),LOGERROR);
m_logger->abort();
m_tts->stop();
m_enc->stop();
return false;
}
QCoreApplication::processEvents();
}
//! remove the intermedia wav file, if requested
QString now = QDate::currentDate().toString("yyyyMMdd");
if(m_removeWav)
{
QFile wavfile(wavfilename);
wavfile.remove();
installlog.remove(wavfilename);
}
else
installlog.setValue(wavfilename.remove(0,m_mountpoint.length()),now);
//! add the .talk file to the install log
installlog.setValue(filename.remove(0,m_mountpoint.length()),now);
it.next();
}
installlog.endGroup();
m_tts->stop();
m_logger->addItem(tr("Finished creating Talk files"),LOGOK);
m_logger->setProgressMax(1);
m_logger->setProgressValue(1);
m_logger->abort();
return true;
}
void TalkFileCreator::abort()
{
m_abort = true;
}
|