Unsolved program doesn't react anymore by checking word longer than 6 chars
-
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]
-
@tobstar008
Seems to be a question about yoursf::Sound
, nothing to do with Qt. -
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 bysleep
ing and fourthly if I understand correctly whatsnd.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.
- Do you know what reentrancy and thread-safety is, and what is the difference?
-
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.
-
@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.
-
@kshegunov ok thanks then I hope that any other can help.
-
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 ?
-
@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? -
....It seems as the infinite loop is the graphem loop...
-
@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.