Get the Raw Audio Data
Feature Overview
SDK provides developers with the ability to obtain raw audio data. The obtained raw audio data format is PCM. Developers can write this data to local devices to achieve audio recording.
Prerequisites
Before obtaining raw audio data, please ensure:
- A project has been created in ZEGOCLOUD Console, and valid AppID and AppSign have been obtained. For details, please refer to Console - Project Information.
- ZEGO Express SDK has been integrated into the project, and basic audio/video streaming functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation.
Usage Steps
1 Initialize SDK
Please refer to Quick Start - Implementation "Create Engine".
2 Get the Raw Audio Data for Local Capture Stream
Developers can call the setCaptureAudioFrameCallback interface to enable raw audio data callback monitoring. The callback parameter ZegoAudioFrame contains audio raw data (channels), number of channels (channelCount), and audio sample rate (sampleRate). When the callback function is set to null, it will stop listening to this audio data.
// Create audio stream
const localStream = await zg.createZegoStream({camera :{audio:true,video:false}});
// Get the Raw Audio Data functionality
zg.setCaptureAudioFrameCallback(
localStream,
(data) => {
// data type is { channels: Float32Array[]; channelCount: number; sampleRate: number }
}
);
// Stop audio data callback
zg.setCaptureAudioFrameCallback(localStream, null);3 Get the Raw Audio Data for Playing Stream
Developers can call the setAudioFrameCallback interface to enable raw audio data callback monitoring. The callback parameter ZegoAudioFrame contains audio raw data (channels), number of channels (channelCount), and audio sample rate (sampleRate). When the callback function is set to null, it will stop listening to this audio data.
// Play stream
const remoteStream = await zg.startPlayingStream(streamID);
// Get the Raw Audio Data functionality
zg.setAudioFrameCallback(
remoteStream,
(data) => {
// data type is { channels: Float32Array[]; channelCount: number; sampleRate: number }
}
);
// Stop audio data callback
zg.setAudioFrameCallback(streamID, null);