File indexing completed on 2024-06-16 04:29:31
0001 #include "speech.h" 0002 0003 #include <QCoreApplication> 0004 #include <QtTextToSpeech/QTextToSpeech> 0005 0006 #include <snore.h> 0007 Speech::Speech() 0008 : Snore::SnoreSecondaryBackend() 0009 , m_speech(new QTextToSpeech(qApp)) 0010 { 0011 connect(m_speech, &QTextToSpeech::stateChanged, this, [this](QTextToSpeech::State state) { 0012 qCDebug(SNORE) << state; 0013 if (state == QTextToSpeech::BackendError) { 0014 setErrorString(tr("System Backend Error")); 0015 } 0016 }); 0017 connect(this, &Speech::enabledChanged, this, [this](bool b) { 0018 if (b) { 0019 connect(&Snore::SnoreCore::instance(), &Snore::SnoreCore::notificationClosed, this, &Speech::slotNotificationClosed); 0020 } else { 0021 disconnect(&Snore::SnoreCore::instance(), &Snore::SnoreCore::notificationClosed, this, &Speech::slotNotificationClosed); 0022 } 0023 }); 0024 } 0025 0026 void Speech::slotNotificationDisplayed(Snore::Notification notification) 0027 { 0028 m_speech->say(tr("%1: %2 %3").arg(notification.application().name(), notification.title(), notification.text())); 0029 } 0030 0031 void Speech::slotNotificationClosed(Snore::Notification notificatiom) { 0032 // TODO: que notifications on our side and make sure to only stop playback of the canceled notification 0033 if (notificatiom.closeReason() != Snore::Notification::TimedOut && m_speech->state() == QTextToSpeech::Speaking) { 0034 m_speech->stop(); 0035 } 0036 }