Problem sending text strings to process with QProcess::write
-
I am trying to use text-to-speech via an independent process. This should allow TTS to proceed without blocking the message queue of my main process. I have a very simple console program which speaks any line of text typed on the keyboard. I want to use QProcess to start this console process and send text to its stdin.
QProcess successfully starts the process (it appears in Task Manager). It also reports the correct number of bytes sent in calls to QProcess::write. However no speech is generated.
The console program works correctly when operated from the keyboard.
I am using QT 5.2.0 and Lubuntu 13.04.
I would appreciate any ideas on what is wong here. I have given all the relevant code below.
@#include <QProcess>
class Voice {
public:QProcess *speechServer;
Voice() {
run();
}void run() {
string speechServerName = SessionDirectory() + "ConsoleTTS";speechServer = new QProcess(); speechServer->start(speechServerName.c_str(), QProcess::Unbuffered | QProcess::ReadWrite); if (!speechServer->waitForStarted()) { Print("Speech server not started"); }
}
void say(const string &text) {
int err1 = speechServer->write(text.c_str());
if (err1==-1) {
Print("QProcess::write failed");
}int err2 = speechServer->write("\n"); if (err2==-1) { Print("QProcess::write failed"); }
}
};
@The console program is:
@#include <QCoreApplication>
#include <QTextStream>
#include <flite.h>extern "C" cst_voice register_cmu_us_kal(const char);
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);QTextStream cin(stdin);
QTextStream cout(stdout);cst_voice *v;
flite_init();
v = register_cmu_us_kal(NULL);do {
QString text = cin.readLine();
cout << text << "\n";
cout.flush();
flite_text_to_speech(text.toStdString().c_str(), v, "play");
} while(true);return a.exec();
}@ -
Isn't this a duplicate of "this one":https://qt-project.org/forums/viewthread/53039/ ?
-
It's the same problem, but I stripped down the voice class so that I could post it in its entirety, giving the full context. I did it on a new thread because the original seemed to have died.The old version actually had problems due to multi-threading. This version does not use multi-threading at all. Consequently the QProcess::write calls appear to work (they return the correct number of bytes sent). However the console program fails to speak, whereas it does work when run from a command prompt and sent text throught the keyboard. My conclusion is that the message is not being received in stdin.
Buffering problem or do I need to force flush ?