Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
voice_recognition_layer.h
Go to the documentation of this file.
1#ifndef VOICE_RECOGNITION_LAYER_H
2#define VOICE_RECOGNITION_LAYER_H
3
4#include "../security_layer.h"
5
6class QAudioInput;
7class QProgressBar;
8class QLabel;
10
21 Q_OBJECT
22
23public:
31 explicit VoiceRecognitionLayer(QWidget *parent = nullptr);
32
37 ~VoiceRecognitionLayer() override;
38
44 void Initialize() override;
45
51 void Reset() override;
52
53private slots:
60 void ProcessAudioInput();
61
67 void UpdateProgress();
68
74 void FinishRecognition();
75
76private:
82 void StartRecording();
83
89 void StopRecording();
90
98 void UpdateAudioVisualizer(const QByteArray &data);
99
106 bool IsSpeaking(float audio_level) const;
107
118
120 QAudioInput *audio_input_;
122 QIODevice *audio_device_;
123
125 QByteArray audio_buffer_;
127 QVector<float> visualizer_data_;
130
141};
142
143#endif // VOICE_RECOGNITION_LAYER_H
SecurityLayer(QWidget *parent=nullptr)
Constructs a SecurityLayer.
Definition security_layer.h:20
Manages the loading and delivery of translations for applications.
Definition translation_manager.h:15
QProgressBar * recognition_progress_
Progress bar indicating the voice recognition progress.
Definition voice_recognition_layer.h:111
int silence_counter_
Counter tracking the duration of silence in milliseconds.
Definition voice_recognition_layer.h:136
QAudioInput * audio_input_
Object managing audio input capture.
Definition voice_recognition_layer.h:120
QTimer * recognition_timer_
Timer defining the maximum duration for the recognition attempt.
Definition voice_recognition_layer.h:115
void UpdateAudioVisualizer(const QByteArray &data)
Updates the audio_visualizer_label_ with a waveform representation of the audio data....
Definition voice_recognition_layer.cpp:258
void Reset() override
Resets the layer to its initial state. Stops recording and timers, resets progress,...
Definition voice_recognition_layer.cpp:126
QIODevice * audio_device_
I/O device providing access to the raw audio stream from audio_input_.
Definition voice_recognition_layer.h:122
void UpdateProgress()
Slot called periodically by progress_timer_ to update the recognition progress bar....
Definition voice_recognition_layer.cpp:341
~VoiceRecognitionLayer() override
Destructor. Stops audio recording and processing, stops and deletes timers.
Definition voice_recognition_layer.cpp:94
bool is_recording_
Flag indicating if audio is currently being recorded.
Definition voice_recognition_layer.h:129
TranslationManager * translator_
The translation manager for handling UI translations.
Definition voice_recognition_layer.h:140
bool is_speaking_
Flag indicating if speech is currently detected (based on threshold and hysteresis).
Definition voice_recognition_layer.h:134
QTimer * progress_timer_
Timer controlling the progress bar update based on speech detection.
Definition voice_recognition_layer.h:113
void StartRecording()
Starts capturing audio from the default input device. Configures the audio format,...
Definition voice_recognition_layer.cpp:164
QLabel * audio_visualizer_label_
Label used as a canvas to draw the audio waveform visualization.
Definition voice_recognition_layer.h:109
QByteArray audio_buffer_
Buffer storing raw audio data captured while the user is speaking.
Definition voice_recognition_layer.h:125
QTimer * audio_process_timer_
Timer controlling how often audio input is processed.
Definition voice_recognition_layer.h:117
float noise_threshold_
Threshold level above which audio input is considered potential speech.
Definition voice_recognition_layer.h:132
bool IsSpeaking(float audio_level) const
Determines if the given audio level exceeds the noise threshold.
Definition voice_recognition_layer.cpp:210
float current_audio_level_
The calculated audio level from the most recently processed audio chunk.
Definition voice_recognition_layer.h:138
QVector< float > visualizer_data_
Vector storing normalized amplitude values for rendering the waveform visualizer.
Definition voice_recognition_layer.h:127
void ProcessAudioInput()
Slot called periodically by audio_process_timer_ to read and process available audio data....
Definition voice_recognition_layer.cpp:214
void Initialize() override
Initializes the layer for display. Resets the layer state, ensures the layer is fully opaque,...
Definition voice_recognition_layer.cpp:116
void FinishRecognition()
Slot called when the recognition process completes (either by progress reaching 100% or recognition_t...
Definition voice_recognition_layer.cpp:358
void StopRecording()
Stops capturing audio and processing. Stops the QAudioInput, deletes the audio input object,...
Definition voice_recognition_layer.cpp:192
VoiceRecognitionLayer(QWidget *parent=nullptr)
Constructs a VoiceRecognitionLayer. Initializes the UI elements (title, audio visualizer,...
Definition voice_recognition_layer.cpp:15