This tutorial mainly introduces how to detect the volume.
Detect the volume of the local microphone and remote users.
Detect whether the user is speaking after muting microphone.
Gain local microphone and remote audio volume.
Dectect Audio Volume
trtc.on(TRTC.EVENT.AUDIO_VOLUME, event => {
event.result.forEach(({ userId, volume }) => {
const isMe = userId === '';
if (isMe) {
console.log(`my volume: ${volume}`);
} else {
console.log(`user: ${userId} volume: ${volume}`);
}
})
});
trtc.enableAudioVolumeEvaluation(500);
trtc.enableAudioVolumeEvaluation(500, true);
trtc.enableAudioVolumeEvaluation(-1);
Detect Whether the User is Speaking after Muting Microphone
const trtc = TRTC.create();
await trtc.startLocalAudio();
let isAudioMuted = false;
await trtc.updateLocalAudio({ mute: true });
isAudioMuted = true;
const trtcA = TRTC.create();
trtcA.enableAudioVolumeEvaluation();
trtcA.on(TRTC.EVENT.AUDIO_VOLUME, event => {
event.result.forEach(item => {
if (item.userId === '' && item.volume > 10 && isAudioMuted) {
}
})
})
await trtcA.startLocalAudio();
Gain Audio Volume
The default local microphone capture volume is 100. You can set the captureVolume parameter of trtc.updateLocalAudio() to gain it.
await trtc.updateLocalAudio({ option: { captureVolume: 200 }});
await trtc.updateLocalAudio({ option: { captureVolume: 50 }});
await trtc.updateLocalAudio({ option: { captureVolume: 0 }});
await trtc.setRemoteAudioVolume('remote_user_id', 200);
await trtc.setRemoteAudioVolume('remote_user_id', 200);
Was this page helpful?