This page shows you how to set audio recording, audio mixing, audio playback and in-ear monitoring volume.
The Agora RTC SDK enables you to manage the volume of the recorded audio or of the audio playback according to your actual scenario. For example, you can set the audio playback volume as 0 to mute a remote user in a one-to-one call.
The following figure shows the workflow for audio volume settings.
Playback is the process of playing the received audio signal on the local playback device.
In-ear monitoring is the process of playing the audio from the recording device.
Recording is the process of sampling audio by a recording device and transmitting the recorded signal to the sender.
Before adjusting the audio volume, ensure that you have implemented the basic real-time communication functions in your project. For details, see Start a Call or Start Interactive Live Streaming.
To set the volume of the audio signal, call adjustPlaybackSignalVolume
or adjustUserPlaybackSignalVolume
.
int volume = 50;
int uid = 123456;
// Sets the playback audio level of all remote users.
mRtcEngine.adjustPlaybackSignalVolume(volume);
// Sets the playback audio level of a specified remote user, such as 123456.
mRtcEngine.adjustUserPlaybackSignalVolume(uid, volume);
In audio recording, mixing and playback, to adjust the volume of the in-ear monitor, call setInEarMonitoringVolume
.
// Enables in-ear monitoring.
rtcEngine.enableInEarMonitoring(true);
int volume = 50;
// Sets the in-ear monitoring volume.
rtcEngine.setInEarMonitoringVolume(volume);
When recording, mixing, or playing audio, you can use the following methods to get the data of the loudest speaker in the channel.
Reports users with the highest peak volumes. The onAudioVolumeIndication
callback reports the user IDs the corresponding volumes of the currently loudest speakers (at most 3) in the channel. The returned uid
is 0 for the local user.
enableAudioVolumeIndication
to be able to receive this callback. private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
...
@override
public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume) {
// Gets a list of the currently loudest speakers and the total volume
}
};
...
// Enables the onAudioVolumeIndication callback
mRtcEngine.enableAudioVolumeIndication(true);
Reports the user with the highest average volume. The onActiveSpeaker
callback reports the user ID with the highest average volume during a certain period of time. The returned uid
is 0 for the local user.
enableAudioVolumeIndication
to be able to receive this callback.
private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
@override
public void onActiveSpeaker(int uid) {
// Gets the uid of the highest average volume during a certain period of time
}
...
};
...
// Enables the onAudioVolumeIndication callback
mRtcEngine.enableAudioVolumeIndication(true);
To set the volume of the recorded signal, call adjustRecordingSignalVolume
.
ChannelMediaOptions options = new ChannelMediaOptions();
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
mRtcEngine.joinChannel(token, channelName, 1234, options);
int volume = 50;
// Sets the volume of the recorded signal.
rtcEngine.adjustRecordingSignalVolume(volume);
This section includes in depth information about the methods you used in this page, and links to related pages.
We provide an open-source AdjustVolume sample project that implements adjusting the sampling, playback, and ear-monitoring volume on GitHub. You can download the sample project and view the source code.