Audio Basic Features

adjustPlaybackSignalVolume

Adjusts the local playback volume of all remote users.

public abstract int adjustPlaybackSignalVolume(int volume);

If you need to adjust the local playback volume of a specific remote user, it is recommended to call adjustUserPlaybackSignalVolume.

Timing

You can call this method before or after joining a channel.

Parameters

volume
User volume, range [0,400]:
  • 0: Mute.
  • 100: (Default) Original volume.
  • 400: Four times the original volume (amplifies the audio signal by four times).

Return Values

  • 0: Success.
  • < 0: Failure.

adjustUserPlaybackSignalVolume

Adjusts the playback volume of a specified remote user.

public abstract int adjustUserPlaybackSignalVolume(int uid, int volume);

You can call this method to adjust the playback volume of a specified remote user. To adjust the volume for multiple remote users, call this method multiple times, once for each user.

Timing

Call this method after joining a channel.

Parameters

uid
The user ID of the remote user.
volume
User volume, range [0, 400]:
  • 0: Mute.
  • 100: (Default) Original volume.
  • 400: Four times the original volume (amplifies the audio signal by four times).

Return Values

  • 0: Success.
  • < 0: Failure.

adjustUserPlaybackSignalVolumeEx

Adjusts the playback volume of a specified remote user.

public abstract int adjustUserPlaybackSignalVolumeEx(int uid, int volume, RtcConnection connection);

You can call this method to adjust the playback volume of a specified remote user. To adjust the playback volume of multiple remote users, call this method multiple times, once for each user.

Scenario

This method applies to multi-channel scenarios.

Timing

Call this method after calling joinChannelEx.

Parameters

uid
User ID of the remote user.
volume
The volume of the user. The value range is [0, 400]:
  • 0: Mute.
  • 100: (Default) Original volume.
  • 400: Four times the original volume (amplifies the audio signal by four times).
connection
Connection information. See RtcConnection.

Return Values

  • 0: Success.
  • < 0: Failure.

disableAudio

Disables the audio module.

public abstract int disableAudio();

The audio module is enabled by default. You can call this method to disable it.

Note: This method resets the internal engine and takes some time to take effect. Agora recommends using the following APIs to control the audio module respectively:

Timing

You can call this method before or after joining a channel. It remains effective after leaving the channel.

Return Values

  • 0: Success.
  • < 0: Failure.

enableAudio

Enables the audio module.

public abstract int enableAudio();

After calling disableAudio to disable the audio module, you can call enableAudio to re-enable it.

Note:

Timing

You can call this method before or after joining a channel. It remains effective after leaving the channel.

Return Values

  • 0: Success.
  • < 0: Failure.

enableAudioVolumeIndication

Enables the reporting of user volume indications.

public abstract int enableAudioVolumeIndication(int interval, int smooth, boolean reportVad);

This method enables the SDK to periodically report the volume information of the local sending stream user and up to three remote users with the highest instantaneous volume to the app.

Timing

You can call this method before or after joining a channel.

Parameters

interval
Sets the interval (ms) between two volume indications:
  • ≤ 0: Disable volume indication.
  • > 0: Interval (ms) between two volume indications. The value must be greater than 10, otherwise the onAudioVolumeIndication callback will not be received. It is recommended to set it greater than 100.
smooth
Sets the smoothing factor for the sensitivity of volume indication. Range is 0 to 10, recommended value is 3. The higher the value, the more sensitive the indication.
reportVad
  • true: Enable voice activity detection (VAD) for the local user. When enabled, the vad parameter in the onAudioVolumeIndication callback reports the local user's voice activity status.
  • false: (Default) Disable VAD for the local user. When disabled, the vad parameter in the onAudioVolumeIndication callback does not report the local user's voice activity status unless the engine automatically detects voice activity.

Return Values

  • 0: Success.
  • < 0: Failure.

enableAudioVolumeIndicationEx

Enables reporting of user audio volume indications.

public abstract int enableAudioVolumeIndicationEx(int interval, int smooth, boolean reportVad, RtcConnection connection);

This method enables the SDK to periodically report the volume information of the local user and up to three remote users with the highest instantaneous volume.

Scenario

This method applies to multi-channel scenarios.

Timing

Call this method after calling joinChannelEx.

Parameters

interval
The time interval (ms) between volume indications:
  • ≤ 0: Disables the volume indication.
  • > 0: Interval between indications. Must be greater than 10 to receive onAudioVolumeIndication callbacks. Recommended value: > 100.
smooth
The smoothing factor for sensitivity. Range: [0, 10]. Recommended: 3. Higher values make indications more sensitive.
reportVad
Whether to enable voice activity detection (VAD) for the local user:
  • true: Enables VAD. The vad parameter in the onAudioVolumeIndication callback reports the local user's voice activity.
  • false: (Default) Disables VAD. The vad parameter does not report local voice activity unless automatically detected by the engine.
connection
Connection information. See RtcConnection.

Return Values

  • 0: Success.
  • < 0: Failure.

setAudioProfile [1/2]

Sets the audio profile and scenario.

public abstract int setAudioProfile(int profile, int scenario);
Deprecated
This method is deprecated. Use setAudioProfile(int profile) to set the audio profile and setAudioScenario(int scenario) to set the audio scenario.

Scenario

This method applies to various audio scenarios. You can choose based on your actual needs. For example, in scenarios with high audio quality requirements (such as music teaching), it is recommended to set profile to AUDIO_PROFILE_MUSIC_HIGH_QUALITY (4) and scenario to AUDIO_SCENARIO_GAME_STREAMING (3). You can call this method before or after joining a channel.

Timing

You can call this method before or after joining a channel.

Parameters

profile
Audio profile, including sampling rate, bitrate, encoding mode, and number of channels. See profile:
  • DEFAULT (0): Default.
    • Live Broadcast: 48 kHz, music encoding, mono, max bitrate 64 Kbps.
    • Communication: 32 kHz, speech encoding, mono, max bitrate 18 Kbps.
  • SPEECH_STANDARD (1): 32 kHz, speech encoding, mono, max bitrate 18 Kbps.
  • MUSIC_STANDARD (2): 48 kHz, music encoding, mono, max bitrate 64 Kbps.
  • MUSIC_STANDARD_STEREO (3): 48 kHz, music encoding, stereo, max bitrate 80 Kbps.
  • MUSIC_HIGH_QUALITY (4): 48 kHz, music encoding, mono, max bitrate 96 Kbps.
  • MUSIC_HIGH_QUALITY_STEREO (5): 48 kHz, music encoding, stereo, max bitrate 128 Kbps.
scenario
Audio scenario. Different scenarios use different volume types. See scenario:
  • AUDIO_SCENARIO_DEFAULT (0): Default automatic scenario. The SDK selects suitable audio quality based on user role and audio routing.
  • AUDIO_SCENARIO_GAME_STREAMING (3): High-quality scenario, suitable for music playback.
  • AUDIO_SCENARIO_CHATROOM (5): Chatroom scenario, suitable for frequent role switching or mute/unmute actions.
  • AUDIO_SCENARIO_CHORUS (7): Real-time chorus scenario, suitable for low-latency environments. Call getAudioDeviceInfo to check if the device supports ultra-low latency. To experience ultra-low latency, ensure isLowLatencyAudioSupported = true.
  • AUDIO_SCENARIO_MEETING (8): Meeting scenario, voice-focused.
  • AUDIO_SCENARIO_AI_CLIENT (10): AI conversation scenario, only for interaction with agents created by Conversational AI Engine.

Return Values

  • 0: Success.
  • < 0: Failure.

setAudioProfile [2/2]

Sets the audio profile.

public abstract int setAudioProfile(int profile);

If you need to set the audio scenario, call setAudioScenario, or call create and set mAudioScenario in RtcEngineConfig.

Scenario

You can choose an appropriate audio profile based on your actual needs. For example, in scenarios such as music teaching that require high audio quality, it is recommended to set profile to AUDIO_PROFILE_MUSIC_HIGH_QUALITY (4). If you need to set the audio scenario, you can call setAudioScenario, or call create [2/2] and set audioScenario in RtcEngineConfig.

Timing

You can call this method before or after joining a channel.

Parameters

profile
Audio profile, including sampling rate, bitrate, encoding mode, and number of channels:
  • DEFAULT (0): Default profile.
    • Live Broadcast: 48 kHz sampling rate, music encoding, mono, max bitrate 64 Kbps.
    • Communication: 32 kHz sampling rate, speech encoding, mono, max bitrate 18 Kbps.
  • SPEECH_STANDARD (1): 32 kHz, speech encoding, mono, max bitrate 18 Kbps.
  • MUSIC_STANDARD (2): 48 kHz, music encoding, mono, max bitrate 64 Kbps.
  • MUSIC_STANDARD_STEREO (3): 48 kHz, music encoding, stereo, max bitrate 80 Kbps.
  • MUSIC_HIGH_QUALITY (4): 48 kHz, music encoding, mono, max bitrate 96 Kbps.
  • MUSIC_HIGH_QUALITY_STEREO (5): 48 kHz, music encoding, stereo, max bitrate 128 Kbps.

Return Values

  • 0: Success.
  • < 0: Failure.

setAudioScenario

Sets the audio scenario.

public abstract int setAudioScenario(int scenario);

Scenario

This method applies to various audio scenarios. For example, in music teaching scenarios with high audio quality requirements, it is recommended to set scenario to AUDIO_SCENARIO_GAME_STREAMING (3).

Timing

You can call this method before or after joining a channel.

Parameters

scenario
Audio scenario. The device uses different volume types under different audio scenarios:
  • AUDIO_SCENARIO_DEFAULT (0): Default automatic scenario. The SDK selects the appropriate audio quality based on the user role and audio route.
  • AUDIO_SCENARIO_GAME_STREAMING (3): High-quality scenario, suitable for music playback.
  • AUDIO_SCENARIO_CHATROOM (5): Chatroom scenario, suitable for frequent role switching or muting/unmuting the microphone.
  • AUDIO_SCENARIO_CHORUS (7): Real-time chorus scenario, suitable for good network conditions and ultra-low latency requirements. Before using this enum value, you need to call getAudioDeviceInfo to check whether the audio device supports ultra-low latency capture and playback. To experience ultra-low latency, ensure the audio device supports ultra-low latency (isLowLatencyAudioSupported = true).
  • AUDIO_SCENARIO_MEETING (8): Meeting scenario, mainly for voice.
  • AUDIO_SCENARIO_AI_CLIENT (10): AI conversation scenario, only applicable when the user interacts with a conversational agent created by the Conversational AI Engine.

Return Values

  • 0: Success.
  • < 0: Failure.

onActiveSpeaker

Callback for the most active remote speaker.

public void onActiveSpeaker(int uid)
After successfully calling enableAudioVolumeIndication, the SDK continuously detects which remote user has the highest volume. The remote user with the most occurrences of highest volume within the current cycle is considered the most active speaker. When there are at least two users in the channel and an active remote speaker exists, the SDK triggers this callback and reports the user ID of the most active remote speaker.
  • If the most active remote speaker remains the same, the SDK triggers this callback only once.
  • If the most active remote speaker changes, the SDK triggers this callback again and reports the new user ID.

Trigger Timing

This callback is triggered when the most active remote speaker is detected.

Parameters

uid
User ID of the most active remote speaker.

onAudioQuality

Callback that reports statistics of the audio stream sent by each remote user.

public void onAudioQuality(int uid, int quality, short delay, short lost)
Deprecated
This method is deprecated. Use onRemoteAudioStats instead.

This callback is triggered every two seconds to report the audio quality of each remote user sending audio streams.

Parameters

uid
Remote user ID sending the audio stream.
quality
User's audio quality:
  • QUALITY_UNKNOWN (0): Unknown quality.
  • QUALITY_EXCELLENT (1): Excellent quality.
  • QUALITY_GOOD (2): Good network quality but slightly lower bitrate than excellent.
  • QUALITY_POOR (3): Slightly impaired call quality.
  • QUALITY_BAD (4): Unable to communicate smoothly.
  • QUALITY_VBAD (5): Very poor quality, almost unable to communicate.
  • QUALITY_DOWN (6): Network disconnected, completely unable to communicate.
  • QUALITY_DETECTING (8): Performing Last-mile network probe.
delay
Network delay from sender to receiver (ms), including audio sampling preprocessing, network transmission, and jitter buffer delay.
lost
Packet loss rate (%) of audio data sent from the remote user to the receiver.

onAudioVolumeIndication

Callback that reports user volume information.

public void onAudioVolumeIndication(AudioVolumeInfo[] speakers, int totalVolume)

By default, this callback is disabled. You can enable it by calling the enableAudioVolumeIndication method. Once enabled, when a user sends an audio stream in the channel, the SDK triggers this callback at the interval set in enableAudioVolumeIndication. The SDK triggers two independent onAudioVolumeIndication callbacks to report the volume information of the local user sending audio and up to three remote users with the highest instantaneous volume.

Note: After enabling this callback, the SDK continues to report the local user's volume even if muteLocalAudioStream is called to mute the local user.
  • If a remote user's volume ranks in the top three but the user stops sending audio for more than 20 seconds, this callback will no longer include that user.
  • If all remote users stop sending audio for more than 20 seconds, the SDK stops triggering the remote user volume callback.

Parameters

speakers
Volume information of users. If this array is empty, it means there are no remote users in the channel or remote users are not sending audio. See AudioVolumeInfo.
totalVolume
Speaker volume, range [0, 255].
  • For local user callback, totalVolume is the volume of the local user sending audio.
  • For remote user callback, totalVolume is the sum of volumes of up to three remote users with the highest instantaneous volume.
  • If startAudioMixing is called, totalVolume is the mixed volume.

onFirstLocalAudioFramePublished

Callback when the first local audio frame is published.

public void onFirstLocalAudioFramePublished(int elapsed)
The SDK triggers this callback when any of the following conditions are met:
  • The local client enables the audio module and successfully calls joinChannel.
  • The local client calls muteLocalAudioStream(true) and then muteLocalAudioStream(false).
  • The local client calls disableAudio and then enableAudio.
  • The local client successfully pushes audio frames to the SDK using pushExternalAudioFrame.

Trigger Timing

This callback is triggered when the first local audio frame is published.

Parameters

elapsed
Time interval (ms) from the local user calling joinChannel to the SDK triggering this callback.

onFirstRemoteAudioDecoded

Callback when the first remote audio frame is decoded.

public void onFirstRemoteAudioDecoded(int uid, int elapsed)
Deprecated
This method is deprecated. Use onRemoteAudioStateChanged instead.

Trigger Timing

This callback is triggered in the following scenarios:
  • A remote user joins the channel and sends an audio stream for the first time.
  • The remote user's audio resumes from offline to online and starts sending audio again. Possible reasons include the remote user leaving the channel, disconnecting, calling muteLocalAudioStream to stop sending audio, or calling disableAudio to disable audio.

Parameters

uid
The user ID of the remote user.
elapsed
Time (ms) from the local user calling joinChannel to the SDK triggering this callback.

onFirstRemoteAudioFrame

Callback when the first audio frame from a remote user is received.

public void onFirstRemoteAudioFrame(int uid, int elapsed) {}
Deprecated
This method is deprecated. Use onRemoteAudioStateChanged instead.

Trigger Timing

This callback is triggered when the SDK receives the first audio frame from a remote user.

Parameters

uid
The user ID of the remote user.
elapsed
Time (ms) from the local user calling joinChannel to the SDK triggering this callback.

onLocalAudioStateChanged

Callback for changes in local audio stream state.

public void onLocalAudioStateChanged(int state, int reason)

When the state of the local audio stream changes, the SDK triggers this callback to report the current state, helping you troubleshoot audio issues.

Note: When the state is LOCAL_AUDIO_STREAM_STATE_FAILED (3), you can check the error information in the error parameter.

Trigger Timing

This callback is triggered when the state of the local audio stream changes.

Parameters

state
The state of the local audio:
  • LOCAL_AUDIO_STREAM_STATE_STOPPED (0): The local audio is in the initial state.
  • LOCAL_AUDIO_STREAM_STATE_RECORDING (1): The local audio capturing device is started successfully.
  • LOCAL_AUDIO_STREAM_STATE_ENCODING (2): The first frame of audio is encoded successfully.
  • LOCAL_AUDIO_STREAM_STATE_FAILED (3): Failed to start the local audio.
reason
The reason for the local audio state change:
  • LOCAL_AUDIO_STREAM_REASON_OK (0): The local audio state is normal.
  • LOCAL_AUDIO_STREAM_REASON_FAILURE (1): The reason for local audio failure is unclear. Prompt the user to rejoin the channel.
  • LOCAL_AUDIO_STREAM_REASON_DEVICE_NO_PERMISSION (2): No permission to use the local audio capturing device. Prompt the user to grant permission.
  • LOCAL_AUDIO_STREAM_REASON_DEVICE_BUSY (3): The microphone is occupied. Prompt the user to check if another app is using the microphone. Audio capturing will automatically resume about five seconds after the microphone is free, or you can try rejoining the channel.
  • LOCAL_AUDIO_STREAM_REASON_CAPTURE_FAILURE (4): Failed to capture local audio.
  • LOCAL_AUDIO_STREAM_REASON_ENCODE_FAILURE (5): Failed to encode local audio.
  • LOCAL_AUDIO_STREAM_REASON_INTERRUPTED (8): Local audio capturing is interrupted by a system phone call, smart assistant, or alarm. To continue capturing, prompt the user to end the phone call, smart assistant, or alarm.

onLocalAudioStats

Callback for local audio stream statistics.

public void onLocalAudioStats(LocalAudioStats stats) {}

This callback is triggered every two seconds.

Trigger Timing

This callback is triggered every two seconds.

Parameters

stats
Local audio statistics. See LocalAudioStats.

onRemoteAudioStateChanged

Callback for remote audio state change.

public void onRemoteAudioStateChanged(int uid, int state, int reason, int elapsed)

This callback is triggered when the audio state of a remote user in a voice/video call channel or a host in a live broadcast channel changes, and is used to report the current state of the remote audio stream.

Note: This callback may not work properly when the number of users (communication scenario) or hosts (live broadcast scenario) in the channel exceeds 32.

Trigger Timing

This callback is triggered when the audio state of a remote user changes.

Parameters

uid
The user ID of the remote user whose audio state has changed.
state
The remote audio state:
  • REMOTE_AUDIO_STATE_STOPPED (0): The remote audio is in the initial state. The SDK reports this state when REMOTE_AUDIO_REASON_LOCAL_MUTED, REMOTE_AUDIO_REASON_REMOTE_MUTED, or REMOTE_AUDIO_REASON_REMOTE_OFFLINE occurs.
  • REMOTE_AUDIO_STATE_STARTING (1): The first packet of remote audio data is received.
  • REMOTE_AUDIO_STATE_DECODING (2): The remote audio stream is decoded and playing normally. The SDK reports this state when REMOTE_AUDIO_REASON_NETWORK_RECOVERY, REMOTE_AUDIO_REASON_LOCAL_UNMUTED, or REMOTE_AUDIO_REASON_REMOTE_UNMUTED occurs.
  • REMOTE_AUDIO_STATE_FROZEN (3): The remote audio is frozen. The SDK reports this state when REMOTE_AUDIO_REASON_NETWORK_CONGESTION occurs.
  • REMOTE_AUDIO_STATE_FAILED (4): The remote audio failed to start. The SDK reports this state when REMOTE_AUDIO_REASON_INTERNAL occurs.
reason
The reason for the remote audio state change:
  • REMOTE_AUDIO_REASON_INTERNAL (0): The SDK reports this reason when the audio state changes.
  • REMOTE_AUDIO_REASON_NETWORK_CONGESTION (1): Network congestion.
  • REMOTE_AUDIO_REASON_NETWORK_RECOVERY (2): Network recovery.
  • REMOTE_AUDIO_REASON_LOCAL_MUTED (3): The local user stops receiving the remote audio stream or disables the audio module.
  • REMOTE_AUDIO_REASON_LOCAL_UNMUTED (4): The local user resumes receiving the remote audio stream or enables the audio module.
  • REMOTE_AUDIO_REASON_REMOTE_MUTED (5): The remote user stops sending the audio stream or disables the audio module.
  • REMOTE_AUDIO_REASON_REMOTE_UNMUTED (6): The remote user resumes sending the audio stream or enables the audio module.
  • REMOTE_AUDIO_REASON_REMOTE_OFFLINE (7): The remote user leaves the channel.
elapsed
The time (ms) from the local user calling joinChannel until the SDK triggers this callback.

onRemoteAudioStats

Callback that reports transport-layer statistics of each remote audio stream.

public void onRemoteAudioStats(RemoteAudioStats stats) {}

This callback is triggered every two seconds. If there are multiple remote users in the channel, the SDK triggers this callback for each user.

Parameters

stats
Statistics of the remote audio stream. See RemoteAudioStats.

onRemoteAudioTransportStats

Reports transport-layer statistics of each remote audio stream.

public void onRemoteAudioTransportStats(int uid, int delay, int lost, int rxKBitRate)
Deprecated
This callback is deprecated. Use onRemoteAudioStats instead.

This callback reports transport-layer statistics of remote audio streams, such as packet loss rate and network delay after the local user receives audio packets from a remote user.

Trigger Timing

This callback is triggered every 2 seconds during the call when the local user receives audio packets from a remote user.

Parameters

uid
Remote user ID, i.e., the user sending the audio stream.
delay
Network delay from the remote user to the receiver, in milliseconds.
lost
Packet loss rate of audio from the remote user to the receiver, in percentage (%).
rxKBitRate
Received audio bitrate in Kbps.

onUserMuteAudio

Callback when a remote user or host stops or resumes sending audio streams.

public void onUserMuteAudio(int uid, boolean muted)

This callback is triggered when a remote user calls muteLocalAudioStream.

Note: When the number of users (in communication scenario) or hosts (in live streaming scenario) in the channel exceeds 32, this callback may not work properly.

Trigger Timing

This callback is triggered when a remote user calls muteLocalAudioStream to stop or resume sending audio streams.

Parameters

uid
Remote user ID.
muted
Whether the remote user's audio stream is muted:
  • true: Audio stream is muted.
  • false: Audio stream is not muted.