Q: Qt - [c++] Qt6 TextToSpeech does not use Localization
-
wrote on 18 Feb 2025, 16:39 last edited by
Hello everyone!
Ich ported my project to Qt6. In the Windows build, everything works fine, except that the TextToSpeech engine does not speak English anymore (which worked in Qt 5.15.2).
I used the following function. Explanation: I try to switch randomly between different voices. (In Windows i usually have only one voice).What's wrong?
void SpeechClass::say(QString text, bool ) { if (text2Speech == nullptr) { QLocale::setDefault(QLocale(QLocale::English, QLocale::LatinScript, QLocale::UnitedStates)); text2Speech = new QTextToSpeech(this); text2Speech->setVolume(0.88); text2Speech->setLocale(QLocale(QLocale::English, QLocale::LatinScript, QLocale::UnitedStates)); QVector<QLocale> _l = text2Speech->availableLocales(); int num_locales = _l.size(); for (int loc = 0; loc < num_locales; loc++) { if (_l.at(loc).language() == QLocale::English) { text2Speech->setLocale(_l.at(loc)); QVector<QVoice> _v = text2Speech->availableVoices(); int num_voices = _v.size(); int __v = rand() % num_voices; text2Speech->setVoice(_v.at(__v)); break; } } } text2Speech->setLocale(QLocale(QLocale::English, QLocale::LatinScript, QLocale::UnitedStates)); text2Speech->say(text); }
best regards, kevin_d
-
wrote on 18 Feb 2025, 16:51 last edited by
The speech output seems to have german phonetics (My Windows is a german installation).
-
Hi,
Which version of Qt 6 are you using ?
On which version of Windows ? -
wrote on 20 Feb 2025, 16:36 last edited by
Qt 6.8.2 on Windows 11 Home 24H2.
regards, kevin -
wrote on 28 Feb 2025, 12:30 last edited by
Solution is still pending... Does anyone know about this?
cheers, kevin_d -
Might be silly but since you are randomizing the voice, did you stumble upon something that was maybe broken on your system ?
-
wrote on 28 Feb 2025, 19:54 last edited by kevin_d
No, I don't think so.
Sorry for the late update: With Qt6.8.2 i only have two locales available, which are both QLocale::German.
With Qt5 I had at least one QLocale::English.
Can I fix this? Maybe add an additional library to include an english Locale?best regards, kevin_d
Reference: https://forum.qt.io/topic/80840/qtexttospeech-locales
-
Do you still have Qt 5 on that machine ?
If so I would check Qt's sources to see what has changed between the two in the Windows backend. -
wrote on 28 Feb 2025, 20:58 last edited by kevin_d
It appears as if I have mutliple engines installed on my setup.
So, instead ofauto *text2speech = new QTextToSpeech(this);
i changed my code accordingly:
for (auto const& v : QTextToSpeech::availableEngines()) { qDebug() << "available engine: " << v.toStdString(); auto *text2Speech = new QTextToSpeech(v); // find suitable locales }
So I am not randomizing voices anymore. I take the first best english voice.
It works. Now testing on Linux :-)
best regards, kevin_d
-