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
= getTTS(userSettings
->value("tts").toString());
35 m_tts
->setCfg(userSettings
,deviceSettings
);
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
= getEncoder(userSettings
->value("encoder").toString());
48 m_enc
->setUserCfg(userSettings
);
52 m_logger
->addItem(tr("Init of Encoder engine failed"),LOGERROR
);
58 QApplication::processEvents();
60 connect(logger
,SIGNAL(aborted()),this,SLOT(abort()));
61 m_logger
->setProgressMax(0);
62 QDirIterator
it(m_dir
,QDirIterator::Subdirectories
);
63 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
64 installlog
.beginGroup("talkfiles");
65 // iterate over all entrys
70 m_logger
->addItem(tr("Talk file creation aborted"),LOGERROR
);
76 QApplication::processEvents();
77 QFileInfo fileInf
= it
.fileInfo();
82 QString path
= fileInf
.filePath();
85 if( path
.endsWith("..") || path
.endsWith(".talk") )
94 // skip entry if folder talking isnt enabled
95 if(m_talkFolders
== false)
100 int index1
= path
.lastIndexOf("/");
101 int index2
= path
.lastIndexOf("/",index1
-1);
103 toSpeak
= path
.mid(index2
+1,(index1
-index2
)-1);
105 filename
= path
.left(index1
) + "/_dirname.talk";
106 qDebug() << "toSpeak: " << toSpeak
<< "filename: " << filename
;
108 else // if it is a file
110 // skip entry if file talking isnt enabled
111 if(m_talkFiles
== false)
116 if(m_stripExtensions
)
117 toSpeak
= fileInf
.baseName();
119 toSpeak
= fileInf
.fileName();
120 filename
= fileInf
.absoluteFilePath() + ".talk";
122 wavfilename
= filename
+ ".wav";
124 QFileInfo
filenameInf(filename
);
125 QFileInfo
wavfilenameInf(wavfilename
);
127 //! the actual generation of the .talk files
128 if(!filenameInf
.exists() || m_overwriteTalk
)
130 if(!wavfilenameInf
.exists() || m_overwriteWav
)
132 m_logger
->addItem(tr("Voicing of %1").arg(toSpeak
),LOGINFO
);
133 if(!m_tts
->voice(toSpeak
,wavfilename
))
135 m_logger
->addItem(tr("Voicing of %s failed").arg(toSpeak
),LOGERROR
);
141 QApplication::processEvents();
143 m_logger
->addItem(tr("Encoding of %1").arg(toSpeak
),LOGINFO
);
144 if(!m_enc
->encode(wavfilename
,filename
))
146 m_logger
->addItem(tr("Encoding of %1 failed").arg(wavfilename
),LOGERROR
);
152 QApplication::processEvents();
155 //! remove the intermedia wav file, if requested
156 QString now
= QDate::currentDate().toString("yyyyMMdd");
159 QFile
wavfile(wavfilename
);
161 installlog
.remove(wavfilename
);
164 installlog
.setValue(wavfilename
.remove(0,m_mountpoint
.length()),now
);
166 //! add the .talk file to the install log
167 installlog
.setValue(filename
.remove(0,m_mountpoint
.length()),now
);
171 installlog
.endGroup();
173 m_logger
->addItem(tr("Finished creating Talk files"),LOGOK
);
174 m_logger
->setProgressMax(1);
175 m_logger
->setProgressValue(1);
182 void TalkFileCreator::abort()