语音活动检测
流式声波及其派生类型(如可捕获声波)支持语音活动检测(VAD)。VAD 会过滤传入的音频数据,仅在检测到语音时填充内部缓冲区。
该插件提供两种 VAD 实现:
- 默认 VAD
- Silero VAD
默认实现使用 libfvad,这是一个轻量级的语音活动检测库,可在 Runtime Audio Importer 支持的所有平台和引擎版本上高效运行。
作为扩展插件提供,Silero VAD 是一种基于神经网络的语音活动检测器,提供更高的准确性,尤其是在嘈杂环境中。它使用机器学习更可靠地区分语音和背景噪声。
基本用法
要在创建声波后启用 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 扩展
Silero VAD 使用神经网络提供更准确的语音检测。使用方法如下:
-
确保 Runtime Audio Importer 插件已安装在您的项目中
-
对于 UE 5.5 及更早版本: 在下载 Silero VAD 扩展插件之前,请确保您项目中已禁用 NNERuntimeORT。在这些引擎版本上,启用 NNERuntimeORT 可能会因冲突导致使用 Silero VAD 时崩溃
-
从 Google Drive 下载 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)
-
Silero VAD 支持 Unreal Engine 4.27 及所有 UE5 版本(4.27、5.0、5.1、5.2、5.3、5.4、5.5 和 5.6)
-
UE 5.5 及更早版本: 在使用 Silero VAD 之前必须禁用 NNERuntimeORT,以防止因插件冲突导致的崩溃
-
UE 5.6+ 要求: 从 Unreal Engine 5.6 开始,Silero VAD 扩展需要手动将 NNERuntimeORT 插件依赖项添加到
.uplugin
文件中 -
Silero VAD 可用于 Windows、Linux、Mac、Android(包括 Meta Quest)和 iOS
-
此扩展以源代码形式提供,需要 C++ 项目才能使用
-
有关如何手动构建插件的更多信息,请参阅构建插件教程
安装后,您可以使用 SetVADProvider
函数并选择 Silero 类提供程序作为您的 VAD 提供程序。
语音开始与结束检测
语音活动检测(Voice Activity Detection)不仅检测语音的存在,还允许检测语音活动的开始和结束。这对于在播放或捕获过程中触发语音开始或结束的事件非常有用。
您可以通过调整参数(如最小语音持续时间和静音持续时间)来自定义语音开始和结束检测的灵敏度。这些参数有助于微调检测,以避免误报,例如拾取短暂的噪音或语音之间过短的停顿。
最小语音持续时 间
最小语音持续时间参数设置了触发语音开始事件所需的最小连续语音活动量。这有助于过滤掉不应被视为语音的短暂噪音,确保只有持续的语音活动被识别。最小语音持续时间的默认值为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
});