Skip to main content

You are looking at Voice Calling v3.x Docs. The newest version is  Voice Calling 4.x

Adjust the Volume

Introduction

The Agora Video SDK enables you to manage the volume of the recorded audio or of the audio playback according to your actual scenario. For example, to mute a remote user in a one-to-one call, you can set the audio playback volume as 0.

This article provides the APIs and additional information relating to audio recording, audio mixing, and audio playback volume settings.

1586770252932

Implementation

Before adjusting the audio volume, ensure that you have implemented the basic real-time communication functions in your project. For details, see Start a Voice Call or Start Live Interactive Streaming.

Adjust the recording volume

Recording is the process of sampling audio by a recording device and transmitting the recorded signal to the sender. To adjust the recording volume, you can set the volume of the recording device or set the volume of the recorded signal. Agora recommends using audio device-related APIs to adjust the recording volume on Windows and macOS devices. 1586770294896

Set the volume of the recording device (macOS and Windows only)

Call SetAudioRecordingDeviceVolume to set the volume of your recording device.

This method sets the global volume of your recording device.

The volume parameter represents the audio level of the recording device, ranging between 0 and 255:

  • 0: Mute.
  • 255: The maximum volume of the device.

As the following screenshot shows, the volume value corresponds to the audio level of your audio recording device. 1577201229190

Sample code

// Retrieves the AudioRecordingDeviceManager object.
AudioRecordingDeviceManager audioRecordingDeviceManager = (AudioRecordingDeviceManager)mRtcEngine.GetAudioRecordingDeviceManager();
// Sets the volume of your recording device as 50.
int ret = audioRecordingDeviceManager.SetAudioRecordingDeviceVolume(50);
Copy

Set the volume of the recorded signal

If SetAudioRecordingDeviceVolume does not suffice, you can call AdjustRecordingSignalVolume to set the volume of the recorded signal.

The volume parameter represents the audio level of the recorded signal, ranging between 0 and 100:

  • 0: Mute.
  • 100: (Default) The original volume.

Sample code

// Sets the volume of the recorded signal to 50.
int ret = mRtcEngine.AdjustRecordingSignalVolume(50);
Copy

API reference

Adjust the playback volume

Playback is the process of playing the received audio signal on the local playback device. To adjust the playback volume, you can set the volume of the playback device, or set the volume of the audio signal. Agora recommends using audio device-related APIs to adjust the playback volume on Windows and macOS devices. 1586770338360

Set the volume of the playback device (macOS and Windows only)

To set the volume on the playback device directly, call SetAudioPlaybackDeviceVolume.

This method sets the global volume of your playback device.

The volume parameter represents the audio level of the playback device, ranging between 0 and 255:

  • 0: Mute.
  • 255: The maximum volume of the device.

As the following screenshot shows, the volume value corresponds to the audio level of your audio playback device. 1577201545034

Sample code

// Retrieves the AudioPlaybackDeviceManager object.
AudioPlaybackDeviceManager audioPlaybackDeviceManager = (AudioPlaybackDeviceManager)mRtcEngine.GetAudioPlaybackDeviceManager();
// Sets the volume of the playback device as 50.
int ret = audioPlaybackDeviceManager.SetAudioPlaybackDeviceVolume(50);
Copy

Set the volume of the playback signal

If SetAudioPlaybackDeviceVolume does not suffice, you can use AdjustPlaybackSignalVolume to set the volume of the audio signal.

  • Universally sets the playback audio level of all remote users after audio mixing.
  • The volume parameter represents the playback audio level, ranging between 0 and 400.
As of v2.3.2, to mute the local audio playback, you must call both AdjustPlaybackSignalVolume and AdjustAudioMixingVolume, and set the volume parameter as 0.

Sample code

// Sets the volume of the local playback of all remote users as 50.
int ret = mRtcEngine.AdjustPlaybackSignalVolume(50);
Copy

API reference

Adjust the audio mixing volume

Audio mixing is the process of combining local or online music files with the local stream so that all the remote users in the channel can hear the host and the music at the same time. See Audio Effects/Mixing for more information about enabling this function. 1586770368334

The AdjustAudioMixingVolume method adjusts the volume of the music file for both the local user and the remote users.

The volume parameter represents the audio level of the music file, ranging between 0 and 100.

  • 0: Mute.
  • 100: (Default) The original volume.

Sample code

// Sets the audio mixing volume for the local user and remote users as 50.
int ret = mRtcEngine.AdjustAudioMixingVolume(50);
Copy

You can also call AdjustAudioMixingPlayoutVolume and AdjustAudioMixingPublishVolume respectively to adjust the audio mixing volume.

  • AdjustAudioMixingPlayoutVolume:
    • Adjusts the audio mixing volume for the local user.
    • The volume parameter represents the audio mixing volume for the local user, ranging between 0 and 100.
  • AdjustAudioMixingPublishVolume
    • Adjusts the audio mixing volume for the remote users.
    • The volume parameter represents the audio mixing volume for the remote users, ranging between 0 and 100.
Call AdjustAudioMixingPlayoutVolume and AdjustAudioMixingPublishVolume after joining a channel.

Sample code

// Sets the audio mixing volume of the music for the remote users as 50.
int ret = mRtcEngine.AdjustAudioMixingPublishVolume(50);
// Sets the audio mixing volume of the music for the local user as 50.
int ret = mRtcEngine.AdjustAudioMixingPlayoutVolume(50);
Copy

API reference

Adjust the audio effects volume

An audio effects here refers to a sound clip which plays a brief sound effect such as clapping or gunshots. See Audio Effects/Mixing for more information on how to enable this function.

1586770384829

You can call SetEffectsVolume or SetVolumeOfEffect to set the audio effects volume.

  • SetEffectsVolume
    • Sets the volume of all audio effects.
    • The volume parameter represents the volume of the audio effects, ranging between 0 and 100.
  • SetVolumeOfEffect
    • Sets the volume of a specified audio effect.
    • The volume parameter represents the volume of a specified audio effect, ranging between 0 and 100.

Sample code

// Retrieves the AudioEffectManagerImpl object.
AudioEffectManagerImpl audioEffectManagerImpl = (AudioEffectManagerImpl)mRtcEngine.GetAudioEffectManager();
// Sets the volume of all audio effects as 50.
int ret = audioEffectManagerImpl.SetEffectsVolume(50);
// Sets the volume of a specified audio effect as 50.
int ret = mRtcEngine.SetVolumeOfEffect(soundId, 50);
Copy

API reference

Adjust the in-ear monitoring volume (Android and iOS only)

In audio recording, mixing and playing, you can call SetInEarMonitoringVolume to adjust the volume of the in-ear monitoring.

1586770402384

The volume parameter represents the volume of the in-ear monitoring, ranging between 0 and 100.

  • 0: Mute.
  • 100: (Default) The original volume.

Sample code

// Enables in-ear monitoring.
int ret = mRtcEngine.EnableInEarMonitoring(true);
// Sets the in-ear monitoring volume as 50.
int ret = mRtcEngine.SetInEarMonitoringVolume(50);
Copy

API reference

Get the data of the loudest speaker (callback)

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 OnVolumeIndicationHandler callback reports the user IDs the corresponding volumes of the currently loudest speakers in the channel.
You must call EnableAudioVolumeIndication to be able to receive this callback.

Sample code

// Gets the user IDs of the users with the highest peak volume, the corresponding volumes, as well as whether the local user is speaking.
// @param speakers is an array containing the user IDs and volumes of the local and the remote users. The volume parameter ranges between 0 and 255.
// @param speakerNumber refers to the number of the speakers, ranging between 0 and 3.
// @param totalVolume refers to the total volume after audio mixing, ranging between 0 and 255.
void OnVolumeIndicationHandler(const AudioVolumeInfo* speakers, unsigned int speakerNumber, int totalVolume) {
}
Copy
  • Reports the user with the highest average volume. The OnActiveSpeakerHandler callback reports the user ID with the highest average volume during a certain period of time.
You must call EnableAudioVolumeIndication to be able to receive this callback.

Sample code

// Gets the user ID of the user with the highest average volume during a certain period of time.
void OnActiveSpeakerHandler(uint uid) {
}
Copy

API reference

Considerations

Setting the audio level too high may cause audio distortion on some devices.

Reference

When adjusting the audio volume, you can also refer to the following articles:

Voice Calling