1 | // Copyright (C) 2022 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_FLITE_H |
5 | #define QTEXTTOSPEECHENGINE_FLITE_H |
6 | |
7 | #include "qtexttospeech_flite_processor.h" |
8 | #include "qtexttospeechengine.h" |
9 | #include "qvoice.h" |
10 | |
11 | #include <QtCore/QString> |
12 | #include <QtCore/QList> |
13 | #include <QtCore/QLocale> |
14 | #include <QtCore/QMultiHash> |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class QTextToSpeechEngineFlite : public QTextToSpeechEngine |
19 | { |
20 | Q_OBJECT |
21 | |
22 | public: |
23 | QTextToSpeechEngineFlite(const QVariantMap ¶meters, QObject *parent); |
24 | ~QTextToSpeechEngineFlite() override; |
25 | |
26 | // Plug-in API: |
27 | QList<QLocale> availableLocales() const override; |
28 | QList<QVoice> availableVoices() const override; |
29 | void say(const QString &text) override; |
30 | void synthesize(const QString &text) override; |
31 | void stop(QTextToSpeech::BoundaryHint boundaryHint) override; |
32 | void pause(QTextToSpeech::BoundaryHint boundaryHint) override; |
33 | void resume() override; |
34 | double rate() const override; |
35 | bool setRate(double rate) override; |
36 | double pitch() const override; |
37 | bool setPitch(double pitch) override; |
38 | QLocale locale() const override; |
39 | bool setLocale(const QLocale &locale) override; |
40 | double volume() const override; |
41 | bool setVolume(double volume) override; |
42 | QVoice voice() const override; |
43 | bool setVoice(const QVoice &voice) override; |
44 | QTextToSpeech::State state() const override; |
45 | QTextToSpeech::ErrorReason errorReason() const override; |
46 | QString errorString() const override; |
47 | |
48 | Q_SIGNALS: |
49 | void speaking(); |
50 | void engineErrorOccurred(QTextToSpeech::ErrorReason, const QString &errorString); |
51 | |
52 | private slots: |
53 | void changeState(QTextToSpeech::State newState); |
54 | void setError(QTextToSpeech::ErrorReason error, const QString &errorString); |
55 | |
56 | private: |
57 | QTextToSpeech::State m_state = QTextToSpeech::Error; |
58 | QTextToSpeech::ErrorReason m_errorReason = QTextToSpeech::ErrorReason::Initialization; |
59 | QString m_errorString; |
60 | |
61 | QVoice m_voice; |
62 | double m_rate = 0; |
63 | double m_pitch = 1; |
64 | double m_volume = 1; |
65 | |
66 | // Voices mapped by their locale name. |
67 | QMultiHash<QLocale, QVoice> m_voices; |
68 | |
69 | // Thread for blocking operations |
70 | QThread m_thread; |
71 | std::unique_ptr<QTextToSpeechProcessorFlite> m_processor; |
72 | }; |
73 | |
74 | QT_END_NAMESPACE |
75 | |
76 | #endif |
77 |