Q: Qt - [c++] Qt6 TextToSpeech does not use Localization
-
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
-
Hi,
Which version of Qt 6 are you using ?
On which version of Windows ? -
Might be silly but since you are randomizing the voice, did you stumble upon something that was maybe broken on your system ?
-
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. -
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
-