1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Solomon Peachy 2025-05-08 17:12:12 -04:00
parent bb20b5c6bf
commit 077f44ca41
6 changed files with 40 additions and 17 deletions

View file

@ -277,14 +277,12 @@ QString TalkGenerator::correctString(const QString& s)
return corrected; return corrected;
} }
void TalkGenerator::setLang(const QString& name) void TalkGenerator::setLang(const QString& name, QFile *correctionsFile)
{ {
m_lang = name; m_lang = name;
// re-initialize corrections list // re-initialize corrections list
m_corrections.clear(); correctionsFile->seek(0);
QFile correctionsFile(":/builtin/voice-corrections.txt");
correctionsFile.open(QIODevice::ReadOnly);
QString engine = RbSettings::value(RbSettings::Tts).toString(); QString engine = RbSettings::value(RbSettings::Tts).toString();
TTSBase* tts = TTSBase::getTTS(this, 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"; m_lang = "english";
LOG_INFO() << "building string corrections list for" LOG_INFO() << "building string corrections list for"
<< m_lang << engine << vendor; << m_lang << engine << vendor;
QTextStream stream(&correctionsFile); QTextStream stream(correctionsFile);
while(!stream.atEnd()) { while(!stream.atEnd()) {
QString line = stream.readLine(); QString line = stream.readLine();
if(line.startsWith(" ") || line.length() < 10) if(line.startsWith(" ") || line.length() < 10)
@ -333,5 +331,4 @@ void TalkGenerator::setLang(const QString& name)
co.modifier = items.at(5); co.modifier = items.at(5);
m_corrections.append(co); m_corrections.append(co);
} }
correctionsFile.close();
} }

View file

@ -57,7 +57,7 @@ public:
public slots: public slots:
void abort(); void abort();
void setLang(const QString& name); void setLang(const QString& name, QFile *correctionsFile);
signals: signals:
void done(bool); void done(bool);
@ -88,4 +88,3 @@ private:
#endif #endif

View file

@ -72,21 +72,40 @@ bool VoiceFileCreator::createVoiceFile()
ZipUtil z(this); ZipUtil z(this);
if(z.open(fn)) { if(z.open(fn)) {
QStringList contents = z.files(); QStringList contents = z.files();
int index; int vindex = -1, cindex = -1;
for(index = 0; index < contents.size(); ++index) { for(int index = 0; index < contents.size(); ++index) {
// strip any path, we don't know the structure in the zip // 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; 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"; LOG_INFO() << "extracting strings file from zip";
// extract strings // extract strings
QTemporaryFile stringsfile; QTemporaryFile stringsfile;
stringsfile.open(); stringsfile.open();
QString sfn = stringsfile.fileName(); QString sfn = stringsfile.fileName();
// ZipUtil::extractArchive() only compares the 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); emit logItem(tr("Extracted voice strings from installation"), LOGINFO);
stringsfile.seek(0); stringsfile.seek(0);
@ -135,6 +154,8 @@ bool VoiceFileCreator::createVoiceFile()
// everything successful, now create the actual voice file. // everything successful, now create the actual voice file.
create(); create();
if (corrFile->isOpen())
corrFile->close();
return true; return true;
} }
@ -282,7 +303,7 @@ void VoiceFileCreator::create(void)
TalkGenerator generator(this); TalkGenerator generator(this);
// set language for string correction. If not set no correction will be made. // set language for string correction. If not set no correction will be made.
if(useCorrection) if(useCorrection)
generator.setLang(m_lang); generator.setLang(m_lang, corrFile);
connect(&generator, &TalkGenerator::done, this, &VoiceFileCreator::done); connect(&generator, &TalkGenerator::done, this, &VoiceFileCreator::done);
connect(&generator, &TalkGenerator::logItem, this, &VoiceFileCreator::logItem); connect(&generator, &TalkGenerator::logItem, this, &VoiceFileCreator::logItem);
connect(&generator, &TalkGenerator::logProgress, this, &VoiceFileCreator::logProgress); connect(&generator, &TalkGenerator::logProgress, this, &VoiceFileCreator::logProgress);

View file

@ -68,10 +68,10 @@ private:
QString m_versionstring; // version string to be used for logging QString m_versionstring; // version string to be used for logging
int m_wavtrimThreshold; int m_wavtrimThreshold;
int m_voiceformat; int m_voiceformat;
QFile *corrFile; // the voice-corrections file
bool m_abort; bool m_abort;
QList<TalkGenerator::TalkEntry> m_talkList; QList<TalkGenerator::TalkEntry> m_talkList;
}; };
#endif #endif

View file

@ -51,3 +51,5 @@ Version 1.5.1
Version 1.5.2 Version 1.5.2
* Add support for Native Port to AIGO Eros Q and various clones * 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) * 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

View file

@ -68,10 +68,15 @@ void TestTalkGenerator::testCorrectString()
QFETCH(QString, from); QFETCH(QString, from);
QFETCH(QString, to); QFETCH(QString, to);
QFile corrfile(":/builtin/voice-corrections.txt");
corrfile.open(QIODevice::ReadOnly);
TalkGenerator t(this); TalkGenerator t(this);
t.setLang(language); t.setLang(language, &corrfile);
QString corrected = t.correctString(from); QString corrected = t.correctString(from);
QCOMPARE(corrected, to); 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 // 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. // test class. It also needs to be at the end.
#include "test-talkgenerator.moc" #include "test-talkgenerator.moc"