public class AgoraAudioVadV2
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private class |
AgoraAudioVadV2.VadData
Simple container for an audio frame and its activity flag.
|
| Modifier and Type | Field and Description |
|---|---|
private int |
adaptiveStartRmsThreshold
Adaptive RMS threshold for start speaking (cached for logging)
|
private int |
adaptiveStopRmsThreshold
Adaptive RMS threshold for stop speaking (cached for logging)
|
private Constants.VadState |
currentState
Current state of the voice activity detector.
|
private int |
refAvgRmsInLastSession
range from 0 to 127, respond to db: -127db, to 0db
|
private int |
silenceCount
Count of recent frames considered as silence.
|
private java.util.Deque<AgoraAudioVadV2.VadData> |
startQueue
Buffer of frames collected while waiting to start speaking.
|
private int |
startSize
Required frame count before declaring the speaking state.
|
private java.util.Deque<AgoraAudioVadV2.VadData> |
stopQueue
Buffer of frames collected while confirming the stop state.
|
private int |
totalVoiceRms
range from 0 to 127, respond to db: -127db, to 0db
|
private AgoraAudioVadConfigV2 |
vadConfig
Runtime configuration for the VAD algorithm.
|
private int |
voiceCount
Count of recent frames considered as voice.
|
| Constructor and Description |
|---|
AgoraAudioVadV2(AgoraAudioVadConfigV2 config)
Creates a VAD instance with the specified configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy()
Destroys the VAD instance and clears cached data.
|
int |
getAdaptiveStartRmsThreshold()
Get current adaptive start RMS threshold
|
int |
getAdaptiveStopRmsThreshold()
Get current adaptive stop RMS threshold
|
private int |
getRefActiveAvgRms(AgoraAudioVadConfigV2 currentVadConfig)
Get reference average RMS threshold for voice activity detection
This implements the adaptive threshold logic from Go SDK
|
int |
getRefAvgRmsInLastSession()
Get the reference average RMS from last session
|
private int |
getSilenceCount(java.util.Deque<AgoraAudioVadV2.VadData> queue,
int startIndex)
Counts the number of silent frames within a queue.
|
private void |
initData()
Resets queues and counters according to the current configuration.
|
boolean |
isActive()
Check if VAD is currently active (speaking detected)
|
private boolean |
isVadActive(AudioFrame frame,
AgoraAudioVadConfigV2 currentVadConfig)
Evaluates a frame to decide whether it is active speech.
|
VadProcessResult |
processFrame(AudioFrame frame)
Process the audio frame
|
private byte[] |
processSpeaking(AgoraAudioVadV2.VadData vadData,
AgoraAudioVadConfigV2 currentVadConfig)
Handles frames while speaking and tracks potential stop transitions.
|
private byte[] |
processStart(AgoraAudioVadV2.VadData vadData,
AgoraAudioVadConfigV2 currentVadConfig)
Handles the transition from silence to speaking by analysing buffered frames.
|
private volatile AgoraAudioVadConfigV2 vadConfig
private volatile Constants.VadState currentState
private volatile int startSize
private volatile java.util.Deque<AgoraAudioVadV2.VadData> startQueue
private volatile java.util.Deque<AgoraAudioVadV2.VadData> stopQueue
private volatile int voiceCount
private volatile int silenceCount
private volatile int totalVoiceRms
private volatile int refAvgRmsInLastSession
private volatile int adaptiveStartRmsThreshold
private volatile int adaptiveStopRmsThreshold
public AgoraAudioVadV2(AgoraAudioVadConfigV2 config)
config - VAD configurationprivate void initData()
public VadProcessResult processFrame(AudioFrame frame)
frame - the audio frameprivate boolean isVadActive(AudioFrame frame, AgoraAudioVadConfigV2 currentVadConfig)
frame - Frame being evaluatedcurrentVadConfig - Active configurationtrue if the frame is considered speechprivate int getRefActiveAvgRms(AgoraAudioVadConfigV2 currentVadConfig)
currentVadConfig - the current VAD configurationprivate byte[] processStart(AgoraAudioVadV2.VadData vadData, AgoraAudioVadConfigV2 currentVadConfig)
vadData - Newly appended datacurrentVadConfig - Active configurationprivate byte[] processSpeaking(AgoraAudioVadV2.VadData vadData, AgoraAudioVadConfigV2 currentVadConfig)
vadData - Newly appended datacurrentVadConfig - Active configurationprivate int getSilenceCount(java.util.Deque<AgoraAudioVadV2.VadData> queue, int startIndex)
queue - Queue containing historical datastartIndex - Index to begin countingpublic boolean isActive()
public int getRefAvgRmsInLastSession()
public int getAdaptiveStartRmsThreshold()
public int getAdaptiveStopRmsThreshold()
public void destroy()