diff options
Diffstat (limited to 'rbutil/rbutilqt/base/talkgenerator.cpp')
-rw-r--r-- | rbutil/rbutilqt/base/talkgenerator.cpp | 81 |
1 files changed, 80 insertions, 1 deletions
diff --git a/rbutil/rbutilqt/base/talkgenerator.cpp b/rbutil/rbutilqt/base/talkgenerator.cpp index 9b0cbf4066..4dffe69a42 100644 --- a/rbutil/rbutilqt/base/talkgenerator.cpp +++ b/rbutil/rbutilqt/base/talkgenerator.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | TalkGenerator::TalkGenerator(QObject* parent): QObject(parent), encFutureWatcher(this), ttsFutureWatcher(this) | 25 | TalkGenerator::TalkGenerator(QObject* parent): QObject(parent), encFutureWatcher(this), ttsFutureWatcher(this) |
26 | { | 26 | { |
27 | m_userAborted = false; | 27 | m_userAborted = false; |
28 | m_lang = ""; | ||
28 | } | 29 | } |
29 | 30 | ||
30 | //! \brief Creates Talkfiles. | 31 | //! \brief Creates Talkfiles. |
@@ -113,6 +114,11 @@ TalkGenerator::Status TalkGenerator::voiceList(QList<TalkEntry>* list,int wavtri | |||
113 | (*list)[i].refs.tts = m_tts; | 114 | (*list)[i].refs.tts = m_tts; |
114 | (*list)[i].refs.wavtrim = wavtrimth; | 115 | (*list)[i].refs.wavtrim = wavtrimth; |
115 | (*list)[i].refs.generator = this; | 116 | (*list)[i].refs.generator = this; |
117 | // enable voice corrections only if a language is set. | ||
118 | if(!m_lang.isEmpty()) { | ||
119 | QString s = (*list)[i].toSpeak; | ||
120 | (*list)[i].toSpeak = correctString(s); | ||
121 | } | ||
116 | 122 | ||
117 | // skip duplicated wav entries | 123 | // skip duplicated wav entries |
118 | if(!duplicates.contains(list->at(i).wavfilename)) | 124 | if(!duplicates.contains(list->at(i).wavfilename)) |
@@ -247,7 +253,7 @@ TalkGenerator::Status TalkGenerator::encodeList(QList<TalkEntry>* list) | |||
247 | TalkGenerators.*/ | 253 | TalkGenerators.*/ |
248 | } | 254 | } |
249 | 255 | ||
250 | connect(&encFutureWatcher, SIGNAL(progressValueChanged(int)), | 256 | connect(&encFutureWatcher, SIGNAL(progressValueChanged(int)), |
251 | this, SLOT(encProgress(int))); | 257 | this, SLOT(encProgress(int))); |
252 | encFutureWatcher.setFuture(QtConcurrent::map(*list, &TalkGenerator::encEntryPoint)); | 258 | encFutureWatcher.setFuture(QtConcurrent::map(*list, &TalkGenerator::encEntryPoint)); |
253 | 259 | ||
@@ -302,3 +308,76 @@ void TalkGenerator::abort() | |||
302 | m_userAborted = true; | 308 | m_userAborted = true; |
303 | } | 309 | } |
304 | 310 | ||
311 | QString TalkGenerator::correctString(QString s) | ||
312 | { | ||
313 | QString corrected = s; | ||
314 | int i = 0; | ||
315 | int max = m_corrections.size(); | ||
316 | while(i < max) { | ||
317 | corrected = corrected.replace(QRegExp(m_corrections.at(i).search, | ||
318 | m_corrections.at(i).modifier.contains("i") | ||
319 | ? Qt::CaseInsensitive : Qt::CaseSensitive), | ||
320 | m_corrections.at(i).replace); | ||
321 | i++; | ||
322 | } | ||
323 | |||
324 | if(corrected != s) | ||
325 | qDebug() << "[VoiceFileCreator] corrected string" << s << "to" << corrected; | ||
326 | |||
327 | return corrected; | ||
328 | } | ||
329 | |||
330 | |||
331 | void TalkGenerator::setLang(QString name) | ||
332 | { | ||
333 | m_lang = name; | ||
334 | |||
335 | // re-initialize corrections list | ||
336 | m_corrections.clear(); | ||
337 | QFile correctionsFile(":/builtin/voice-corrections.txt"); | ||
338 | correctionsFile.open(QIODevice::ReadOnly); | ||
339 | |||
340 | QString engine = RbSettings::value(RbSettings::Tts).toString(); | ||
341 | TTSBase* tts = TTSBase::getTTS(this,RbSettings::value(RbSettings::Tts).toString()); | ||
342 | QString vendor = tts->voiceVendor(); | ||
343 | delete tts; | ||
344 | |||
345 | if(m_lang.isEmpty()) | ||
346 | m_lang = "english"; | ||
347 | qDebug() << "[TalkGenerator] building string corrections list for" | ||
348 | << m_lang << engine << vendor; | ||
349 | QTextStream stream(&correctionsFile); | ||
350 | while(!stream.atEnd()) { | ||
351 | QString line = stream.readLine(); | ||
352 | if(line.startsWith(" ") || line.length() < 10) | ||
353 | continue; | ||
354 | // separator is first character | ||
355 | QString separator = line.at(0); | ||
356 | line.remove(0, 1); | ||
357 | QStringList items = line.split(separator); | ||
358 | // we need to have at least 6 separate entries. | ||
359 | if(items.size() < 6) | ||
360 | continue; | ||
361 | |||
362 | QRegExp re_lang(items.at(0)); | ||
363 | QRegExp re_engine(items.at(1)); | ||
364 | QRegExp re_vendor(items.at(2)); | ||
365 | if(!re_lang.exactMatch(m_lang)) { | ||
366 | continue; | ||
367 | } | ||
368 | if(!re_vendor.exactMatch(vendor)) { | ||
369 | continue; | ||
370 | } | ||
371 | if(!re_engine.exactMatch(engine)) { | ||
372 | continue; | ||
373 | } | ||
374 | struct CorrectionItems co; | ||
375 | co.search = items.at(3); | ||
376 | co.replace = items.at(4); | ||
377 | // Qt uses backslash for back references, Perl uses dollar sign. | ||
378 | co.replace.replace(QRegExp("\\$(\\d+)"), "\\\\1"); | ||
379 | co.modifier = items.at(5); | ||
380 | m_corrections.append(co); | ||
381 | } | ||
382 | correctionsFile.close(); | ||
383 | } | ||