From 077f44ca410c67beae059ae31fcb4babaf66b42b Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 8 May 2025 17:12:12 -0400 Subject: [PATCH] rbutil: Pull voice-corrections.txt out of voicestrings.zip If the corrections file is not present on the target, then fall back to the (probably outdated) compile-time builtin version. Change-Id: I9904b81b2f3737149fc8a905ecd03ff54782bbdf --- utils/rbutilqt/base/talkgenerator.cpp | 9 ++---- utils/rbutilqt/base/talkgenerator.h | 3 +- utils/rbutilqt/base/voicefile.cpp | 33 ++++++++++++++++++---- utils/rbutilqt/base/voicefile.h | 2 +- utils/rbutilqt/changelog.txt | 2 ++ utils/rbutilqt/test/test-talkgenerator.cpp | 8 ++++-- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/utils/rbutilqt/base/talkgenerator.cpp b/utils/rbutilqt/base/talkgenerator.cpp index 8bbc7702e0..d14fe36a7e 100644 --- a/utils/rbutilqt/base/talkgenerator.cpp +++ b/utils/rbutilqt/base/talkgenerator.cpp @@ -277,14 +277,12 @@ QString TalkGenerator::correctString(const QString& s) return corrected; } -void TalkGenerator::setLang(const QString& name) +void TalkGenerator::setLang(const QString& name, QFile *correctionsFile) { m_lang = name; // re-initialize corrections list - m_corrections.clear(); - QFile correctionsFile(":/builtin/voice-corrections.txt"); - correctionsFile.open(QIODevice::ReadOnly); + correctionsFile->seek(0); QString engine = RbSettings::value(RbSettings::Tts).toString(); TTSBase* tts = TTSBase::getTTS(this, RbSettings::value(RbSettings::Tts).toString()); @@ -300,7 +298,7 @@ void TalkGenerator::setLang(const QString& name) m_lang = "english"; LOG_INFO() << "building string corrections list for" << m_lang << engine << vendor; - QTextStream stream(&correctionsFile); + QTextStream stream(correctionsFile); while(!stream.atEnd()) { QString line = stream.readLine(); if(line.startsWith(" ") || line.length() < 10) @@ -333,5 +331,4 @@ void TalkGenerator::setLang(const QString& name) co.modifier = items.at(5); m_corrections.append(co); } - correctionsFile.close(); } diff --git a/utils/rbutilqt/base/talkgenerator.h b/utils/rbutilqt/base/talkgenerator.h index 7e25f8ce5e..6bdb22745e 100644 --- a/utils/rbutilqt/base/talkgenerator.h +++ b/utils/rbutilqt/base/talkgenerator.h @@ -57,7 +57,7 @@ public: public slots: void abort(); - void setLang(const QString& name); + void setLang(const QString& name, QFile *correctionsFile); signals: void done(bool); @@ -88,4 +88,3 @@ private: #endif - diff --git a/utils/rbutilqt/base/voicefile.cpp b/utils/rbutilqt/base/voicefile.cpp index 267af18010..e5b7a1df1f 100644 --- a/utils/rbutilqt/base/voicefile.cpp +++ b/utils/rbutilqt/base/voicefile.cpp @@ -72,21 +72,40 @@ bool VoiceFileCreator::createVoiceFile() ZipUtil z(this); if(z.open(fn)) { QStringList contents = z.files(); - int index; - for(index = 0; index < contents.size(); ++index) { + int vindex = -1, cindex = -1; + for(int index = 0; index < contents.size(); ++index) { // strip any path, we don't know the structure in the zip - if(QFileInfo(contents.at(index)).baseName() == m_lang) { + if(QFileInfo(contents.at(index)).baseName() == m_lang) + vindex = index; + if(QFileInfo(contents.at(index)).baseName() == "voice-corrections") + cindex = index; + if (vindex != -1 && cindex != -1) break; + } + if(cindex != -1) { + LOG_INFO() << "extracting voice corrections file"; + QTemporaryFile corrfileT; + corrfileT.open(); + QString cfn = corrfileT.fileName(); + if(z.extractArchive(cfn, QFileInfo(contents.at(cindex)).fileName())) { + emit logItem(tr("Extracted voice corrections file from installation"), LOGINFO); + corrFile = &corrfileT; + } else { + corrfileT.close(); + emit logItem(tr("Using internal voice corrections file"), LOGINFO); + QFile corrfile(":/builtin/voice-corrections.txt"); + corrfile.open(QIODevice::ReadOnly); + corrFile = &corrfile; } } - if(index < contents.size()) { + if(vindex != -1) { LOG_INFO() << "extracting strings file from zip"; // extract strings QTemporaryFile stringsfile; stringsfile.open(); QString sfn = stringsfile.fileName(); // ZipUtil::extractArchive() only compares the filename. - if(z.extractArchive(sfn, QFileInfo(contents.at(index)).fileName())) { + if(z.extractArchive(sfn, QFileInfo(contents.at(vindex)).fileName())) { emit logItem(tr("Extracted voice strings from installation"), LOGINFO); stringsfile.seek(0); @@ -135,6 +154,8 @@ bool VoiceFileCreator::createVoiceFile() // everything successful, now create the actual voice file. create(); + if (corrFile->isOpen()) + corrFile->close(); return true; } @@ -282,7 +303,7 @@ void VoiceFileCreator::create(void) TalkGenerator generator(this); // set language for string correction. If not set no correction will be made. if(useCorrection) - generator.setLang(m_lang); + generator.setLang(m_lang, corrFile); connect(&generator, &TalkGenerator::done, this, &VoiceFileCreator::done); connect(&generator, &TalkGenerator::logItem, this, &VoiceFileCreator::logItem); connect(&generator, &TalkGenerator::logProgress, this, &VoiceFileCreator::logProgress); diff --git a/utils/rbutilqt/base/voicefile.h b/utils/rbutilqt/base/voicefile.h index feb0ac6e5a..2c63ae4c80 100644 --- a/utils/rbutilqt/base/voicefile.h +++ b/utils/rbutilqt/base/voicefile.h @@ -68,10 +68,10 @@ private: QString m_versionstring; // version string to be used for logging int m_wavtrimThreshold; int m_voiceformat; + QFile *corrFile; // the voice-corrections file bool m_abort; QList m_talkList; }; #endif - diff --git a/utils/rbutilqt/changelog.txt b/utils/rbutilqt/changelog.txt index e08cc48c7f..7da7330830 100644 --- a/utils/rbutilqt/changelog.txt +++ b/utils/rbutilqt/changelog.txt @@ -51,3 +51,5 @@ Version 1.5.1 Version 1.5.2 * Add support for Native Port to AIGO Eros Q and various clones * Make Hosted Port to AIGO Eros Q and various clones "disabled" (can be reenabled by checking the "show disabled targets" checkbox) +* When installing development builds, fall back to daily artefacts for non-firmware files +* Where possible, extract voice corrections file from the actual device diff --git a/utils/rbutilqt/test/test-talkgenerator.cpp b/utils/rbutilqt/test/test-talkgenerator.cpp index 82649471da..e3969a1d71 100644 --- a/utils/rbutilqt/test/test-talkgenerator.cpp +++ b/utils/rbutilqt/test/test-talkgenerator.cpp @@ -68,10 +68,15 @@ void TestTalkGenerator::testCorrectString() QFETCH(QString, from); QFETCH(QString, to); + QFile corrfile(":/builtin/voice-corrections.txt"); + corrfile.open(QIODevice::ReadOnly); + TalkGenerator t(this); - t.setLang(language); + t.setLang(language, &corrfile); + QString corrected = t.correctString(from); QCOMPARE(corrected, to); + corrfile.close(); } @@ -80,4 +85,3 @@ QTEST_MAIN(TestTalkGenerator) // this include is needed because we don't use a separate header file for the // test class. It also needs to be at the end. #include "test-talkgenerator.moc" -