rbutilqt: QtTTS: Pick a sane TTS engine/backend by default

* Ignore 'mock' tts engine
 * Must support synthesizing to a file (ie not just "speaking")
 * Don't claim 'speak' capabilities if the chosen engine does not

Change-Id: Id5fd224466ed62df5af837256fa66a340672d167
This commit is contained in:
Solomon Peachy 2026-07-09 20:36:16 -04:00
parent 8157759b7e
commit 931fbb6734
2 changed files with 22 additions and 8 deletions

View file

@ -74,8 +74,7 @@ TTSStatus TTSQt::voice(const QString& text, const QString& wavfile, QString* err
if (wavfile.isEmpty()) {
m_tts->say(text);
}
else {
} else {
m_audioData.clear();
m_format = QAudioFormat();
@ -128,14 +127,23 @@ bool TTSQt::start(QString *errStr)
return false;
}
// XXX figure out the "best" engine. Ignore 'mock' and
// any anything that doesn't support file output!
/* Build list of engines that support synthesis (ie not just "speaking") */
for (const QString &str : m_tts->availableEngines()) {
if (str == "mock")
continue;
m_tts->setEngine(str);
if (m_tts->engineCapabilities() & QTextToSpeech::Capability::Synthesize)
m_engines << str;
}
if (!(m_tts->engineCapabilities() & QTextToSpeech::Capability::Synthesize)) {
LOG_ERROR() << "QT TTS engine '" << m_tts->engine() << " does not support synthesis to file";
if (m_engines.isEmpty()) {
if (errStr) *errStr = "No TTS suitable engines available on this system";
return false;
}
/* Default to first suitable engine */
m_tts->setEngine(m_engines.at(0));
LOG_INFO() << "QT TTS engine: " << m_tts->engine();
return true;
@ -161,7 +169,7 @@ bool TTSQt::configOk()
void TTSQt::generateSettings()
{
// TODO
// TODO -- enumerate engines (m_engines), locale, and voice lists.
}
void TTSQt::saveSettings()
@ -171,7 +179,12 @@ void TTSQt::saveSettings()
TTSBase::Capabilities TTSQt::capabilities()
{
return TTSBase::CanSpeak | TTSBase::RunInParallel;
TTSBase::Capabilities caps = TTSBase::RunInParallel;
if (m_tts->engineCapabilities() & QTextToSpeech::Capability::Speak)
caps |= TTSBase::CanSpeak;
return caps;
}
bool TTSQt::writeWavFile(const QString &filePath, const QByteArray &audioData, const QAudioFormat &format)

View file

@ -46,6 +46,7 @@ private:
QTextToSpeech *m_tts = nullptr;
QByteArray m_audioData;
QAudioFormat m_format;
QStringList m_engines;
// Helper to write raw PCM data to a WAV file
bool writeWavFile(const QString &filePath, const QByteArray &audioData, const QAudioFormat &format);