声学回声消除
Streaming Sound Wave 及其派生类型,如 Capturable Sound Wave,支持声学回声消除 (AEC)。AEC 可消除因回放渲染信号(例如通过扬声器播放的音频)而导致的麦克风捕捉音频中的回声。结果是在实时通信场景中获得更清晰的语音捕获。
该插件通过 WebRTC AEC3 实现提供 AEC,它作为一个轻量级扩展插件提供,仅包含相关的 AEC3 代码。WebRTC AEC3 是一种高质量的回声消除器,广泛应用于实时通信应用程序中。它模拟扬声器和麦克风之间的声学路径,以从捕获的信号中减去回声。
安装
要使用声学回声消除,您需要安装 WebRTC AEC3 扩展插件:
- 确保项目中已安装 Runtime Audio Importer 插件
- 从此处下载 WebRTC AEC3 扩展插件
- 将下载的压缩包中的文件夹解压到项目的
Plugins文件夹中(如该文件夹不存在,则创建它) - 重新构建项目(此扩展需要 C++ 项目)
- WebRTC AEC3 支持 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)
- 此扩展以源代码形式提供,使用时需要 C++ 项目
- WebRTC AEC3 可用于 Windows、Linux、Mac、Android(包括 Meta Quest)和 iOS
- 有关如何手动构建插件的更多信息,请参阅构建插件教程
基本用法
典型的 AEC 工作流程包含三个步骤:
- 在您的流式/可捕获 Sound Wave 上启用 AEC
- 在渲染 Sound Wave 上配置渲染块大小以实现 10 毫秒帧传输
- 绑定渲染 Sound Wave,其音频将用于消除捕获信号中的回声
启用 AEC
在创建流式 Sound Wave 后启用 AEC,请使用 ToggleAEC 函数。您必须为 AEC 处理器指定采样率和声道数。如果传入的捕获或渲染音频与这些值不匹配,它将自动重采样,然而,配置的采样率仍然会影响质量(例如,48000 Hz 的回声消除效果会优于 16000 Hz)和性能,因此值得特意选择这些值,而不是依赖重采样。
- Blueprint
- C++

// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
StreamingSoundWave->ToggleAEC(true, 48000, 1);
您可以检查当前是否已启用 AEC:
- Blueprint
- C++

// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
bool bEnabled = StreamingSoundWave->IsAECEnabled();
配置渲染块大小
WebRTC AEC3 要求音频以 10 毫秒的块 进行处理。为了确保渲染声音波形以正确的帧大小提供音频数据,请在 渲染 Imported Sound Wave(通过扬声器播放的声音波形)上使用 SetNumSamplesPerChunk 函数。
计算每个块正确样本数的公式如下:
例如,对于 48000 Hz 音频:每个块 48000 / 100 = 480 个样本。
- Blueprint
- C++

// Assuming ImportedSoundWave is a UE reference to a UImportedSoundWave object (the render sound wave being played through speakers)
ImportedSoundWave->SetNumSamplesPerChunk(ImportedSoundWave->GetSampleRate() / 100);
绑定渲染声波
启用声学回声消除 (AEC) 并配置块大小后,绑定用于从采集信号中识别并消除回声的渲染声波。这通常是通过扬声器播放的、麦克风可能拾取的声波:
- Blueprint
- C++

// Assuming StreamingSoundWave is the capture sound wave (microphone input) with AEC enabled
// (can also be a UCapturableSoundWave, which is the most common use case)
// Assuming ImportedSoundWave is the render sound wave being played through speakers
StreamingSoundWave->BindAECToSoundWavePlayback(ImportedSoundWave);
要解绑渲染声波:
- Blueprint
- C++

// Assuming StreamingSoundWave is the capture sound wave (microphone input) with AEC enabled
// (can also be a UCapturableSoundWave, which is the most common use case)
// Assuming ImportedSoundWave is the render sound wave being played through speakers
StreamingSoundWave->UnbindAECFromSoundWavePlayback(ImportedSoundWave);
附加配置
流延迟
你可以设置预估的流延迟(以毫秒为单位),介于渲染和捕获音频路径之间。这考虑到了硬件和系统延迟,不过在许多情况下 WebRTC AEC3 可以自动估算该延迟:
- Blueprint
- C++

// Assuming StreamingSoundWave is a UE reference to a UStreamingSoundWave object (or its derived type, such as UCapturableSoundWave)
StreamingSoundWave->SetAECStreamDelay(50);
重置 AEC
您可以在任何时候重置内部 AEC 处理器状态,清除任何累积的回声模型:
- Blueprint
- C++

StreamingSoundWave->ResetAEC();
WebRTC AEC3 支持 8000、16000、32000 和 48000 Hz 的采样率。不匹配的音频会自动重新采样,但这会带来性能开销。为了获得最佳质量和性能,请使用 48000 Hz 并匹配捕获流和渲染流的实际音频配置。