void QGCAudioWorker::say(QString inText, int severity)
{
	static bool threadInit = false;
	if (!threadInit) {
		threadInit = true;
		init();
	}

    if (!muted)
    {
        QString text = _fixTextMessageForAudio(inText);
        // Prepend high priority text with alert beep
        if (severity < GAudioOutput::AUDIO_SEVERITY_CRITICAL) {
            beep();
        }

#ifdef QGC_NOTIFY_TUNES_ENABLED
        // Wait for the last sound to finish
        while (!sound->isFinished()) {
            QGC::SLEEP::msleep(100);
        }
#endif

#if defined _MSC_VER && defined QGC_SPEECH_ENABLED
        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;
        espeak_Synth(text.toStdString().c_str(), espeak_size, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL);

#elif defined Q_OS_MAC && defined QGC_SPEECH_ENABLED
        // Slashes necessary to have the right start to the sentence
        // copying data prevents SpeakString from reading additional chars
        text = "\\" + text;
        std::wstring str = text.toStdWString();
        unsigned char str2[1024] = {};
        memcpy(str2, text.toLatin1().data(), str.length());
        SpeakString(str2);

        // Block the thread while busy
        // because we run in our own thread, this doesn't
        // halt the main application
        while (SpeechBusy()) {
            QGC::SLEEP::msleep(100);
        }

#else
        // Make sure there isn't an unused variable warning when speech output is disabled
        Q_UNUSED(inText);
#endif
    }
}
void MiaWrong()
{
    int n;
    string wrong;
    string text;

    n = Random(NUM_WRONGS) + 1;
    wrong = MIA_WRONG_TAG + IntToString(n);
    text = GetWrong(n);

    SoundObjectPlay(GetObjectByTag(wrong));
    AssignCommand(pc, SpeakString(text, TALKVOLUME_TALK));
}
void TauntMia()
{
    int n;
    string taunt;
    string text;

    n = Random(NUM_ATTACKS) + 1;
    taunt = SHADOW_ATTACK_TAG + IntToString(n);
    text = GetAttack(n);

    SoundObjectPlay(GetObjectByTag(taunt));
    SpeakString(text, TALKVOLUME_SHOUT);
    AssignCommand(OBJECT_SELF, PlayAnimation(ANIMATION_FIREFORGET_TAUNT));
}