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
)
28 bool TalkFileCreator::initEncoder()
30 QFileInfo
enc(m_EncExec
);
41 bool TalkFileCreator::initTTS()
43 QFileInfo
tts(m_TTSexec
);
55 bool TalkFileCreator::createTalkFiles(ProgressloggerInterface
* logger
)
59 m_logger
->addItem("Starting Talkfile generation",LOGINFO
);
62 m_logger
->addItem("Init of TTS engine failed",LOGERROR
);
67 m_logger
->addItem("Init of encoder failed",LOGERROR
);
70 QApplication::processEvents();
72 connect(logger
,SIGNAL(aborted()),this,SLOT(abort()));
73 m_logger
->setProgressMax(0);
74 QDirIterator
it(m_dir
,QDirIterator::Subdirectories
);
75 QSettings
installlog(m_mountpoint
+ "/.rockbox/rbutil.log", QSettings::IniFormat
, 0);
76 installlog
.beginGroup("talkfiles");
77 // iterate over all entrys
82 m_logger
->addItem("Talkfile creation aborted",LOGERROR
);
86 QApplication::processEvents();
87 QFileInfo fileInf
= it
.fileInfo();
92 if(fileInf
.fileName() == "." || fileInf
.fileName() == ".." || fileInf
.suffix() == "talk")
97 if(fileInf
.isDir()) // if it is a dir
99 toSpeak
= fileInf
.fileName();
100 filename
= fileInf
.absolutePath() + "/_dirname.talk";
102 else // if it is a file
104 if(m_stripExtensions
)
105 toSpeak
= fileInf
.baseName();
107 toSpeak
= fileInf
.fileName();
108 filename
= fileInf
.absoluteFilePath() + ".talk";
110 wavfilename
= filename
+ ".wav";
112 QFileInfo
filenameInf(filename
);
113 QFileInfo
wavfilenameInf(wavfilename
);
115 if(!filenameInf
.exists() || m_overwriteTalk
)
117 if(!wavfilenameInf
.exists() || m_overwriteWav
)
119 m_logger
->addItem("Voicing of " + toSpeak
,LOGINFO
);
120 if(!voice(toSpeak
,wavfilename
))
122 m_logger
->addItem("Voicing of " + toSpeak
+ " failed",LOGERROR
);
127 m_logger
->addItem("Encoding of " + toSpeak
,LOGINFO
);
128 if(!encode(wavfilename
,filename
))
130 m_logger
->addItem("Encoding of " + wavfilename
+ " failed",LOGERROR
);
138 QFile
wavfile(wavfilename
);
140 installlog
.remove(wavfilename
);
143 installlog
.setValue(wavfilename
.remove(m_mountpoint
),installlog
.value(wavfilename
,0).toInt()+1);
145 installlog
.setValue(filename
.remove(m_mountpoint
),installlog
.value(filename
,0).toInt()+1);
149 installlog
.endGroup();
150 m_logger
->addItem("Finished creating Talkfiles",LOGOK
);
151 m_logger
->setProgressMax(1);
152 m_logger
->setProgressValue(1);
159 void TalkFileCreator::abort()
164 bool TalkFileCreator::voice(QString text
,QString wavfile
)
167 QString execstring
= m_curTTSTemplate
;
169 execstring
.replace("%exe",m_TTSexec
);
170 execstring
.replace("%options",m_TTSOpts
);
171 execstring
.replace("%wavfile",wavfile
);
172 execstring
.replace("%text",text
);
174 QProcess::execute(execstring
);
179 bool TalkFileCreator::encode(QString input
,QString output
)
181 QString execstring
= m_curEncTemplate
;
183 execstring
.replace("%exe",m_EncExec
);
184 execstring
.replace("%options",m_EncOpts
);
185 execstring
.replace("%input",input
);
186 execstring
.replace("%output",output
);
188 QProcess::execute(execstring
);