logo
Live Streaming
On this page

Custom Audio Capture and Rendering

2024-02-27

Feature Introduction

Custom audio capture

In the following scenarios, it is recommended to use the custom audio capture feature:

  • Developers need to obtain captured input from existing audio streams, audio files, or customized capture systems and hand it over to the SDK for transmission.
  • Developers have their own requirements for special sound effect processing on PCM input sources, and after sound effect processing, hand it over to the SDK for transmission.

Custom audio rendering

When developers have their own rendering requirements, such as performing special applications or processing on the captured raw PCM data before rendering, it is recommended to use the SDK's custom audio rendering feature.

Warning

Audio capture and rendering are divided into 3 situations:

  • Internal capture, internal rendering
  • Custom capture, custom rendering
  • Custom capture, internal rendering

Please choose the appropriate audio capture and rendering method according to your business scenario.

Sample Source Code Download

Please refer to Download Sample Source Code to get the source code.

For related source code, please check the files in the "/ZegoExpressExample/Examples/AdvancedAudioProcessing/CustomAudioCaptureAndRendering" directory.

Prerequisites

Before implementing custom audio capture and rendering, please ensure:

Usage Steps

The following figure shows the API interface call sequence diagram:

1 Initialize SDK

Please refer to "Create Engine" in Quick Start - Implementation Flow.

2 Enable custom audio capture rendering

You can call ZegoCustomAudioConfig to set sourceType = ZegoAudioSourceTypeCustom, and then call the enableCustomAudioIO interface to enable custom audio IO functionality.

// Set audio source to custom capture and rendering
ZegoCustomAudioConfig *audioConfig = [[ZegoCustomAudioConfig alloc] init];
audioConfig.sourceType = ZegoAudioSourceTypeCustom;

[[ZegoExpressEngine sharedEngine] enableCustomAudioIO:YES config:audioConfig];

3 Login room and then publish/play streams

Please refer to "Login Room", "Publish Stream", and "Playing Stream" in Quick Start - Implementation Flow.

4 Capture audio data

Open the audio capture device and pass the captured audio data to the engine through sendCustomAudioCaptureAACData or sendCustomAudioCapturePCMData.

5 Render audio data

Open the audio rendering device, use fetchCustomAudioRenderPCMData to get audio data from the engine, and then play it through the rendering device after getting the audio data.

FAQ

  1. Timing for calling custom audio capture rendering related interfaces?

  2. Frequency for calling custom audio capture rendering related interfaces?

    The optimal way is to drive according to the clock of the physical audio device, call sendCustomAudioCaptureAACData and sendCustomAudioCapturePCMData when the physical capture device captures data; call fetchCustomAudioRenderPCMData when the physical rendering device needs data.

    If there is no specific physical device to drive in the actual scenario, it is recommended to call the above interfaces once every 10 ms ~ 20 ms.

  3. When calling fetchCustomAudioRenderPCMData, if the SDK internal data is less than "dataLength", how does the SDK handle it?

    In the case that "param" is filled in normally, when the SDK internal data is less than "dataLength", the remaining insufficient length is filled with silent data.

Previous

Scenario-based AI Noise Reduction

Next

Custom Audio Processing