语音活动检测
Streaming Sound Wave,及其派生类型如Capturable Sound Wave,支持语音活动检测(VAD)。VAD过滤输入音频数据,仅在检测到语音时填充内部缓冲区。此功能通过libfvad实现。
在创建音波后,可以使用相应的函数启用VAD。
- Blueprint
- C++
// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
StreamingSoundWave->ToggleVAD(true);
一旦启用 VAD,您可以根据需要设置 VAD 模式或重置 VAD。 这些函数应仅在启用 VAD 时调用。
- Blueprint
- C++
// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
// Set the VAD mode
StreamingSoundWave->SetVADMode(ERuntimeVADMode::VeryAggressive);
// Reset the VAD
StreamingSoundWave->ResetVAD();
语音开始和结束检测
语音活动检测不仅检测语音的存在,还可以检测语音活动的开始和结束。这对于在回放或捕获过程中触发语音开始或结束时的事件非常有用。
您可以通过调整参数(如最小语音持续时间和静音持续时间)来自定义语音开始和结束检测的灵敏度。这些参数有助于微调检测,以避免误报,如拾取短暂噪音或语音之间过短的停顿。
最小语音持续时间
最小语音持续时间参数设置触发语音开始事件所需的最小连续语音活动时间。这有助于过滤不应视为语音的短暂噪音,确保只识别持续的语音活动。最小语音持续时间的默认值为300毫秒。
- Blueprint
- C++
// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
// Set the minimum speech duration
StreamingSoundWave->SetMinimumSpeechDuration(200);
静音持续时间
静音持续时间参数设置触发语音结束事件所需的静默持续时间。这可以防止在单词或句子之间的自然停顿期间语音检测 过早结束。静音持续时间的默认值为500毫秒。
- Blueprint
- C++
// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
// Set the silence duration
StreamingSoundWave->SetSilenceDuration(700);
绑定到语音代理
您可以在语音开始或结束时绑定到特定的代理。这对于根据语音活动触发自定义行为非常有用,例如启动或停止文本识别,或调整其他音频源的音量。
- Blueprint
- C++
// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
// Bind to the OnSpeechStartedNative delegate
StreamingSoundWave->OnSpeechStartedNative.AddWeakLambda(this, [this]()
{
// Handle the result when speech starts
});
// Bind to the OnSpeechEndedNative delegate
StreamingSoundWave->OnSpeechEndedNative.AddWeakLambda(this, [this]()
{
// Handle the result when speech ends
});