A security layer simulating voice recognition verification.
More...
#include <voice_recognition_layer.h>
|
| void | Initialize () override |
| | Initializes the layer for display. Resets the layer state, ensures the layer is fully opaque, and starts audio recording after a short delay.
|
| |
| void | Reset () override |
| | Resets the layer to its initial state. Stops recording and timers, resets progress, clears audio buffers and visualizer data, resets UI element styles, and ensures the layer is fully opaque.
|
| |
| | VoiceRecognitionLayer (QWidget *parent=nullptr) |
| | Constructs a VoiceRecognitionLayer. Initializes the UI elements (title, audio visualizer, instructions, progress bar), sets up the layout, creates timers for progress, recognition duration, and audio processing, and initializes audio-related variables.
|
| |
| | ~VoiceRecognitionLayer () override |
| | Destructor. Stops audio recording and processing, stops and deletes timers.
|
| |
| | SecurityLayer (QWidget *parent=nullptr) |
| | Constructs a SecurityLayer.
|
| |
| | ~SecurityLayer () override=default |
| | Virtual destructor. Ensures proper cleanup for derived classes.
|
| |
|
| void | FinishRecognition () |
| | Slot called when the recognition process completes (either by progress reaching 100% or recognition_timer_ timeout). Stops recording and timers, updates UI elements to green to indicate success, renders a final green waveform, and initiates the fade-out animation after a short delay.
|
| |
| void | ProcessAudioInput () |
| | Slot called periodically by audio_process_timer_ to read and process available audio data. Reads data from the audio input device, calculates the current audio level, determines if the user is speaking (using a threshold and hysteresis), updates the visualizer data, and appends audio data to the buffer if speech is detected.
|
| |
| void | UpdateProgress () |
| | Slot called periodically by progress_timer_ to update the recognition progress bar. Increments the progress bar value only if speech is currently detected (is_speaking_ is true). Calls FinishRecognition() when the progress reaches 100%.
|
| |
|
| bool | IsSpeaking (float audio_level) const |
| | Determines if the given audio level exceeds the noise threshold.
|
| |
| void | StartRecording () |
| | Starts capturing audio from the default input device. Configures the audio format, initializes QAudioInput, starts the input device, and starts the associated timers (progress, recognition duration, audio processing).
|
| |
| void | StopRecording () |
| | Stops capturing audio and processing. Stops the QAudioInput, deletes the audio input object, stops the audio processing timer, and sets the is_recording_ flag to false.
|
| |
| void | UpdateAudioVisualizer (const QByteArray &data) |
| | Updates the audio_visualizer_label_ with a waveform representation of the audio data. Shifts existing visualizer data, adds new amplitude data, and redraws the waveform using QPainter. The color of the waveform changes based on whether speech is detected. Also draws a noise threshold indicator and a status text.
|
| |
|
| QByteArray | audio_buffer_ |
| | Buffer storing raw audio data captured while the user is speaking.
|
| |
| QIODevice * | audio_device_ |
| | I/O device providing access to the raw audio stream from audio_input_.
|
| |
| QAudioInput * | audio_input_ |
| | Object managing audio input capture.
|
| |
| QTimer * | audio_process_timer_ |
| | Timer controlling how often audio input is processed.
|
| |
| QLabel * | audio_visualizer_label_ |
| | Label used as a canvas to draw the audio waveform visualization.
|
| |
| float | current_audio_level_ |
| | The calculated audio level from the most recently processed audio chunk.
|
| |
| bool | is_recording_ |
| | Flag indicating if audio is currently being recorded.
|
| |
| bool | is_speaking_ |
| | Flag indicating if speech is currently detected (based on threshold and hysteresis).
|
| |
| float | noise_threshold_ |
| | Threshold level above which audio input is considered potential speech.
|
| |
| QTimer * | progress_timer_ |
| | Timer controlling the progress bar update based on speech detection.
|
| |
| QProgressBar * | recognition_progress_ |
| | Progress bar indicating the voice recognition progress.
|
| |
| QTimer * | recognition_timer_ |
| | Timer defining the maximum duration for the recognition attempt.
|
| |
| int | silence_counter_ |
| | Counter tracking the duration of silence in milliseconds.
|
| |
| TranslationManager * | translator_ |
| | The translation manager for handling UI translations.
|
| |
| QVector< float > | visualizer_data_ |
| | Vector storing normalized amplitude values for rendering the waveform visualizer.
|
| |
|
| void | layerCompleted () |
| | Emitted when the user successfully completes the security challenge presented by this layer.
|
| |
| void | layerFailed () |
| | Emitted when the user fails the security challenge (e.g., incorrect code, timeout, collision). Note: Not all layers currently implement failure conditions that emit this signal.
|
| |
A security layer simulating voice recognition verification.
This layer captures audio input from the default microphone and displays a real-time audio waveform visualization. It requires the user to speak continuously for a set duration (simulated by a progress bar filling up while speech is detected above a noise threshold). Upon successful completion (progress reaches 100%), the UI elements turn green, and the layer fades out, emitting the layerCompleted() signal.
◆ VoiceRecognitionLayer()
| VoiceRecognitionLayer::VoiceRecognitionLayer |
( |
QWidget * | parent = nullptr | ) |
|
|
explicit |
Constructs a VoiceRecognitionLayer. Initializes the UI elements (title, audio visualizer, instructions, progress bar), sets up the layout, creates timers for progress, recognition duration, and audio processing, and initializes audio-related variables.
- Parameters
-
| parent | Optional parent widget. |
◆ ~VoiceRecognitionLayer()
| VoiceRecognitionLayer::~VoiceRecognitionLayer |
( |
| ) |
|
|
override |
Destructor. Stops audio recording and processing, stops and deletes timers.
◆ FinishRecognition
| void VoiceRecognitionLayer::FinishRecognition |
( |
| ) |
|
|
privateslot |
Slot called when the recognition process completes (either by progress reaching 100% or recognition_timer_ timeout). Stops recording and timers, updates UI elements to green to indicate success, renders a final green waveform, and initiates the fade-out animation after a short delay.
◆ Initialize()
| void VoiceRecognitionLayer::Initialize |
( |
| ) |
|
|
overridevirtual |
Initializes the layer for display. Resets the layer state, ensures the layer is fully opaque, and starts audio recording after a short delay.
Implements SecurityLayer.
◆ IsSpeaking()
| bool VoiceRecognitionLayer::IsSpeaking |
( |
float | audio_level | ) |
const |
|
private |
Determines if the given audio level exceeds the noise threshold.
- Parameters
-
| audio_level | The calculated audio level (typically normalized RMS or average absolute value). |
- Returns
- True if the level is above the threshold, false otherwise.
- Note
- Actual speech detection logic with hysteresis is implemented in ProcessAudioInput().
◆ ProcessAudioInput
| void VoiceRecognitionLayer::ProcessAudioInput |
( |
| ) |
|
|
privateslot |
Slot called periodically by audio_process_timer_ to read and process available audio data. Reads data from the audio input device, calculates the current audio level, determines if the user is speaking (using a threshold and hysteresis), updates the visualizer data, and appends audio data to the buffer if speech is detected.
◆ Reset()
| void VoiceRecognitionLayer::Reset |
( |
| ) |
|
|
overridevirtual |
Resets the layer to its initial state. Stops recording and timers, resets progress, clears audio buffers and visualizer data, resets UI element styles, and ensures the layer is fully opaque.
Implements SecurityLayer.
◆ StartRecording()
| void VoiceRecognitionLayer::StartRecording |
( |
| ) |
|
|
private |
Starts capturing audio from the default input device. Configures the audio format, initializes QAudioInput, starts the input device, and starts the associated timers (progress, recognition duration, audio processing).
◆ StopRecording()
| void VoiceRecognitionLayer::StopRecording |
( |
| ) |
|
|
private |
Stops capturing audio and processing. Stops the QAudioInput, deletes the audio input object, stops the audio processing timer, and sets the is_recording_ flag to false.
◆ UpdateAudioVisualizer()
| void VoiceRecognitionLayer::UpdateAudioVisualizer |
( |
const QByteArray & | data | ) |
|
|
private |
Updates the audio_visualizer_label_ with a waveform representation of the audio data. Shifts existing visualizer data, adds new amplitude data, and redraws the waveform using QPainter. The color of the waveform changes based on whether speech is detected. Also draws a noise threshold indicator and a status text.
- Parameters
-
| data | The raw audio data chunk to visualize (used to calculate the new amplitude). |
◆ UpdateProgress
| void VoiceRecognitionLayer::UpdateProgress |
( |
| ) |
|
|
privateslot |
Slot called periodically by progress_timer_ to update the recognition progress bar. Increments the progress bar value only if speech is currently detected (is_speaking_ is true). Calls FinishRecognition() when the progress reaches 100%.
◆ audio_buffer_
| QByteArray VoiceRecognitionLayer::audio_buffer_ |
|
private |
Buffer storing raw audio data captured while the user is speaking.
◆ audio_device_
| QIODevice* VoiceRecognitionLayer::audio_device_ |
|
private |
I/O device providing access to the raw audio stream from audio_input_.
◆ audio_input_
| QAudioInput* VoiceRecognitionLayer::audio_input_ |
|
private |
Object managing audio input capture.
◆ audio_process_timer_
| QTimer* VoiceRecognitionLayer::audio_process_timer_ |
|
private |
Timer controlling how often audio input is processed.
◆ audio_visualizer_label_
| QLabel* VoiceRecognitionLayer::audio_visualizer_label_ |
|
private |
Label used as a canvas to draw the audio waveform visualization.
◆ current_audio_level_
| float VoiceRecognitionLayer::current_audio_level_ |
|
private |
The calculated audio level from the most recently processed audio chunk.
◆ is_recording_
| bool VoiceRecognitionLayer::is_recording_ |
|
private |
Flag indicating if audio is currently being recorded.
◆ is_speaking_
| bool VoiceRecognitionLayer::is_speaking_ |
|
private |
Flag indicating if speech is currently detected (based on threshold and hysteresis).
◆ noise_threshold_
| float VoiceRecognitionLayer::noise_threshold_ |
|
private |
Threshold level above which audio input is considered potential speech.
◆ progress_timer_
| QTimer* VoiceRecognitionLayer::progress_timer_ |
|
private |
Timer controlling the progress bar update based on speech detection.
◆ recognition_progress_
| QProgressBar* VoiceRecognitionLayer::recognition_progress_ |
|
private |
Progress bar indicating the voice recognition progress.
◆ recognition_timer_
| QTimer* VoiceRecognitionLayer::recognition_timer_ |
|
private |
Timer defining the maximum duration for the recognition attempt.
◆ silence_counter_
| int VoiceRecognitionLayer::silence_counter_ |
|
private |
Counter tracking the duration of silence in milliseconds.
◆ translator_
The translation manager for handling UI translations.
◆ visualizer_data_
| QVector<float> VoiceRecognitionLayer::visualizer_data_ |
|
private |
Vector storing normalized amplitude values for rendering the waveform visualizer.
The documentation for this class was generated from the following files: