diff --git a/src/audio/QGCAudioWorker.cpp b/src/audio/QGCAudioWorker.cpp index 5e79774f6e2b6d8117ee7b4c5485e9338495f10e..8a19f0db537dbf599034b91e2117cca45983b070 100644 --- a/src/audio/QGCAudioWorker.cpp +++ b/src/audio/QGCAudioWorker.cpp @@ -10,47 +10,27 @@ #if (defined __macos__) && defined QGC_SPEECH_ENABLED #include +#include -static SpeechChannel sc; -static Fixed volume; +void macSpeak(const char* words) +{ + static SpeechChannel sc = NULL; -static void speechDone(SpeechChannel sc2, void *) { - if (sc2 == sc) - { - DisposeSpeechChannel(sc); + while (SpeechBusy()) { + QGC::SLEEP::msleep(100); } -} + if (sc == NULL) { + Float32 volume = 1.0; -class MacSpeech -{ -public: - MacSpeech() - { - setVolume(100); - } - ~MacSpeech() - { - } - void say(const char* words) - { - while (SpeechBusy()) { - QGC::SLEEP::msleep(100); - } NewSpeechChannel(NULL, &sc); - SetSpeechInfo(sc, soVolume, &volume); - SetSpeechInfo(sc, soSpeechDoneCallBack, reinterpret_cast(speechDone)); - CFStringRef cfstr = CFStringCreateWithCString(NULL, words, kCFStringEncodingUTF8); - SpeakCFString(sc, cfstr, NULL); - } - void setVolume(int v) - { - volume = FixRatio(v, 100); + CFNumberRef volumeRef = CFNumberCreate(NULL, kCFNumberFloat32Type, &volume); + SetSpeechProperty(sc, kSpeechVolumeProperty, volumeRef); + CFRelease(volumeRef); } -}; - -//-- Singleton -MacSpeech macSpeech; - + CFStringRef strRef = CFStringCreateWithCString(NULL, words, kCFStringEncodingUTF8); + SpeakCFString(sc, strRef, NULL); + CFRelease(strRef); +} #endif #if (defined __ios__) && defined QGC_SPEECH_ENABLED @@ -154,7 +134,7 @@ void QGCAudioWorker::say(QString inText) espeak_Synth(text.toStdString().c_str(), espeak_size, 0, POS_CHARACTER, 0, espeakCHARS_AUTO, NULL, NULL); espeak_Synchronize(); #elif (defined __macos__) && defined QGC_SPEECH_ENABLED - macSpeech.say(text.toStdString().c_str()); + macSpeak(text.toStdString().c_str()); #elif (defined __ios__) && defined QGC_SPEECH_ENABLED iOSSpeak(text); #else @@ -172,7 +152,7 @@ void QGCAudioWorker::mute(bool mute) this->muted = mute; QSettings settings; settings.setValue(QGC_GAUDIOOUTPUT_KEY + "muted", this->muted); -// emit mutedChanged(muted); + // emit mutedChanged(muted); } }