Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. program doesn't react anymore by checking word longer than 6 chars

program doesn't react anymore by checking word longer than 6 chars

Scheduled Pinned Locked Moved Unsolved C++ Gurus
10 Posts 4 Posters 896 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.
  • T Offline
    T Offline
    tobstar008
    wrote on last edited by kshegunov
    #1

    hello I'm working on a TTS synthesizer and it reads words lower than 6 chars. But if I write words longer than 6 chars, the program won't react anymore. If I use steps in the debugging mode, qtcreator won't show me any problems, and the program won't react anymore too. I don't know how to solve. Should I try to use QThreads?
    Here is my say methode:

    void Link2TTS::say(QString txt)
    {
        struct Tones
        {
            sf::SoundBuffer sb;
            int d /*, overload*/;
        };
    
    
        QStringList words = txt.split(" ");
        sf::Sound snd;
    
        Q_FOREACH(QString word, words)
        {
            QVector<Tones> tones;
            word=QString(word).toUpper();
            if(Lexicon)
            {
                if(Lexicon->exist(word))
                {
                    words.replaceInStrings(word, Lexicon->getPronunciation(word));
                    word = Lexicon->getPronunciation(word);
                }
            }
            for(int i = 0; i < word.size(); i++)
            {
    
                for(int k = word.size(); k > 0; k--)
                {
                    if(Language->isGraphem(word.mid(i, k)))
                    {
                        Tones t;
                        t.sb = *Voice->getSound(Language->getGraphem(word.mid(i, k)));
                        t.d = t.sb.getDuration().asMilliseconds();
                        /*if(Language->getLength(Language->getGraphem(word.mid(i, k))) == 0)
                            t.overload = delay*100;
                        else
                            t.overload = Language->getLength(Language->getGraphem(word.mid(i, k)))*100;*/
                        tones.append(t);
                        if(k <= word.size())
                        {
                            i = k;
    
                        }
    
                        break;
                    }
    
                }
                if(Language->isPhonem(QString(word[i])))
                {
                    Tones t;
                    t.sb = *Voice->getSound(Language->getPhonem(QString(word[i])));
                    t.d = t.sb.getDuration().asMilliseconds();
                    /*if(Language->getLength(Language->getPhonem(QString(word[i]))) == 0)
                        t.overload = delay*100;
                    else*/
                      //  t.overload = Language->getLength(Language->getPhonem(QString(word[i])))*100;
                    tones.append(t);
                }
            }
            for(int i = 0; i < tones.size(); i++)
            {
                snd.setBuffer(tones[i].sb);
                snd.play();
    
                sf::sleep(sf::milliseconds(delay*100-tones[i].d));
            }
    
            tones.clear();
        }
    
    }
    

    I hope you can say me what I could try to solve this problem.

    [Added code tags ~kshegunov]

    JonBJ 1 Reply Last reply
    0
    • T tobstar008

      hello I'm working on a TTS synthesizer and it reads words lower than 6 chars. But if I write words longer than 6 chars, the program won't react anymore. If I use steps in the debugging mode, qtcreator won't show me any problems, and the program won't react anymore too. I don't know how to solve. Should I try to use QThreads?
      Here is my say methode:

      void Link2TTS::say(QString txt)
      {
          struct Tones
          {
              sf::SoundBuffer sb;
              int d /*, overload*/;
          };
      
      
          QStringList words = txt.split(" ");
          sf::Sound snd;
      
          Q_FOREACH(QString word, words)
          {
              QVector<Tones> tones;
              word=QString(word).toUpper();
              if(Lexicon)
              {
                  if(Lexicon->exist(word))
                  {
                      words.replaceInStrings(word, Lexicon->getPronunciation(word));
                      word = Lexicon->getPronunciation(word);
                  }
              }
              for(int i = 0; i < word.size(); i++)
              {
      
                  for(int k = word.size(); k > 0; k--)
                  {
                      if(Language->isGraphem(word.mid(i, k)))
                      {
                          Tones t;
                          t.sb = *Voice->getSound(Language->getGraphem(word.mid(i, k)));
                          t.d = t.sb.getDuration().asMilliseconds();
                          /*if(Language->getLength(Language->getGraphem(word.mid(i, k))) == 0)
                              t.overload = delay*100;
                          else
                              t.overload = Language->getLength(Language->getGraphem(word.mid(i, k)))*100;*/
                          tones.append(t);
                          if(k <= word.size())
                          {
                              i = k;
      
                          }
      
                          break;
                      }
      
                  }
                  if(Language->isPhonem(QString(word[i])))
                  {
                      Tones t;
                      t.sb = *Voice->getSound(Language->getPhonem(QString(word[i])));
                      t.d = t.sb.getDuration().asMilliseconds();
                      /*if(Language->getLength(Language->getPhonem(QString(word[i]))) == 0)
                          t.overload = delay*100;
                      else*/
                        //  t.overload = Language->getLength(Language->getPhonem(QString(word[i])))*100;
                      tones.append(t);
                  }
              }
              for(int i = 0; i < tones.size(); i++)
              {
                  snd.setBuffer(tones[i].sb);
                  snd.play();
      
                  sf::sleep(sf::milliseconds(delay*100-tones[i].d));
              }
      
              tones.clear();
          }
      
      }
      

      I hope you can say me what I could try to solve this problem.

      [Added code tags ~kshegunov]

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @tobstar008
      Seems to be a question about your sf::Sound, nothing to do with Qt.

      1 Reply Last reply
      0
      • kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #3

        First of all we know nothing about what is what here. You work with some structures that we know nothing about. Secondly, there's some side issues, like using Q_FOREACH which is deprecated. Thirdly, you're blocking the event loop by sleeping and fourthly if I understand correctly what snd.play(); is supposed to do you're not giving it any chance to do it by blocking the event loop.

        It raises signals when it starts, and when it finishes playing, so connect to these signals and then play the next thing. Or create a playlist and run it as a whole.

        @tobstar008 said in program doesn't react anymore by checking word longer than 6 chars:

        Should I try to use QThreads?

        This is the checklist for using threads:

        • Do you know what reentrancy and thread-safety is, and what is the difference?
          If you don't, don't use threads.
        • Have you ever used threads before?
          If you haven't, don't use threads.
        • Do you know what's the difference between a blocking and non-blocking (a.k.a. synchronous and asynchronous) operations, what is latency and how they intertwine?
          If you don't, don't use threads.
        • Have you experience with race conditions and how one tests for them and traces such errors in code?
          If you haven't, don't use threads.
        • Can you do without threads?
          If you can, don't use threads.

        Now, you should tell us whether you should use threads, we don't know.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        2
        • T Offline
          T Offline
          tobstar008
          wrote on last edited by tobstar008
          #4

          ok, you're right sorry. Then I try to explain what I'm programming and my structures:
          I'm programming my own tts engine with recordings of human voice. The recordings are in a resource file. And are splitted in phonems (single characters "a", "b", "c"...) and graphems (more charactes together like: "ba", "be" , "ber"...).
          I wrote in the background 2 structures which are mapping phonem or graphem characters to their soundfiles. Because I've to manipulate the gaps between the playlist I choose instead of QSound the sfml package. And use a soundbuffer (sb) where I store the soundfile and the durationtime (d) in my structure . Then I use now foreachloop to check if each word exists in a tts lexicon. If not sort it into graphems or phonems and appends to vector of my structure.
          then made a loop to play each soundbuffer and I've to slow down the loop, otherwise it plays to fast so that there is nothing to hear, or is sounding like a mass.

          On udemy I bought the Qt Advanced course where I learned a little bit about threads but I'm not sure how to apply it to my.

          kshegunovK 1 Reply Last reply
          0
          • T tobstar008

            ok, you're right sorry. Then I try to explain what I'm programming and my structures:
            I'm programming my own tts engine with recordings of human voice. The recordings are in a resource file. And are splitted in phonems (single characters "a", "b", "c"...) and graphems (more charactes together like: "ba", "be" , "ber"...).
            I wrote in the background 2 structures which are mapping phonem or graphem characters to their soundfiles. Because I've to manipulate the gaps between the playlist I choose instead of QSound the sfml package. And use a soundbuffer (sb) where I store the soundfile and the durationtime (d) in my structure . Then I use now foreachloop to check if each word exists in a tts lexicon. If not sort it into graphems or phonems and appends to vector of my structure.
            then made a loop to play each soundbuffer and I've to slow down the loop, otherwise it plays to fast so that there is nothing to hear, or is sounding like a mass.

            On udemy I bought the Qt Advanced course where I learned a little bit about threads but I'm not sure how to apply it to my.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @tobstar008 said in program doesn't react anymore by checking word longer than 6 chars:

            I wrote in the background 2 structures which are mapping phonem or graphem characters to their soundfiles. Because I've to manipulate the gaps between the playlist I choose instead of QSound the sfml package. And use a soundbuffer (sb) where I store the soundfile and the durationtime (d) in my structure . Then I use now foreachloop to check if each word exists in a tts lexicon. If not sort it into graphems or phonems and appends to vector of my structure.

            That sounds fine to me, but I have no experience with that libarary/package whatsoever, so I'm of no use there.

            Read and abide by the Qt Code of Conduct

            T 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @tobstar008 said in program doesn't react anymore by checking word longer than 6 chars:

              I wrote in the background 2 structures which are mapping phonem or graphem characters to their soundfiles. Because I've to manipulate the gaps between the playlist I choose instead of QSound the sfml package. And use a soundbuffer (sb) where I store the soundfile and the durationtime (d) in my structure . Then I use now foreachloop to check if each word exists in a tts lexicon. If not sort it into graphems or phonems and appends to vector of my structure.

              That sounds fine to me, but I have no experience with that libarary/package whatsoever, so I'm of no use there.

              T Offline
              T Offline
              tobstar008
              wrote on last edited by
              #6

              @kshegunov ok thanks then I hope that any other can help.

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

                Hi,

                Did you check whether you are not entering an infinite loop somehow ?

                Or is it freezing at the time of playing because of some wrong values you pass to that library ?

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

                T 1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Did you check whether you are not entering an infinite loop somehow ?

                  Or is it freezing at the time of playing because of some wrong values you pass to that library ?

                  T Offline
                  T Offline
                  tobstar008
                  wrote on last edited by
                  #8

                  @SGaist: thanks it is an infinite loop before the playing loop!!!!!
                  But then I don't understand why shorter words working without problems???? And why more short words working perfectly too?

                  T 1 Reply Last reply
                  0
                  • T tobstar008

                    @SGaist: thanks it is an infinite loop before the playing loop!!!!!
                    But then I don't understand why shorter words working without problems???? And why more short words working perfectly too?

                    T Offline
                    T Offline
                    tobstar008
                    wrote on last edited by
                    #9

                    ....It seems as the infinite loop is the graphem loop...

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

                      @tobstar008 said in program doesn't react anymore by checking word longer than 6 chars:

                      loop...

                      You are modifying i within the loop so you might be in a situation where you change it to a value that does not allow the loop to end.

                      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