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 QTEXTTOSPEECH_MOCK_H
5#define QTEXTTOSPEECH_MOCK_H
6
7#include "qtexttospeechengine.h"
8#include <QtCore/QBasicTimer>
9
10QT_BEGIN_NAMESPACE
11
12class QTextToSpeechEngineMock : public QTextToSpeechEngine
13{
14 Q_OBJECT
15
16public:
17 explicit QTextToSpeechEngineMock(const QVariantMap &parameters, QObject *parent = nullptr);
18 ~QTextToSpeechEngineMock();
19
20 QList<QLocale> availableLocales() const override;
21 QList<QVoice> availableVoices() const override;
22
23 void say(const QString &text) override;
24 void synthesize(const QString &text) override;
25 void stop(QTextToSpeech::BoundaryHint boundaryHint) override;
26 void pause(QTextToSpeech::BoundaryHint boundaryHint) override;
27 void resume() override;
28
29 double rate() const override;
30 bool setRate(double rate) override;
31 double pitch() const override;
32 bool setPitch(double pitch) override;
33 QLocale locale() const override;
34 bool setLocale(const QLocale &locale) override;
35 double volume() const override;
36 bool setVolume(double volume) override;
37 QVoice voice() const override;
38 bool setVoice(const QVoice &voice) override;
39 QTextToSpeech::State state() const override;
40 QTextToSpeech::ErrorReason errorReason() const override;
41 QString errorString() const override;
42
43protected:
44 void timerEvent(QTimerEvent *e) override;
45
46private:
47 // mock engine uses 100ms per word, +/- 50ms depending on rate
48 int wordTime() const { return 100 - int(50.0 * m_rate); }
49
50 const QVariantMap m_parameters;
51 QString m_text;
52 QLocale m_locale;
53 QVoice m_voice;
54 QBasicTimer m_timer;
55 double m_rate = 0.0;
56 double m_pitch = 0.0;
57 double m_volume = 0.5;
58 QTextToSpeech::State m_state = QTextToSpeech::Error;
59 QTextToSpeech::ErrorReason m_errorReason = QTextToSpeech::ErrorReason::Initialization;
60 QString m_errorString;
61 bool m_pauseRequested = false;
62 qsizetype m_currentIndex = -1;
63 QAudioFormat m_format;
64};
65
66QT_END_NAMESPACE
67
68#endif
69

source code of qtspeech/src/plugins/tts/mock/qtexttospeech_mock.h