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();
87 QString path
= fileInf
.filePath();
90 if( path
.endsWith("..") || path
.endsWith(".talk") )
99 // skip entry if folder talking isnt enabled
100 if(m_talkFolders
== false)
105 int index1
= path
.lastIndexOf("/");
106 int index2
= path
.lastIndexOf("/",index1
-1);
108 toSpeak
= path
.mid(index2
+1,(index1
-index2
)-1);
110 filename
= path
.left(index1
) + "/_dirname.talk";
111 qDebug() << "toSpeak: " << toSpeak
<< "filename: " << filename
;
113 else // if it is a file
115 // skip entry if file talking isnt enabled
116 if(m_talkFiles
== false)
121 if(m_stripExtensions
)
122 toSpeak
= fileInf
.baseName();
124 toSpeak
= fileInf
.fileName();
125 filename
= fileInf
.absoluteFilePath() + ".talk";
127 wavfilename
= filename
+ ".wav";
129 QFileInfo
filenameInf(filename
);
130 QFileInfo
wavfilenameInf(wavfilename
);
132 //! the actual generation of the .talk files
133 if(!filenameInf
.exists() || m_overwriteTalk
)
135 if(!wavfilenameInf
.exists() || m_overwriteWav
)
137 m_logger
->addItem(tr("Voicing of %1").arg(toSpeak
),LOGINFO
);
138 if(!m_tts
->voice(toSpeak
,wavfilename
))
140 m_logger
->addItem(tr("Voicing of %s failed").arg(toSpeak
),LOGERROR
);
147 QCoreApplication::processEvents();
149 m_logger
->addItem(tr("Encoding of %1").arg(toSpeak
),LOGINFO
);
150 if(!m_enc
->encode(wavfilename
,filename
))
152 m_logger
->addItem(tr("Encoding of %1 failed").arg(wavfilename
),LOGERROR
);
159 QCoreApplication::processEvents();
162 //! remove the intermedia wav file, if requested
163 QString now
= QDate::currentDate().toString("yyyyMMdd");
166 QFile
wavfile(wavfilename
);
168 installlog
.remove(wavfilename
);
171 installlog
.setValue(wavfilename
.remove(0,m_mountpoint
.length()),now
);
173 //! add the .talk file to the install log
174 installlog
.setValue(filename
.remove(0,m_mountpoint
.length()),now
);
178 installlog
.endGroup();
180 m_logger
->addItem(tr("Finished creating Talk files"),LOGOK
);
181 m_logger
->setProgressMax(1);
182 m_logger
->setProgressValue(1);
189 void TalkFileCreator::abort()