1 | // Copyright (C) 2015 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only |
3 | |
4 | #ifndef QTEXTTOSPEECHENGINE_SPEECHD_H |
5 | #define QTEXTTOSPEECHENGINE_SPEECHD_H |
6 | |
7 | #include "qtexttospeechengine.h" |
8 | #include "qvoice.h" |
9 | |
10 | #include <QtCore/qhash.h> |
11 | #include <QtCore/qlist.h> |
12 | #include <QtCore/qlocale.h> |
13 | #include <QtCore/qobject.h> |
14 | #include <QtCore/qstring.h> |
15 | #include <libspeechd.h> |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | class QTextToSpeechEngineSpeechd : public QTextToSpeechEngine |
20 | { |
21 | Q_OBJECT |
22 | |
23 | public: |
24 | QTextToSpeechEngineSpeechd(const QVariantMap ¶meters, QObject *parent); |
25 | ~QTextToSpeechEngineSpeechd(); |
26 | |
27 | // Plug-in API: |
28 | QList<QLocale> availableLocales() const override; |
29 | QList<QVoice> availableVoices() const override; |
30 | void say(const QString &text) override; |
31 | void synthesize(const QString &text) override; |
32 | void stop(QTextToSpeech::BoundaryHint boundaryHint) override; |
33 | void pause(QTextToSpeech::BoundaryHint boundaryHint) override; |
34 | void resume() override; |
35 | double rate() const override; |
36 | bool setRate(double rate) override; |
37 | double pitch() const override; |
38 | bool setPitch(double pitch) override; |
39 | QLocale locale() const override; |
40 | bool setLocale(const QLocale &locale) override; |
41 | double volume() const override; |
42 | bool setVolume(double volume) override; |
43 | QVoice voice() const override; |
44 | bool setVoice(const QVoice &voice) override; |
45 | QTextToSpeech::State state() const override; |
46 | QTextToSpeech::ErrorReason errorReason() const override; |
47 | QString errorString() const override; |
48 | |
49 | void spdStateChanged(SPDNotificationType state); |
50 | |
51 | private: |
52 | QLocale localeForVoice(SPDVoice *voice) const; |
53 | bool connectToSpeechDispatcher(); |
54 | void updateVoices(); |
55 | void setError(QTextToSpeech::ErrorReason reason, const QString &errorString); |
56 | |
57 | QTextToSpeech::State m_state = QTextToSpeech::Error; |
58 | QTextToSpeech::ErrorReason m_errorReason = QTextToSpeech::ErrorReason::Initialization; |
59 | QString m_errorString; |
60 | SPDConnection *speechDispatcher; |
61 | QVoice m_currentVoice; |
62 | // Voices mapped by their locale name. |
63 | QMultiHash<QLocale, QVoice> m_voices; |
64 | }; |
65 | |
66 | QT_END_NAMESPACE |
67 | |
68 | #endif |
69 |