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 ****************************************************************************/
22 TalkFileCreator::TalkFileCreator(QObject
* parent
): QObject(parent
)
27 bool TalkFileCreator::createTalkFiles(ProgressloggerInterface
* logger
)
31 m_logger
->addItem(tr("Starting Talk file generation"),LOGINFO
);
34 m_tts
= TTSBase::getTTS(settings
->curTTS());
35 m_tts
->setCfg(settings
);
38 if(!m_tts
->start(&errStr
))
40 m_logger
->addItem(errStr
,LOGERROR
);
41 m_logger
->addItem(tr("Init of TTS engine failed"),LOGERROR
);
47 m_enc
= EncBase::getEncoder(settings
->curEncoder());
48 m_enc
->setCfg(settings
);
52 m_logger
->addItem(tr("Init of Encoder engine failed"),LOGERROR
);
58 QCoreApplication::processEvents();
60 connect(logger
,SIGNAL(aborted()),this,SLOT(abort()));
61 m_logger
->setProgressMax(0);
63 QDirIterator::IteratorFlags flags
= QDirIterator::NoIteratorFlags
;
65 flags
= QDirIterator::Subdirectories
;
67 QDirIterator
it(m_dir
,flags
);
68 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
69 installlog
.beginGroup("talkfiles");
70 // iterate over all entrys
75 m_logger
->addItem(tr("Talk file creation aborted"),LOGERROR
);
81 QCoreApplication::processEvents();
82 QFileInfo fileInf
= it
.fileInfo();
88 QString path
= fileInf
.filePath();
91 if( path
.endsWith("..") || path
.endsWith(".") || path
.endsWith(".talk") )
100 // skip entry if folder talking isnt enabled
101 if(m_talkFolders
== false)
107 toSpeak
= fileInf
.fileName();
109 filepath
= fileInf
.filePath() + "/";
110 filename
= "_dirname.talk";
111 qDebug() << "toSpeak: " << toSpeak
<< "filename: " << filename
<< " path: " <<filepath
;
113 else // if it is a file
115 // skip entry if file talking isnt enabled
116 if(m_talkFiles
== false)
122 // create toSpeak string
123 if(m_stripExtensions
)
124 toSpeak
= fileInf
.baseName();
126 toSpeak
= fileInf
.fileName();
127 // create filename and path
128 filepath
= fileInf
.absolutePath();
129 filename
= fileInf
.fileName() + ".talk";
133 wavfilename
= QDir::tempPath()+ "/"+ filename
+ ".wav";
135 QFileInfo
filenameInf(filepath
+filename
);
136 QFileInfo
wavfilenameInf(wavfilename
);
138 //! the actual generation of the .talk files
139 if(!filenameInf
.exists() || m_overwriteTalk
)
141 if(!wavfilenameInf
.exists() || m_overwriteWav
)
143 m_logger
->addItem(tr("Voicing of %1").arg(toSpeak
),LOGINFO
);
144 if(!m_tts
->voice(toSpeak
,wavfilename
))
146 m_logger
->addItem(tr("Voicing of %s failed").arg(toSpeak
),LOGERROR
);
153 QCoreApplication::processEvents();
155 m_logger
->addItem(tr("Encoding of %1").arg(toSpeak
),LOGINFO
);
156 if(!m_enc
->encode(wavfilename
,filepath
+filename
))
158 m_logger
->addItem(tr("Encoding of %1 failed").arg(wavfilename
),LOGERROR
);
165 QCoreApplication::processEvents();
168 //! remove the intermedia wav file, if requested
169 QString now
= QDate::currentDate().toString("yyyyMMdd");
172 QFile
wavfile(wavfilename
);
174 installlog
.remove(wavfilename
);
177 installlog
.setValue(wavfilename
.remove(0,m_mountpoint
.length()),now
);
179 //! add the .talk file to the install log
180 installlog
.setValue(QString(filepath
+filename
).remove(0,m_mountpoint
.length()),now
);
184 installlog
.endGroup();
186 m_logger
->addItem(tr("Finished creating Talk files"),LOGOK
);
187 m_logger
->setProgressMax(1);
188 m_logger
->setProgressValue(1);
195 void TalkFileCreator::abort()