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
.
// Swift
// Sets the volume of the local playback of all remote users as 50.
agoraKit.adjustPlaybackSignalVolume(50)
// Sets the volume of the local playback of a specified remote user as 50.
agoraKit.adjustUserPlaybackSignalVolume(uid, volume: 50)
// Objective-C
// Sets the volume of the local playback of all remote users as 50.
[agoraKit adjustPlaybackSignalVolume: 50];
// Sets the volume of the local playback of a specified remote user as 50.
[agoraKit adjustUserPlaybackSignalVolume: uid, volume: 50];
In audio recording, mixing, and playback, to adjust the volume of the in-ear monitor, call setInEarMonitoringVolume
.
enableInEarMonitoring(true)
before calling this method.// Swift
// Enables in-ear monitoring.
agoraKit.enableInearMonitoring(true)
// Sets the in-ear monitor volume as 50.
agoraKit.setInEarMonitoringVolume(50)
// Objective-C
// Enables in-ear monitoring.
[agoraKit enableInEarMonitoring(true)];
// Sets the in-ear monitor volume as 50.
[agoraKit setInEarMonitoringVolume: 50];
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 reportAudioVolumeIndicationOfSpeakers
callback reports the user IDs the corresponding volumes of the currently loudest speakers in the channel. The returned uid
is 0 for the local user.
// Swift
// Gets the the user IDs of the users with the highest peak volume, the corresponding volumes, as well as whether the local user is speaking.
func rtcEngine(_ engine: AgoraRtcEngineKit, reportAudioVolumeIndicationOfSpeakers speakers:
[AgoraRtcAudioVolumeInfo], totalVolume: Int) {
}
// Objective-C
// Gets the the user IDs of the users with the highest peak volume, the corresponding volumes, as well as whether the local user is speaking.
- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine reportAudioVolumeIndicationOfSpeakers:(NSArray<AgoraRtcAudioVolumeInfo*> *_Nonnull)speakers totalVolume:(NSInteger)totalVolume {
}
Reports the user with the highest average volume. The activeSpeaker
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.
// Swift
// Gets the user ID of the user with the highest average volume during a certain period of time.
func rtcEngine(_ engine: AgoraRtcEngineKit, activeSpeaker speakerUid: UInt) {
}
// Objective-C
// Gets the user ID of the user with the highest average volume during a certain period of time.
- (void)rtcEngine:(AgoraRtcEngineKit *_Nonnull)engine activeSpeaker:(NSUInteger)speakerUid {
}
Call adjustRecordingSignalVolume
to set the volume of the recorded signal.
// Swift
// Sets the volume of the recorded signal as 50.
agoraKit.adjustRecordingSignalVolume(50)
// Objective-C
// Sets the volume of the recording signal as 50.
[agoraKit adjustRecordingSignalVolume: 50];
This section includes in depth information about the methods you used in this page, and links to related pages.
We provide an open-source JoinChannelAudio sample project that implements adjusting the recording, playback, and ear-monitoring volume on GitHub. You can download the sample project and view the source code.
When adjusting the audio volume, you can also refer to the following articles: