diff --git a/src/GAudioOutput.cc b/src/GAudioOutput.cc index ca2a4aa952a3ca6b1c29084af442b7ca5aeb1def..e0134a5c800ac85a5879dd9f42fbce85aa1e9be6 100644 --- a/src/GAudioOutput.cc +++ b/src/GAudioOutput.cc @@ -64,8 +64,6 @@ GAudioOutput::GAudioOutput(QObject *parent) : QObject(parent), worker(new QGCAudioWorker()) { worker->moveToThread(thread); - // Initialize within right thread context - worker->init(); connect(this, SIGNAL(textToSpeak(QString,int)), worker, SLOT(say(QString,int))); connect(this, SIGNAL(beepOnce()), worker, SLOT(beep())); thread->start(); diff --git a/src/audio/QGCAudioWorker.cpp b/src/audio/QGCAudioWorker.cpp index 5c4c4579848c283da2e33f60b8ee55d077f3509f..0d2ee3e6b0304023232eaf3039a36efb9b6dfe95 100644 --- a/src/audio/QGCAudioWorker.cpp +++ b/src/audio/QGCAudioWorker.cpp @@ -95,6 +95,12 @@ QGCAudioWorker::~QGCAudioWorker() void QGCAudioWorker::say(QString text, int severity) { + static bool threadInit = false; + if (!threadInit) { + threadInit = true; + init(); + } + if (!muted) { // Prepend high priority text with alert beep @@ -110,8 +116,10 @@ void QGCAudioWorker::say(QString text, int severity) #endif #if defined _MSC_VER && defined QGC_SPEECH_ENABLED - pVoice->Speak(text.toStdWString().c_str(), SPF_DEFAULT, NULL); - + HRESULT hr = pVoice->Speak(text.toStdWString().c_str(), SPF_DEFAULT, NULL); + if (FAILED(hr)) { + qDebug() << "Speak failed, HR:" << QString("%1").arg(hr, 0, 16); + } #elif defined Q_OS_LINUX && defined QGC_SPEECH_ENABLED // Set size of string for espeak: +1 for the null-character unsigned int espeak_size = strlen(text.toStdString().c_str()) + 1;