logo
On this page

Audio Spectrum and Sound Level


Feature Introduction

Sound Level: Refers to the volume of a specific stream, hereinafter referred to as "Sound Level".

In Karaoke scenarios, it is often necessary to pull multiple streams and display which users are speaking. ZEGO provides the ability to identify whether users are speaking and their speaking volume (Sound Level), facilitating UI display for developers. For example:

Download Sample Source Code

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

For related source code, please check the "src/common.js" file.

Prerequisites

Before implementing the Sound Level feature, please ensure:

Usage Steps

Listen for Sound Level Callback

Register the soundLevelUpdate callback to receive stream sound level changes.

zg.on('soundLevelUpdate', (streamList) => {
    streamList.forEach(stream => {
        stream.type == 'push' && $('#soundLevel').html(Math.round(stream.soundLevel) + '');
        console.warn(`${stream.type} ${stream.streamID}, soundLevel: ${stream.soundLevel}`);
    });
});

Start Sound Level Monitoring

Call the setSoundLevelDelegate interface to start monitoring sound levels and set the sound level callback interval.

zg.setSoundLevelDelegate(true, 1000);

Stop Sound Level Monitoring

Call the setSoundLevelDelegate interface to stop monitoring sound levels.

zg.setSoundLevelDelegate(false);

API Reference List

MethodDescription
soundLevelUpdateSound level update callback
setSoundLevelDelegateSet sound level callback

Previous

Real-time Messaging and Signaling

Next

Ear Monitor and Channel Settings

On this page

Back to top