From 560f679f7a2eb87055d287cd554f62329c5ca082 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Tue, 9 Dec 2014 11:31:20 -0800 Subject: [PATCH] Move init to correct thread --- src/GAudioOutput.cc | 2 -- src/audio/QGCAudioWorker.cpp | 12 ++++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/GAudioOutput.cc b/src/GAudioOutput.cc index dc847cee7..4109efdad 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 e0a202f37..0db57378b 100644 --- a/src/audio/QGCAudioWorker.cpp +++ b/src/audio/QGCAudioWorker.cpp @@ -94,6 +94,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 @@ -109,8 +115,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; -- 2.22.0