You need to enable JavaScript to run this app.
导航
美声和音频降噪
最近更新时间:2025.06.05 12:02:51首次发布时间:2024.02.05 19:50:10
我的收藏
有用
有用
无用
无用

在互动娱乐(如 KTV、语聊房、游戏语音等)场景中,引入变声、混响、降噪等音频效果,能显著提升趣味性、优化用户听觉体验,并增强互动氛围。例如,主播通过立体声或 KTV 混响效果,可以让声音更具吸引力;而精准的降噪则能保证通话质量,让沟通更清晰。

前提条件

功能实现

以下时序图以 Android SDK 中的 API 名称为例。不同端的 SDK 中 API 或回调名称可能略有不同,以 API 参考为准。

alt

1. 创建并初始化 RTC 引擎

创建和初始化一个音视频引擎类。

如果你需要获取远端的音频数据,还需要加入房间并发布音频流,参考 构建 RTC 应用 获取详细步骤。

rtcVideo = RTCVideo.createRTCVideo(this, Constants.APP_ID, rtcVideoEventHandler, null, null);

2. 开启本地音频采集

在对本地音频进行处理前,确保已开启音频采集。
rtcVideo.startAudioCapture();

3. 设置变声与混响特效

通过 setVoiceChangerTypesetVoiceReverbType 选择 RTC SDK 提供的变声和混响效果。

// 设置变声特效
rtcVideo.setVoiceChangerType(type);
// 设置混响特效
rtcVideo.setVoiceReverbType(type);

其中,PC 端使用变声特效 setVoiceChangerType 需要传入音频技术 SDK 的 Token

#ifdef  Q_OS_WINDOWS
    QJsonObject obj;
    QString sami_path = QApplication::applicationDirPath() + "/Resources/sami_effect";
    obj.insert("rtc.sami_app_key", QString::fromStdString(g_sami_key));
    obj.insert("rtc.sami_resource_path", sami_path);
    obj.insert("rtc.sami_token", QString::fromStdString(g_sami_token));

    QJsonDocument doc(obj);
    QString str = QJsonDocument(obj).toJson(QJsonDocument::Compact);
    std::string str_sami = str.toStdString();
    int ret = m_video->setRuntimeParameters(str_sami.c_str());
#endif //  Q_OS_WINDOWS

4. 自定义音调和混响效果

如果预设效果无法满足你的业务需求,你还可以通过 enableLocalVoiceReverbsetLocalVoiceReverbParam 自定义人声效果。

// 设置变调,范围 [-12,12]
rtcVideo.setLocalVoicePitch(value);

// 开启本地音效混响效果
rtcVideo.enableLocalVoiceReverb(true);
// 设置本地采集音频的混响效果
rtcVideo.setLocalVoiceReverbParam(config);

5. 设置降噪类型

您可以根据场景需求,调用 setAnsMode 来选择合适的降噪模式:

  • AI 降噪:主要是抑制非平稳噪声,比如键盘敲击声、桌椅碰撞声等。

    在 V3.57.1 之前的版本,AI 降噪功能只在特定的房间模式生效。详情,请参见AI 降噪的房间模式限制

  • 传统降噪:主要是抑制平稳噪声,比如空调声、风扇声等。
rtcVideo.setAnsMode(mode);

AI 降噪的房间模式限制

在 V3.57.1 之前的版本,调用 setAnsMode 开启 AI 降噪时,其生效条件与房间模式(RoomProfileType)相关。只有当客户端设置为以下房间模式之一时,AI 降噪才会生效:

  • 游戏语音模式:kRoomProfileTypeGame
  • 高音质游戏模式:kRoomProfileTypeGameHD
  • 云游戏模式:kRoomProfileTypeCloudGame
  • 1 vs 1 音视频通话:kRoomProfileTypeChat
  • 多端同步播放音视频:kRoomProfileTypeLwTogether
  • 云端会议中的个人设备:kRoomProfileTypeMeeting
  • 课堂互动模式:kRoomProfileTypeClassroom
  • 云端会议中的会议室终端:kRoomProfileTypeMeetingRoom

示例项目

参考以下项目获取完整代码。

API 参考

说明:表格中的 macOS API 接口为 Objective-C,而示例项目中的 macOS 项目使用的是 Windows SDK 中的 API 接口。

平台AndroidiOSmacOSWindowsLinuxElectronFlutterUnity
变声setVoiceChangerTypesetVoiceChangerType:setVoiceChangerType:setVoiceChangerTypesetVoiceChangerTypesetVoiceChangerType
预设混响特效setVoiceReverbTypesetVoiceReverbType:setVoiceReverbType:setVoiceReverbTypesetVoiceReverbTypesetVoiceReverbTypeSetVoiceReverbType
变调setLocalVoicePitchsetLocalVoicePitch:setLocalVoicePitch:setLocalVoicePitchsetLocalVoicePitchsetLocalVoicePitchsetLocalVoicePitch
开启自定义混响效果enableLocalVoiceReverbenableLocalVoiceReverb:enableLocalVoiceReverb:enableLocalVoiceReverbenableLocalVoiceReverbenableLocalVoiceReverb
设置自定义混响效果setLocalVoiceReverbParamsetLocalVoiceReverbParam:setLocalVoiceReverbParam:setLocalVoiceReverbParamsetLocalVoiceReverbParamsetLocalVoiceReverbParam
降噪setAnsModesetAnsMode:setAnsMode:setAnsModesetAnsModesetAnsModesetAnsMode

常见问题

Q:调用 setAnsMode 开启降噪后,降噪不生效或降噪效果不明显

A:如果你使用的 SDK 版本是 V3.57.1 之前的版本,确保客户端选择的房间模式为以下模式时,AI 降噪功能才能正常开启。建议升级到最新版本,可以在任意房间模式下开启 AI 降噪。