Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Q: Qt - [c++] Qt6 TextToSpeech does not use Localization
QtWS25 Last Chance

Q: Qt - [c++] Qt6 TextToSpeech does not use Localization

Scheduled Pinned Locked Moved Solved Game Development
9 Posts 2 Posters 331 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kevin_d
    wrote on 18 Feb 2025, 16:39 last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kevin_d
      wrote on 18 Feb 2025, 16:51 last edited by
      #2

      The speech output seems to have german phonetics (My Windows is a german installation).

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 18 Feb 2025, 19:34 last edited by
        #3

        Hi,

        Which version of Qt 6 are you using ?
        On which version of Windows ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kevin_d
          wrote on 20 Feb 2025, 16:36 last edited by
          #4

          Qt 6.8.2 on Windows 11 Home 24H2.
          regards, kevin

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kevin_d
            wrote on 28 Feb 2025, 12:30 last edited by
            #5

            Solution is still pending... Does anyone know about this?
            cheers, kevin_d

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 28 Feb 2025, 13:37 last edited by
              #6

              Might be silly but since you are randomizing the voice, did you stumble upon something that was maybe broken on your system ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • K Offline
                K Offline
                kevin_d
                wrote on 28 Feb 2025, 19:54 last edited by kevin_d
                #7

                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

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 28 Feb 2025, 20:05 last edited by
                  #8

                  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.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kevin_d
                    wrote on 28 Feb 2025, 20:58 last edited by kevin_d
                    #9

                    It appears as if I have mutliple engines installed on my setup.
                    So, instead of

                    auto *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

                    1 Reply Last reply
                    2
                    • K kevin_d has marked this topic as solved on 28 Feb 2025, 21:02

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved