This page shows you how to set audio recording, audio mixing, and audio playback volume.
The Agora RTC SDK enables you to manage the volume of the recorded audio or the audio playback according to your 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 diagram shows the workflow for audio volume settings.
Playback is the process of playing the received audio signal on the local playback 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 Callor Start Interactive Live Streaming.
setDeviceVolume
. As the following screenshot shows, the volume
value corresponds to the value in the attributes of the macOS audio device. 255 corresponds to the volume value of the speaker/headset in the screenshot to the far right.// swift
// Adjust the playback volume to 50
agoraKit.setDeviceVolume(.audioPlayout, volume: 50)
// Objective-C
// Adjust the playback volume to 50
[agoraKit setDeviceVolume: AgoraMediaDeviceTypeAudioPlayout volume: 50];
To adjust the volume of the audio playback signal, call adjustPlaybackSignalVolume
or adjustUserPlaybackSignalVolume
.
// swift
// Set the playback audio level of all local remote users
agoraKit.adjustPlaybackSignalVolume(50)
// Set the playback audio level of the specified remote user
agoraKit.adjustUserPlaybackSignalVolume(uid, volume: 50)
// Objective-C
// Set the playback audio level of all local remote users
[agoraKit adjustPlaybackSignalVolume: 50];
// Set the playback audio level of the specified remote user
[agoraKit adjustUserPlaybackSignalVolume: uid, volume: 50];
When recording, mixing, or playing the audio, the reportAudioVolumeIndicationOfSpeakers
callback reports the user IDs and the corresponding volumes of the speakers that are currently the loudest (three maximum) in the channel. The returned uid
is 0 for the local user.
enableAudioVolumeIndication
to be able to receive this callback.// swift
// Get the user IDs and the corresponding volumes of the speakers that are currently the loudest (three maximum) in the channel, and whether the local user is speaking.
func rtcEngine(_ engine: AgoraRtcEngineKit, reportAudioVolumeIndicationOfSpeakers speakers:
[AgoraRtcAudioVolumeInfo], totalVolume: Int) {
}
// Objective-C
// Get the user IDs and the corresponding volumes of the speakers that are currently the loudest (three maximum) in the channel, and whether the local user is speaking.
- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportAudioVolumeIndicationOfSpeakers:(NSArray<AgoraRtcAudioVolumeInfo*> *_Nonnull) speakers totalVolume:(NSInteger)totalVolume {
}
setDeviceVolume
. As the following screenshot shows, the volume
value corresponds to the value in the attributes of the macOS audio device. 255 corresponds to the volume of the microphone in the screenshot to the far right.// swift
// Adjust the recording volume to 50
agoraKit.setDeviceVolume(.audioRecording, volume: 50)
// Objective-C
// Adjust the recording volume to 50
[agoraKit setDeviceVolume: AgoraMediaDeviceTypeAudioRecording volume: 50];
To adjust the volume of the audio recording signal, call adjustRecordingSignalVolume
.
// swift
// Adjust the volume of the audio recording signal
agoraKit.adjustRecordingSignalVolume(50)
// Objective-C
// Adjust the volume of the audio recording signal
[agoraKit adjustRecordingSignalVolume: 50];
This section includes in-depth information about the methods in this page and links to related pages.
Agora provides an open-source JoinChannelAudio sample project on GitHub that implements adjusting the sampling, playback, and ear-monitoring volume. You can download the sample project and view the source code.
When adjusting the audio volume, you can also refer to the following article: