From 19be931cfed9fc1c220c459f9f0f7ea2c0c640c9 Mon Sep 17 00:00:00 2001 From: Holden Date: Wed, 17 Apr 2024 17:37:49 -0400 Subject: [PATCH] Audio Output: Fix Mute --- src/Audio/AudioOutput.cc | 43 +++++++++++++++++++++------------------- src/Audio/AudioOutput.h | 4 ++-- src/QGCApplication.cc | 1 + src/Vehicle/Vehicle.cc | 2 +- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/Audio/AudioOutput.cc b/src/Audio/AudioOutput.cc index 21555810b00..759c2152b96 100644 --- a/src/Audio/AudioOutput.cc +++ b/src/Audio/AudioOutput.cc @@ -8,12 +8,13 @@ ****************************************************************************/ #include "AudioOutput.h" +#include "QGCLoggingCategory.h" #include #define MAX_TEXT_QUEUE_SIZE 20U -Q_LOGGING_CATEGORY( AudioOutputLog, "qgc.audio.audiooutput" ); +QGC_LOGGING_CATEGORY( AudioOutputLog, "qgc.audio.audiooutput" ); // qt.speech.tts.flite // qt.speech.tts.android @@ -47,29 +48,26 @@ AudioOutput* AudioOutput::instance() AudioOutput::AudioOutput( QObject* parent ) : QTextToSpeech( QStringLiteral("none"), parent ) { - #ifdef QT_DEBUG - ( void ) connect( this, &QTextToSpeech::stateChanged, []( QTextToSpeech::State state ) { - qCInfo( AudioOutputLog ) << Q_FUNC_INFO << "State:" << state; - }); - ( void ) connect( this, &QTextToSpeech::errorOccurred, []( QTextToSpeech::ErrorReason reason, const QString &errorString ) { - ( void ) reason; - qCInfo( AudioOutputLog ) << Q_FUNC_INFO << "Error:" << errorString; - }); - #endif + ( void ) connect( this, &QTextToSpeech::stateChanged, []( QTextToSpeech::State state ) { + qCDebug( AudioOutputLog ) << Q_FUNC_INFO << "State:" << state; + }); + ( void ) connect( this, &QTextToSpeech::errorOccurred, []( QTextToSpeech::ErrorReason reason, const QString &errorString ) { + qCDebug( AudioOutputLog ) << Q_FUNC_INFO << "Error: (" << reason << ") " << errorString; + }); + ( void ) connect( this, &QTextToSpeech::volumeChanged, []( double volume ) { + qCDebug( AudioOutputLog ) << Q_FUNC_INFO << "volume:" << volume; + }); if ( !QTextToSpeech::availableEngines().isEmpty() ) { if ( setEngine( QString() ) ) { // Autoselect engine by priority + qCDebug( AudioOutputLog ) << Q_FUNC_INFO << "engine:" << engine(); if ( availableLocales().contains( QLocale( "en_US" ) ) ) { setLocale( QLocale( "en_US" ) ); } - ( void ) connect( this, &QTextToSpeech::volumeChanged, [ this ]( double volume ) { - ( void ) volume; - const bool muted = isMuted(); - if ( muted != m_lastMuted ) { - emit mutedChanged( muted ); - m_lastMuted = muted; - } + ( void ) connect( this, &AudioOutput::mutedChanged, [ this ]( bool muted ) { + qCDebug( AudioOutputLog ) << Q_FUNC_INFO << "muted:" << muted; + ( void ) QMetaObject::invokeMethod( this, "setVolume", Qt::AutoConnection, muted ? 0. : 1. ); }); } } @@ -77,18 +75,23 @@ AudioOutput::AudioOutput( QObject* parent ) bool AudioOutput::isMuted() const { - return qFuzzyIsNull( volume() ); + return m_muted; } void AudioOutput::setMuted( bool enable ) { if ( enable != isMuted() ) { - ( void ) QMetaObject::invokeMethod( this, "setVolume", Qt::AutoConnection, enable ? 0. : 100. ); + m_muted = enable; + emit mutedChanged( m_muted ); } } -void AudioOutput::say( const QString& text, AudioOutput::TextMods textMods ) +void AudioOutput::read( const QString& text, AudioOutput::TextMods textMods ) { + if( m_muted ) { + return; + } + if ( !engineCapabilities().testFlag( QTextToSpeech::Capability::Speak ) ) { qCWarning( AudioOutputLog ) << Q_FUNC_INFO << "Speech Not Supported:" << text; return; diff --git a/src/Audio/AudioOutput.h b/src/Audio/AudioOutput.h index 3c967895acc..45b0692116d 100644 --- a/src/Audio/AudioOutput.h +++ b/src/Audio/AudioOutput.h @@ -36,7 +36,7 @@ class AudioOutput : public QTextToSpeech bool isMuted() const; void setMuted( bool enable ); - void say( const QString& text, AudioOutput::TextMods textMods = TextMod::None ); + void read( const QString& text, AudioOutput::TextMods textMods = TextMod::None ); static AudioOutput* instance(); static bool getMillisecondString( const QString& string, QString& match, int& number ); @@ -47,7 +47,7 @@ class AudioOutput : public QTextToSpeech private: qsizetype m_textQueueSize = 0; - bool m_lastMuted = false; + bool m_muted = false; static const QHash s_textHash; }; Q_DECLARE_OPERATORS_FOR_FLAGS( AudioOutput::TextMods ) diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index 9612637e3a2..6938ee36ed1 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -526,6 +526,7 @@ bool QGCApplication::_initForNormalAppBoot() { AudioOutput::instance()->setMuted( value.toBool() ); }); + AudioOutput::instance()->setMuted( toolbox()->settingsManager()->appSettings()->audioMuted()->rawValue().toBool() ); _qmlAppEngine = toolbox()->corePlugin()->createQmlApplicationEngine(this); toolbox()->corePlugin()->createRootWindow(_qmlAppEngine); diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index a626f87e75e..adf4634d0c9 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -2511,7 +2511,7 @@ void Vehicle::virtualTabletJoystickValue(double roll, double pitch, double yaw, void Vehicle::_say(const QString& text) { - AudioOutput::instance()->say(text.toLower()); + AudioOutput::instance()->read(text.toLower()); } bool Vehicle::airship() const