From ab97ce7349c186d3bb8dadaee23c4bd6b7fe8abd Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Thu, 16 Feb 2023 12:40:05 +0000 Subject: [PATCH] ADS-B: Only enable text to speech engine if speech used, as this can take 10 seconds on Linux --- plugins/channelrx/demodadsb/adsbdemodgui.cpp | 36 ++++++++++++++++---- plugins/channelrx/demodadsb/adsbdemodgui.h | 1 + 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/plugins/channelrx/demodadsb/adsbdemodgui.cpp b/plugins/channelrx/demodadsb/adsbdemodgui.cpp index 35a455966..4a75e0e78 100644 --- a/plugins/channelrx/demodadsb/adsbdemodgui.cpp +++ b/plugins/channelrx/demodadsb/adsbdemodgui.cpp @@ -3104,9 +3104,32 @@ void ADSBDemodGUI::checkDynamicNotification(Aircraft *aircraft) } } +// Initialise text to speech engine +// This takes 10 seconds on some versions of Linux, so only do it, if user actually +// has speech notifications configured +void ADSBDemodGUI::enableSpeechIfNeeded() +{ + if (m_speech) { + return; + } + for (const auto& notification : m_settings.m_notificationSettings) + { + if (!notification->m_speech.isEmpty()) + { + qDebug() << "ADSBDemodGUI: Enabling text to speech"; + m_speech = new QTextToSpeech(this); + return; + } + } +} + void ADSBDemodGUI::speechNotification(Aircraft *aircraft, const QString &speech) { - m_speech->say(subAircraftString(aircraft, speech)); + if (m_speech) { + m_speech->say(subAircraftString(aircraft, speech)); + } else { + qDebug() << "ADSBDemodGUI::speechNotification: Unable to say " << speech; + } } void ADSBDemodGUI::commandNotification(Aircraft *aircraft, const QString &command) @@ -3308,7 +3331,9 @@ void ADSBDemodGUI::on_feed_clicked(bool checked) void ADSBDemodGUI::on_notifications_clicked() { ADSBDemodNotificationDialog dialog(&m_settings); - if (dialog.exec() == QDialog::Accepted) { + if (dialog.exec() == QDialog::Accepted) + { + enableSpeechIfNeeded(); applySettings(); } } @@ -4216,7 +4241,7 @@ void ADSBDemodGUI::updateAirports() if (azEl.getDistance() <= m_settings.m_airportRange*1000.0f) { // Only display the airport if it's large enough - if (airportInfo->m_type >= m_settings.m_airportMinimumSize) + if (airportInfo->m_type >= (AirportInformation::AirportType)m_settings.m_airportMinimumSize) { // Only display heliports if enabled if (m_settings.m_displayHeliports || (airportInfo->m_type != AirportInformation::AirportType::Heliport)) @@ -4613,6 +4638,7 @@ ADSBDemodGUI::ADSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb m_airspaceModel(this), m_trackAircraft(nullptr), m_highlightAircraft(nullptr), + m_speech(nullptr), m_progressDialog(nullptr), m_loadingData(false) { @@ -4761,9 +4787,6 @@ ADSBDemodGUI::ADSBDemodGUI(PluginAPI* pluginAPI, DeviceUISet *deviceUISet, Baseb updateNavAids(); update3DModels(); - // Initialise text to speech engine - m_speech = new QTextToSpeech(this); - m_flightInformation = nullptr; m_aviationWeather = nullptr; @@ -4952,6 +4975,7 @@ void ADSBDemodGUI::displaySettings() getRollupContents()->restoreState(m_rollupState); blockApplySettings(false); + enableSpeechIfNeeded(); } void ADSBDemodGUI::leaveEvent(QEvent* event) diff --git a/plugins/channelrx/demodadsb/adsbdemodgui.h b/plugins/channelrx/demodadsb/adsbdemodgui.h index c54f66ecd..f411d0484 100644 --- a/plugins/channelrx/demodadsb/adsbdemodgui.h +++ b/plugins/channelrx/demodadsb/adsbdemodgui.h @@ -994,6 +994,7 @@ private: SWGSDRangel::SWGMapAnimation *engineAnimation(QDateTime startDateTime, int engine, bool stop); void checkStaticNotification(Aircraft *aircraft); void checkDynamicNotification(Aircraft *aircraft); + void enableSpeechIfNeeded(); void speechNotification(Aircraft *aircraft, const QString &speech); void commandNotification(Aircraft *aircraft, const QString &command); QString subAircraftString(Aircraft *aircraft, const QString &string);