Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Trouble with QtSpeech (again)
Qt 6.11 is out! See what's new in the release blog

Trouble with QtSpeech (again)

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 940 Views 1 Watching
  • 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.
  • quentinthorntonQ Offline
    quentinthorntonQ Offline
    quentinthornton
    wrote on last edited by
    #1

    Hey guys, I recently installed qtspeech (thanks to sgaist), and now I'm having problems again. I start by making a qt widgets application with all the defaults selected, and when I put these simple lines:

     QTextToSpeech voice;
     voice.say("Hello World");
    

    in the constructor for mainwindow.cpp it didn't work. But when I put it in the main.cpp, it worked. I looked in the hello test and all it did, to say something, was this:

    QTextToSpeech * voice;//it even has this code in the mainwindow.cpp, and it doesn't have a problem working.
    voice->say("Hello World");
    

    So I also tried that too, but it didn't work at all, even in the main.cpp. When I try to put that code in the mainwindow.cpp, it comes up with a window saying QtSpeechTest.exe stopped working. Am I doing anything wrong? If so, how could I fix it? Thanks.

    P.S. I've also tried making a speak function that looks like this:

    void MainWindow::saySomething(QString stringToSay){
          QTextToSpeech voice;
          voice.say(stringToSay);
    }
    

    and I made a button that was suppose to call that function and say, "hello world" when I released the button, but that didn't work either.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      QTextToSpeech * voice; //<< That's just declaring a pointer
      voice->say("Hello World");
      

      You are not allocating any object of type QTextToSpeech hence the crash.

      void MainWindow::saySomething(QString stringToSay){
            QTextToSpeech voice;
            voice.say(stringToSay);  // << say isn't necessarily synchronous
      }
      

      In this case, voice will get destroyed at the end of the function which might happen before the TTS engine got a change to run hence the silence.

      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
      • quentinthorntonQ Offline
        quentinthorntonQ Offline
        quentinthornton
        wrote on last edited by
        #3

        Thanks! I changed it like so and now it works!:

            QTextToSpeech * tts = new QTextToSpeech(this);
            tts->say("hello world");
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          If you do that in saySomething then you have a memory leak.

          Make tts a member of your class and be done with it.

          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

          • Login

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