QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AudioOutput.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4
5#include <chrono>
6
7class QTextToSpeech;
8class Fact;
9class AudioOutputTest;
10
13class AudioOutput : public QObject
14{
15 Q_OBJECT
16
17 friend AudioOutputTest;
18
19public:
21 enum class TextMod {
22 None = 0,
23 Translate = 1 << 0,
24 };
25 Q_FLAG(TextMod)
26 Q_DECLARE_FLAGS(TextMods, TextMod)
27
28
30 explicit AudioOutput(QObject *parent = nullptr);
31
34
37 static AudioOutput *instance();
38
40 void init(Fact *volumeFact, Fact *mutedFact);
41
45 void say(const QString &text, TextMods textMods = TextMod::None);
46
48 void testAudioOutput();
49
50private:
51 QTextToSpeech *_engine = nullptr;
52 qsizetype _textQueueSize = 0;
53 bool _initialized = false;
54 bool _speakCapable = false;
55 Fact *_volumeFact = nullptr;
56 Fact *_mutedFact = nullptr;
57 double _lastVolume = -1.0;
58
60 double _volumeSetting() const;
61
63 bool _mutedSetting() const;
64
66 void _setVolume();
67
69 void _applyEngineSettings();
70
72 void _finishInit();
73
74 static const QHash<QString, QString> _textHash;
75
76 static constexpr qsizetype kMaxTextQueueSize = 20;
77
79 static constexpr std::chrono::seconds kEngineInitWarnTimeout{10};
80
84 static QString _fixTextMessageForAudio(const QString &string);
85
89 static QString _replaceAbbreviations(const QString &input);
90
92 static QString _replaceNegativeSigns(const QString &input);
93
95 static QString _replaceDecimalPoints(const QString &input);
96
98 static QString _replaceMeters(const QString &input);
99
101 static QString _convertMilliseconds(const QString &input);
102
108 static bool _getMillisecondString(const QString &string, QString &match, int &number);
109
110};
111Q_DECLARE_OPERATORS_FOR_FLAGS(AudioOutput::TextMods)
The AudioOutput class provides functionality for audio output using text-to-speech.
Definition AudioOutput.h:14
void say(const QString &text, TextMods textMods=TextMod::None)
void testAudioOutput()
Tests the audio output. Will stop current output before test.
TextMod
Enumeration for text modification options.
Definition AudioOutput.h:21
static AudioOutput * instance()
~AudioOutput()
Destructor for the AudioOutput class.
void init(Fact *volumeFact, Fact *mutedFact)
Initialize the Singleton.
A Fact is used to hold a single value within the system.
Definition Fact.h:17