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 <chrono>
4
5#include <QtCore/QHash>
6#include <QtCore/QObject>
7#include <QtCore/QSet>
8#include <QtCore/QString>
9
10class QTextToSpeech;
11class Fact;
12class AudioOutputTest;
13
16class AudioOutput : public QObject
17{
18 Q_OBJECT
19
20 friend AudioOutputTest;
21
22public:
24 enum class TextMod {
25 None = 0,
26 Translate = 1 << 0,
27 };
28 Q_FLAG(TextMod)
29 Q_DECLARE_FLAGS(TextMods, TextMod)
30
31
33 explicit AudioOutput(QObject *parent = nullptr);
34
37
40 static AudioOutput *instance();
41
43 void init(Fact *volumeFact, Fact *mutedFact);
44
48 void say(const QString &text, TextMods textMods = TextMod::None);
49
51 void testAudioOutput();
52
53private:
54 QTextToSpeech *_engine = nullptr;
55 qsizetype _textQueueSize = 0;
56 bool _initialized = false;
57 bool _speakCapable = false;
58 Fact *_volumeFact = nullptr;
59 Fact *_mutedFact = nullptr;
60 double _lastVolume = -1.0;
61
63 double _volumeSetting() const;
64
66 bool _mutedSetting() const;
67
69 void _setVolume();
70
72 void _applyEngineSettings();
73
75 void _finishInit();
76
77 static const QHash<QString, QString> _textHash;
78 static const QSet<QString> _spelledAcronyms;
79
80 static constexpr qsizetype kMaxTextQueueSize = 20;
81
83 static constexpr std::chrono::seconds kEngineInitWarnTimeout{10};
84
88 static QString _fixTextMessageForAudio(const QString &string);
89
93 static QString _replaceAbbreviations(const QString &input);
94
97 static QString _spokenAbbreviation(const QString& token);
98
100 static QString _replaceNegativeSigns(const QString &input);
101
103 static QString _replaceDecimalPoints(const QString &input);
104
106 static QString _replaceMeters(const QString &input);
107
109 static QString _convertMilliseconds(const QString &input);
110
116 static bool _getMillisecondString(const QString &string, QString &match, int &number);
117
118};
119Q_DECLARE_OPERATORS_FOR_FLAGS(AudioOutput::TextMods)
The AudioOutput class provides functionality for audio output using text-to-speech.
Definition AudioOutput.h:17
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:24
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:15