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 _engineSwitched = false;
58 bool _speakCapable = false;
59 Fact *_volumeFact = nullptr;
60 Fact *_mutedFact = nullptr;
61 double _lastVolume = -1.0;
62
64 double _volumeSetting() const;
65
67 bool _mutedSetting() const;
68
70 void _setVolume();
71
73 void _applyEngineSettings();
74
76 void _finishInit();
77
79 static QString _engineName();
80
82 void _fallBackToDefaultEngine();
83
84 static const QHash<QString, QString> _textHash;
85 static const QSet<QString> _spelledAcronyms;
86
87 static constexpr qsizetype kMaxTextQueueSize = 20;
88
90 static constexpr std::chrono::seconds kEngineInitWarnTimeout{10};
91
95 static QString _fixTextMessageForAudio(const QString &string);
96
100 static QString _replaceAbbreviations(const QString &input);
101
104 static QString _spokenAbbreviation(const QString& token);
105
107 static QString _replaceNegativeSigns(const QString &input);
108
110 static QString _replaceDecimalPoints(const QString &input);
111
113 static QString _replaceMeters(const QString &input);
114
116 static QString _convertMilliseconds(const QString &input);
117
123 static bool _getMillisecondString(const QString &string, QString &match, int &number);
124
125};
126Q_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)
AudioOutput(QObject *parent=nullptr)
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