볼륨
본 튜토리얼은 주로 볼륨을 감지하는 방법을 소개합니다.
로컬 마이크와 원격 사용자의 볼륨을 감지합니다.
마이크 음소거된 후 사용자가 말하고 있는지 여부를 감지합니다.
로컬 마이크와 원격 볼륨을 조절합니다.
오디오 볼륨 감지
TRTC.EVENT.AUDIO_VOLUME 이벤트를 모니터링하고, 그 다음 trtc.enableAudioVolumeEvaluation()를 호출하여 볼륨 콜백 이벤트를 활성화합니다.
trtc.on(TRTC.EVENT.AUDIO_VOLUME, event => {event.result.forEach(({ userId, volume }) => {// When userId is an empty string, it represents the volume of the local microphone.const isMe = userId === '';if (isMe) {console.log(`my volume: ${volume}`);} else {console.log(`user: ${userId} volume: ${volume}`);}})});// Enable volume event and trigger the event every 500mstrtc.enableAudioVolumeEvaluation(500);// For performance reasons, when the page switches to the background,// the SDK will not throw volume callback events. If you need to receive volume event// when the page is switched to the background, you can set the second parameter to true.trtc.enableAudioVolumeEvaluation(500, true);// To turn off the volume event, pass in an value less than or equal to 0trtc.enableAudioVolumeEvaluation(-1);
마이크 음소거된 후 사용자가 말을 하는지 여부를 감지
const trtc = TRTC.create();await trtc.startLocalAudio();let isAudioMuted = false;await trtc.updateLocalAudio({ mute: true });isAudioMuted = true;// create a new trtc instance for detecting the volume of microphone.const trtcA = TRTC.create();trtcA.enableAudioVolumeEvaluation();trtcA.on(TRTC.EVENT.AUDIO_VOLUME, event => {event.result.forEach(item => {// 1. userId === '' is local volume.// 2. It is generally believed that when the volume is greater than 10, the user is talking, and you can also customize this threshold.if (item.userId === '' && item.volume > 10 && isAudioMuted) {// The user is speaking after microphone muted.}})})await trtcA.startLocalAudio();
오디오 볼륨 조정
// Increase the capture volume by setting captureVolume upper than 100.await trtc.updateLocalAudio({ option: { captureVolume: 200 }});// Decrease the capture volume by setting captureVolume below 100.await trtc.updateLocalAudio({ option: { captureVolume: 50 }});await trtc.updateLocalAudio({ option: { captureVolume: 0 }});
// Increase remote audio volumeawait trtc.setRemoteAudioVolume('remote_user_id', 200);// Decrease remote audio volumeawait trtc.setRemoteAudioVolume('remote_user_id', 50);