语音活动检测
Streaming Sound Wave,以及它的派生类型如 Capturable Sound Wave,支持语音活动检测(VAD)。VAD 会过滤传入的音频数据,仅当检测到语音时才填充内部缓冲区。
该插件提供两种 VAD 实现:
- Default VAD
- Silero VAD
默认实现使用 libfvad,这是一个轻量级的语音活动检测库,可以在 Runtime Audio Importer 支持的所有平台和引擎版本上高效运行。
Silero VAD 以扩展插件的形式提供,它是一种基于神经网络的语音活动检测器,精度更高,尤其是在嘈杂的环境中。它使用机器学习来更可靠地区分语音和背景噪声。
基本用法
要在创建 Sound Wave 后启用 VAD,请使用 ToggleVAD 函数:
- Blueprint
- C++

// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
StreamingSoundWave->ToggleVAD(true);
启用VAD后,您可以随时重置它:
- Blueprint
- C++

// Reset the VAD
StreamingSoundWave->ResetVAD();
默认 VAD 设置
当使用默认 VAD 提供程序时,您可以通过更改 VAD 模式来调整其灵敏性:
- Blueprint
- C++

// Set the VAD mode (only works with the default VAD provider)
StreamingSoundWave->SetVADMode(ERuntimeVADMode::VeryAggressive);
mode 参数控制 VAD 过滤音频的积极程度。值越高越严格,意味着它们不太可能报告误报,但可能会遗漏一些语音。
VAD 提供程序
在使用 ToggleVAD 函数启用 VAD 后,您可以根据需要选择不同的语音活动检测提供程序。默认提供程序是内置的,而其他提供程序(如 Silero VAD)可通过扩展插件获得。
- Blueprint
- C++

// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
// Make sure to call ToggleVAD(true) before setting the provider
// Set the VAD provider to Silero VAD
StreamingSoundWave->SetVADProvider(URuntimeSileroVADProvider::StaticClass());
Silero VAD Extension
Silero VAD 使用神经网络提供更准确的语音检测。要使用它:
-
确保 Runtime Audio Importer 插件已安装在你的项目中
-
对于 UE 5.5 及更早版本: 在下载 Silero VAD 扩展插件之前,请确保在项目中禁用了 NNERuntimeORT。由于冲突,在这些引擎版本上启用 NNERuntimeORT 可能会导致使用 Silero VAD 时崩溃。
-
从 这里 下载 Silero VAD 扩展插件
-
将下载的压缩包中的文件夹解压到你项目的
Plugins文件夹中(如果该文件夹不存在,请创建) -
对于 UE 5.6 及更高版本: 编辑
RuntimeAudioImporterSileroVAD.uplugin文件,添加 NNERuntimeORT 依赖。在 "Plugins" 字段中,在 RuntimeAudioImporter 包含项之后添加:
,
{
"Name": "NNERuntimeORT",
"Enabled": true
}
- 重新构建你的项目(此扩展需要C++项目)
-
默认VAD适用于Runtime Audio Importer支持的所有引擎版本(UE 4.24、4.25、4.26、4.27、5.0、5.1、5.2、5.3、5.4、5.5、5.6、5.7和5.8)
-
Silero VAD支持Unreal Engine 4.27及所有UE5版本(4.27、5.0、5.1、5.2、5.3、5.4、5.5、5.6、5.7和5.8)
-
UE 5.5及更早版本: 在使用Silero VAD之前必须禁用NNERuntimeORT,以防止插件冲突导致崩溃。特别是在UE 5.3中,还必须禁用NNERuntimeORTCpu和NNERuntimeORTGpu
-
UE 5.6+要求: 从Unreal Engine 5.6开始,Silero VAD扩展需要将NNERuntimeORT插件依赖手动添加到
.uplugin文件中 -
Silero VAD适用于Windows、Linux、Mac、Android(包括Meta Quest)和iOS
-
此扩展以源代码形式提供,使用它需要C++项目
-
有关如何手动构建插件的更多信息,请参阅构建插件教程
安装后,你可以使用SetVADProvider函数并选择Silero类提供程序,将其选为你的VAD提供程序。
语音开始和结束检测
语音活动检测不仅能检测语音的存在,还能检测语音活动的开始和结束。这在播放或捕获期间语音开始或结束时触发事件非常有用。
你可以通过调整参数(如最小语音持续时间和静音持续时间)来自定义语音开始和结束检测的灵敏度。这些参数有助于微调检测,以避免误报,比如拾取短暂的噪音或语音间过短的停顿。
最小语音持续时间
最小语音持续时间参数设置触发语音开始事件所需的最小连续语音活动量。这有助于滤除不应被视为语音的短暂噪音,确保只有持续的语音活动被识别。最小语音持续时间的默认值为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);
Silence Duration
Silence Duration 参数设置触发语音结束事件所需的静默持续时间。这可以防止在单词或句子之间的自然停顿期间过早结束语音检测。Silence Duration 的默认值为 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
});