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:
- The ZEGO Express SDK has been integrated into the project and basic real-time voice functionality has been implemented. For details, please refer to Quick Start - Integration and Quick Start - Implementation Process.
- A project has been created in the ZEGO Console and a valid AppID has been obtained.
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
| Method | Description |
|---|---|
| soundLevelUpdate | Sound level update callback |
| setSoundLevelDelegate | Set sound level callback |
