The default Agora audio module interacts seamlessly with the devices your app runs on. The SDK enables you to add specialized audio features to your app using a custom audio source.!
By default, SDK integrates the default audio modules on the device your app runs on for real-time communication. However, there are scenarios where you may want to integrate a custom audio capturer. For example:
To manage the capture and processing of audio frames when using a custom audio source, use methods from outside the Agora SDK.
The API call sequence is as follows:
When customizing the audio source, you need to record and process the audio data on your own.
Before adjusting the audio volume, ensure that you have implemented the basic real-time communication functions in your project. For details, see the following quickstart guides:
To implement a custom audio source in your project, refer to the following steps.
Before joining a channel, call setExternalAudioSource
to notify the SDK to use the external audio source.
agoraKit.setExternalAudioSource(true, sampleRate: Int(sampleRate), channels: Int(channel), sourceNumber: 1, localPlayback: true, publish: true)
Record and process the audio data on your own.
Send the audio data back to the SDK using pushExternalAudioFrameSampleBuffer
, or pushExternalAudioFrameNSData
.
extension CustomPcmAudioSourceMain: AgoraPcmSourcePushDelegate {
func onAudioFrame(data: Data) {
agoraKit.pushExternalAudioFrameNSData(data, sourceId: 0, timestamp: 0)
}
}
This section includes in depth information about the methods you used in this page, and links to related pages.
Agora provides the following open-sourced sample projects that implement custom audio source functions: