5#include "CoreMinimal.h"
6#include "Misc/ScopeLock.h"
20#pragma region public API
28 void RegisterSocket(TWeakPtr<AudioWebSocket> socket,
int bufferMillisecondSize);
63 void ShutDown(
bool alsoDestroyCaptureDevice =
false);
79 TArray<uint8> m_socketDataBuffer;
81 static constexpr float DEFAULT_SILENCE_DECIBELS = -144.f;
86 FString m_deviceName = EMPTY_STRING;
87 bool m_isCapturing =
false;
88 int m_bufferMillisecondSize = 0;
90 float m_decibels = DEFAULT_SILENCE_DECIBELS;
91 bool m_isTestMode =
false;
92 FDateTime m_lastVoiceTimestamp = FDateTime();
94 mutable FCriticalSection m_captureGuard;
95 TUniquePtr<FVoiceRunnerThread> m_voiceRunnerThread;
96 TWeakPtr<AudioWebSocket> m_webSocket;
97 TSharedPtr<IVoiceCapture> m_voiceCaptureDevice;
100#pragma region private API
102 void CaptureAndSendVoiceData();
110 bool CaptureVoiceInternal(TArray<uint8>& voiceDataBuffer,
float& decibels)
const;
117 void SendInternal(
const TArray<uint8>& rawData)
const;
127 float AnalyseDecibels(
const TArray<uint8>& voiceInputData, uint32 dataSize)
const;
130 bool IsInputSilentInternal()
const;
AudioCaptureHandler.
Definition AudioCaptureHandler.h:19
bool TryInitializeVoiceCapture(int sampleRate=16000, int numChannels=1)
Tries to create a voice capture instance (IVoiceCapture).
Definition AudioCaptureHandler.cpp:18
void RegisterSocket(TWeakPtr< AudioWebSocket > socket, int bufferMillisecondSize)
Store a pointer to the websocket that will receive the parsed data from the FVoiceModule.
Definition AudioCaptureHandler.cpp:12
bool TryStartVoiceCapture()
Tries to start that IVoiceCapture and also start the background thread that will forward any captured...
Definition AudioCaptureHandler.cpp:82
void ShutDown(bool alsoDestroyCaptureDevice=false)
Stops the capture, permanently clearing the reserved memory for the background thread.
Definition AudioCaptureHandler.cpp:141
friend class FVoiceRunnerThread
The background thread needs access to our private functions.
Definition AudioCaptureHandler.h:84
void ConfigureSilenceThresholds(float micNoiseGateThreshold, float silenceDetectionThreshold, float micInputGain)
Configure values to help the microphone to pick up voice without background noise.
Definition AudioCaptureHandler.cpp:63
float GetDecibels() const
Definition AudioCaptureHandler.cpp:230
const FString & GetDeviceName() const
Definition AudioCaptureHandler.cpp:236
void StopCapture()
Stop the voice capture, reset the buffers and stops the background thread.
Definition AudioCaptureHandler.cpp:122
bool IsInputSilent() const
Definition AudioCaptureHandler.cpp:185
void SetIsTestMode(bool isTestMode)
Definition AudioCaptureHandler.cpp:241
AudioWebSocket Main low level API to communicate with the audio streaming socket of VoxtaServer.
Definition AudioWebSocket.h:16