Add a new QtTextToSpeech backend

This commit is contained in:
Hannah von Reth 2017-01-20 10:46:07 +01:00
parent cb4c38411a
commit 7c21be4e26
4 changed files with 30 additions and 10 deletions

View File

@ -1,4 +1,5 @@
ecm_optional_add_subdirectory(toasty)
ecm_optional_add_subdirectory(nma)
ecm_optional_add_subdirectory(sound)
ecm_optional_add_subdirectory(speech)
ecm_optional_add_subdirectory(pushover_backend)

View File

@ -28,7 +28,7 @@ Sound::Sound():
// connect(m_player,QMediaPlayer::positionChanged,[](qint64 pos){
// qCDebug(SNORE) << "Player: " << pos;
// });
connect(m_player, &QMediaPlayer::stateChanged, [](QMediaPlayer::State state) {
connect(m_player, &QMediaPlayer::stateChanged, this, [](QMediaPlayer::State state) {
qCDebug(SNORE) << "Player: " << state;
});
}

View File

@ -1,6 +1,19 @@
#include "speech.h"
Speech::Speech(QObject *parent) : QObject(parent)
#include <QtTextToSpeech/QTextToSpeech>
Speech::Speech()
: Snore::SnoreSecondaryBackend()
, m_speech(new QTextToSpeech(this))
{
connect(m_speech, &QTextToSpeech::stateChanged, this, [this](QTextToSpeech::State state){
qCDebug(SNORE) << state;
if (state == QTextToSpeech::BackendError) {
setErrorString(tr("Sytem Backend Error"));
}
});
}
void Speech::slotNotificationDisplayed(Snore::Notification notification)
{
m_speech->say(tr("%1: %2 %3").arg(notification.application().name(), notification.title(), notification.text()));
}

View File

@ -1,17 +1,23 @@
#ifndef SPEECH_H
#define SPEECH_H
#include <QObject>
#include <plugins/snoresecondarybackend.h>
class Speech : public QObject
class QTextToSpeech;
class Speech : public Snore::SnoreSecondaryBackend
{
Q_OBJECT
Q_INTERFACES(Snore::SnoreSecondaryBackend)
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0" FILE "snore_plugin.json")
public:
explicit Speech(QObject *parent = 0);
explicit Speech();
~Speech() = default;
signals:
public slots:
public Q_SLOTS:
void slotNotificationDisplayed(Snore::Notification notification) override;
private:
QTextToSpeech *m_speech;
};
#endif // SPEECH_H
#endif // SPEECH_H