logo
Video Call
On this page

Get the Raw Audio Data

2024-01-02

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:

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);

Previous

Custom Audio Capture

Next

Common Video Configuration

On this page

Back to top