Audio Features
Audio Basic Features
adjustPlaybackSignalVolume
Adjusts the local playback volume of all remote users.
virtual int adjustPlaybackSignalVolume(int volume) = 0;
If you want to adjust the local playback volume of a specific remote user, it is recommended to call the adjustUserPlaybackSignalVolume method.
Timing
This method can be called before or after joining a channel.
Parameters
- volume
- The user's 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 signal volume of a specified remote user.
virtual int adjustUserPlaybackSignalVolume(uid_t uid, int volume) = 0;
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.
Timing
Call this method after joining the channel.
Parameters
- uid
- The user ID of the remote user.
- volume
- The user's volume. The range is [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 signal volume of a specified remote user.
virtual int adjustUserPlaybackSignalVolumeEx(uid_t uid, int volume, const RtcConnection& connection) = 0;
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
- Remote user ID.
- volume
- User volume. Range: [0, 400]:
- 0: Mute.
- 100: (Default) Original volume.
- 400: Four times the original volume (amplifies audio signal fourfold).
- connection
- Connection information. See RtcConnection.
Return Values
- 0: Success.
- < 0: Failure.
disableAudio
Disables the audio module.
virtual int disableAudio() = 0;
- enableLocalAudio: Enables or disables the microphone to create a local audio stream.
- enableLoopbackRecording: Enables or disables loopback audio capture.
- muteLocalAudioStream: Publishes or stops publishing the local audio stream.
- muteRemoteAudioStream: Subscribes to or unsubscribes from and plays remote audio streams.
- muteAllRemoteAudioStreams: Subscribes to or unsubscribes from and plays all remote audio streams.
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.
virtual int enableAudio() = 0;
The audio module is enabled by default. After calling disableAudio to disable it, you can call this method to re-enable it.
- enableLocalAudio: Whether to enable the microphone to create a local audio stream.
- muteLocalAudioStream: Whether to publish the local audio stream.
- muteRemoteAudioStream: Whether to subscribe to and play a remote audio stream.
- muteAllRemoteAudioStreams: Whether to subscribe to and play all remote audio streams.
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 audio volume indication reporting.
virtual int enableAudioVolumeIndication(int interval, int smooth, bool reportVad) = 0;
This method enables the SDK to periodically report the volume information of the local user who sends the audio stream and up to three remote users with the highest instantaneous volume.
Timing
You can call this method before or after joining a channel.
Parameters
- interval
- The time interval (ms) between two volume indications:
- ≤ 0: Disables the volume indication.
- > 0: The interval in milliseconds. Must be greater than 10 to receive the onAudioVolumeIndication callback. A value greater than 100 is recommended.
- smooth
- The smoothing factor of the volume indication. The range is 0 to 10. The recommended value is 3. The higher the value, the more sensitive the indication.
- reportVad
- Whether to enable the voice activity detection (VAD) of the local user:
- true: Enables VAD. The
vadparameter in the onAudioVolumeIndication callback reports the local user's voice activity status. - false: (Default) Disables VAD. The
vadparameter in the onAudioVolumeIndication callback does not report the local user's voice activity status unless the engine detects voice activity automatically.
- true: Enables VAD. The
Return Values
- 0: Success.
- < 0: Failure.
enableAudioVolumeIndicationEx
Enables the reporting of user volume indications.
virtual int enableAudioVolumeIndicationEx(int interval, int smooth, bool reportVad, const RtcConnection& connection) = 0;
This method enables the SDK to periodically report the volume information of the local user who sends the audio stream 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
- Sets the time interval (ms) between two volume indications:
- ≤ 0: Disables volume indication.
- > 0: The time interval (ms) between two volume indications. This value must be greater than 10; otherwise, you will not receive the onAudioVolumeIndication callback. A value greater than 100 is recommended.
- smooth
- Sets the smoothing factor of the volume indication. The range is [0,10], and the recommended value is 3. The larger the value, the more sensitive the indication.
- reportVad
- Whether to enable voice activity detection (VAD) for the local user:
- true: Enable VAD. The
vadparameter in the onAudioVolumeIndication callback reports the voice activity status of the local user. - false: (Default) Disable VAD. The
vadparameter in the onAudioVolumeIndication callback does not report the voice activity status of the local user unless the engine automatically detects voice activity.
- true: Enable VAD. The
- connection
- Connection information. See RtcConnection.
Return Values
- 0: Success.
- < 0: Failure.
setAudioProfile [1/2]
Sets the audio profile and scenario.
virtual int setAudioProfile(AUDIO_PROFILE_TYPE profile, AUDIO_SCENARIO_TYPE scenario) __deprecated = 0;
- Deprecated
- This method is deprecated. You can use setAudioProfile [2/2] instead. To set the audio scenario, call the initialize method and pass the value in the
audioScenariomember of the RtcEngineContext struct.
AUDIO_SCENARIO_GAME_STREAMING (3). In this scenario, the SDK switches to media volume to avoid this issue.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.
Parameters
- profile
- Audio profile, including sample rate, bitrate, encoding mode, and number of channels. See AUDIO_PROFILE_TYPE.
- scenario
- Audio scenario. Different scenarios use different volume types. See AUDIO_SCENARIO_TYPE.
Return Values
- 0: Success.
- < 0: Failure.
setAudioProfile [2/2]
Sets the audio profile.
virtual int setAudioProfile(AUDIO_PROFILE_TYPE profile) = 0;
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 initialize and set audioScenario in RtcEngineContext.
Timing
You can call this method before or after joining a channel.
Parameters
- profile
- Audio profile, including sample rate, bitrate, encoding mode, and number of channels. See AUDIO_PROFILE_TYPE.
Return Values
- 0: Success.
- < 0: Failure.
setAudioScenario
Sets the audio scenario.
virtual int setAudioScenario(AUDIO_SCENARIO_TYPE scenario) = 0;
AUDIO_SCENARIO_GAME_STREAMING (3). In this scenario, the SDK switches to media volume to avoid this issue.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. Devices use different volume types under different scenarios. See AUDIO_SCENARIO_TYPE.
Return Values
- 0: Success.
- < 0: Failure.
setAudioSessionOperationRestriction
Sets the SDK's permission to operate the audio session.
virtual int setAudioSessionOperationRestriction(AUDIO_SESSION_OPERATION_RESTRICTION restriction) = 0;
By default, both the SDK and the app can configure the audio session. If you want only the app to configure it, you can restrict the SDK's permission by calling this method. You can call it before or after joining a channel. Once restricted, the SDK will be limited when attempting to change the audio session.
- This method is only applicable on iOS.
- This method does not restrict the app's permission to operate the audio session.
Parameters
- restriction
- The SDK's permission to operate the audio session. This parameter is a bitmask, with each bit representing a permission. See AUDIO_SESSION_OPERATION_RESTRICTION.
Return Values
- 0: Success.
- < 0: Failure.
onActiveSpeaker
Callback for the most active remote speaker.
virtual void onActiveSpeaker(uid_t uid)
- If the most active speaker remains the same, the SDK triggers this callback only once.
- If the most active speaker changes, the SDK triggers this callback again and reports the new most active speaker's user ID.
Parameters
- uid
- The user ID of the most active remote speaker.
onAudioQuality
Reports statistics of audio streams sent by each remote user.
virtual void onAudioQuality(uid_t uid, int quality, unsigned short delay, unsigned short lost) __deprecated
- Deprecated
- This callback is deprecated. Use onRemoteAudioStats instead.
The SDK triggers this callback every two seconds to report the audio quality of each remote user sending audio streams. If multiple users send audio streams in the channel, the SDK triggers this callback multiple times.
Parameters
- uid
- User ID of the remote user sending the audio stream.
- quality
- Audio quality of the user. See QUALITY_TYPE.
- delay
- Network delay (ms) from sender to receiver, including audio sampling pre-processing, network transmission, and jitter buffering.
- lost
- Audio packet loss rate (%) from the remote user to the receiver.
onAudioVolumeIndication
onAudioVolumeIndication callback.
virtual void onAudioVolumeIndication(const AudioVolumeInfo* speakers, unsigned int speakerNumber, int totalVolume)
By default, this callback is disabled. You can enable it by calling enableAudioVolumeIndication. Once enabled, when users in the channel send audio streams, the SDK triggers this callback at the interval set in enableAudioVolumeIndication. The SDK triggers two separate onAudioVolumeIndication callbacks: one for the local user sending audio and one for up to three remote users with the highest instantaneous volume.
Trigger Timing
Triggered when audio volume indication is enabled and users are sending audio streams.
Parameters
- speakers
- Volume information of users. See AudioVolumeInfo. If the
speakersarray is empty, it means there are no remote users or no users are sending audio streams. - speakerNumber
- Total number of users.
- In the local user's callback, if the local user is sending audio,
speakerNumberis 1. - In the remote users' callback,
speakerNumberranges from 0 to 3. If there are three or more remote users sending audio,speakerNumberis 3.
- In the local user's callback, if the local user is sending audio,
- totalVolume
- Volume of the speaker, ranging from 0 to 255.
- In the local user's callback,
totalVolumeis the local user's volume. - In the remote users' callback,
totalVolumeis the sum of the volumes of up to three remote users with the highest instantaneous volume. IfstartAudioMixingis called, this value is the mixed audio volume.
- In the local user's callback,
onFirstLocalAudioFramePublished
Callback triggered when the local user publishes the first audio frame.
virtual void onFirstLocalAudioFramePublished(int elapsed)
Trigger Timing
- The local client enables the audio module and successfully calls
joinChannel. - The local client calls
muteLocalAudioStream(true)followed bymuteLocalAudioStream(false). - The local client calls disableAudio followed by enableAudio.
- The local client successfully pushes audio frames to the SDK using pushAudioFrame.
Parameters
- elapsed
- Time elapsed (ms) from the local user calling
joinChannelto the SDK triggering this callback.
onFirstRemoteAudioDecoded
Callback when the first remote audio frame is decoded.
virtual void onFirstRemoteAudioDecoded(uid_t uid, int elapsed) __deprecated
- Deprecated
- This method is deprecated. Use onRemoteAudioStateChanged instead.
Trigger Timing
Triggered when a remote user sends an audio stream for the first time, or when the audio recovers from offline to online and starts sending again.
Parameters
- uid
- Remote user ID.
- elapsed
- Time in milliseconds from the local user calling
joinChannelto the SDK triggering this callback.
onFirstRemoteAudioFrame
Callback when the first audio frame from a remote user arrives.
virtual void onFirstRemoteAudioFrame(uid_t uid, int elapsed) __deprecated
- Deprecated
- This method is deprecated. Use onRemoteAudioStateChanged instead.
Parameters
- uid
- Remote user ID.
- elapsed
- Time in milliseconds from the local user calling
joinChannelto the SDK triggering this callback.
onLocalAudioStateChanged
Callback for changes in the local audio stream state.
virtual void onLocalAudioStateChanged(LOCAL_AUDIO_STREAM_STATE state, LOCAL_AUDIO_STREAM_REASON reason)
When the state of the local audio stream (including audio capture and encoding state) changes, the SDK triggers this callback to report the current state, helping you troubleshoot audio issues.
LOCAL_AUDIO_STREAM_STATE_FAILED (3), you can check the error information in the reason parameter.Parameters
- state
- The state of the local audio stream. See LOCAL_AUDIO_STREAM_STATE.
- reason
- The reason for the local audio stream state change. See LOCAL_AUDIO_STREAM_REASON.
onLocalAudioStats
Callback for local audio statistics.
virtual void onLocalAudioStats(const LocalAudioStats& stats)
Trigger Timing
The SDK triggers this callback every two seconds.
Parameters
- stats
- Local audio statistics. See LocalAudioStats.
onRemoteAudioStateChanged
Callback for changes in the remote audio state.
virtual void onRemoteAudioStateChanged(uid_t uid, REMOTE_AUDIO_STATE state, REMOTE_AUDIO_STATE_REASON reason, int elapsed)
Trigger Timing
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. See REMOTE_AUDIO_STATE.
- reason
- The reason for the remote audio state change. See REMOTE_AUDIO_STATE_REASON.
- elapsed
- The time (ms) elapsed from the local user calling
joinChannelto the SDK triggering this callback.
onRemoteAudioStats
Callback for remote audio stream statistics.
virtual void onRemoteAudioStats(const RemoteAudioStats& stats)
This callback is triggered every two seconds to report transport-layer statistics for each remote user sending an audio stream. If there are multiple remote users in the channel, the SDK triggers this callback separately for each user.
Parameters
- stats
- Statistics of the remote audio stream. See RemoteAudioStats.
onRemoteAudioTransportStats
Callback to report transport layer statistics for each remote audio stream.
virtual void onRemoteAudioTransportStats(uid_t uid, unsigned short delay, unsigned short lost, unsigned short rxKBitRate) __deprecated
- Deprecated
- This method is deprecated. Use onRemoteAudioStats instead.
This callback reports transport layer statistics, such as packet loss rate and network delay after the local user receives audio packets from a remote user. It is triggered every 2 seconds during a call.
Trigger Timing
During a call, triggered every 2 seconds 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 (ms) from the remote user to the local receiver.
- lost
- Audio packet loss rate (%) from the remote user to the local receiver.
- rxKBitRate
- Received audio bitrate (Kbps).
onUserMuteAudio
Callback for remote user or host stopping or resuming audio stream.
virtual void onUserMuteAudio(uid_t uid, bool muted)
This callback is triggered when the remote user calls muteLocalAudioStream to stop or resume sending the audio stream.
Parameters
- uid
- The remote user ID.
- muted
- Whether the remote user's audio stream is muted:
- true: The audio stream is muted.
- false: The audio stream is not muted.
Audio Capture
adjustLoopbackSignalVolume
Adjusts the volume of the loopback recording signal.
virtual int adjustLoopbackSignalVolume(int volume) = 0;
After calling enableLoopbackRecording to enable loopback audio capture, you can call this method to adjust the volume of the loopback signal.
Parameters
- volume
- The mixing volume. The range is [0, 100]. (The default is 100, which means original volume.)
Return Values
- 0: Success.
- < 0: Failure.
adjustRecordingSignalVolume
Adjusts the volume of the recorded audio signal.
virtual int adjustRecordingSignalVolume(int volume) = 0;
If you only need to mute the audio signal, Agora recommends using the muteRecordingSignal method.
Timing
This method can be called before or after joining a channel.
Parameters
- volume
- The user's 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.
enableInEarMonitoring
Enables or disables in-ear monitoring.
virtual int enableInEarMonitoring(bool enabled, int includeAudioFilters) = 0;
Timing
You can call this method before or after joining the channel.
Parameters
- enabled
- Whether to enable in-ear monitoring.
Note:
- true: Enable in-ear monitoring.
- false: (Default) Disable in-ear monitoring.
- includeAudioFilters
- The type of audio filter used for in-ear monitoring. See EAR_MONITORING_FILTER_TYPE.
Return Values
- 0: Success.
- < 0: Failure.
- -8: Please ensure the current audio route is Bluetooth or wired headset.
enableLocalAudio
Enables or disables local audio capture.
virtual int enableLocalAudio(bool enabled) = 0;
- enableLocalAudio: Disables or re-enables local audio capture and processing. If you disable or re-enable local audio capture using this method, the local user may hear an interruption in remote audio playback.
- muteLocalAudioStream: Only stops or resumes sending the local audio stream without affecting the audio capture state.
enabled to false is suitable for scenarios where you only want to receive remote audio streams without sending local audio.You can call this method before or after joining a channel. If called before joining, it only sets the device state and takes effect immediately after joining.Scenario
enableLocalAudio(false) is suitable for scenarios where only remote audio streams are received without sending locally captured audio. This method does not affect receiving remote audio streams.
Timing
You can call this method before or after joining a channel. If called before joining, it only sets the device state and takes effect immediately after joining.
Parameters
- enabled
- Whether to enable local audio capture:
- true: (Default) Re-enables the local audio function, i.e., starts the local audio capture device (e.g., microphone).
- false: Disables the local audio function, i.e., stops local audio capture.
Return Values
- 0: Success.
- < 0: Failure.
enableLoopbackRecording
Enables loopback recording using the sound card.
virtual int enableLoopbackRecording(bool enabled, const char* deviceName = NULL) = 0;
After enabling this feature, the output audio from the sound card will be mixed into the audio stream sent to the remote user.
- This method is only applicable to macOS and Windows platforms.
- You can call this method before or after joining the channel.
- If you have called disableAudio to disable the audio module, audio capture will also be disabled. To enable audio capture, call enableAudio first, then call enableLoopbackRecording.
Parameters
- enabled
- Whether to enable loopback recording:
- true: Enable loopback recording. You can view the virtual sound card name in the system audio device > output.
- false: Disable loopback recording. The virtual sound card name will not appear in the system audio device > output.
- deviceName
-
- macOS: The device name of the virtual sound card. The default is NULL, which uses
AgoraALDfor loopback recording. - Windows: The device name of the sound card. The default is NULL, which means the SDK uses your device's sound card for loopback recording.
- macOS: The device name of the virtual sound card. The default is NULL, which uses
Return Values
- 0: Success.
- < 0: Failure.
enableLoopbackRecordingEx
Enables loopback recording, mixing the sound card output into the audio stream sent.
virtual int enableLoopbackRecordingEx(const RtcConnection& connection, bool enabled, const char* deviceName = NULL) = 0;
After enabling this feature, the sound card output is mixed into the audio stream sent to remote users.
- This method is only applicable to macOS and Windows.
- macOS does not support loopback recording from the default sound card. To use this feature, use a virtual sound card and pass its name to the
deviceNameparameter.AgoraALDis recommended as the virtual sound card. - This method supports only one sound card for audio capture.
Scenario
This method applies to multi-channel scenarios.
Parameters
- connection
- Connection information. See RtcConnection.
- enabled
- Whether to enable loopback recording:
- true: Enable loopback recording.
- false: (Default) Disable loopback recording.
- deviceName
-
- macOS: Name of the virtual sound card. Default is NULL, which uses
AgoraALDfor loopback recording. - Windows: Name of the sound card. Default is NULL, which uses the current device's sound card for recording.
- macOS: Name of the virtual sound card. Default is NULL, which uses
Return Values
- 0: Success.
- < 0: Failure.
muteRecordingSignal
Mutes or unmutes the recording signal.
virtual int muteRecordingSignal(bool mute) = 0;
- Record the current adjusted volume.
- Mute the recording signal.
Timing
This method can be called before or after joining a channel.
Parameters
- mute
- Whether to mute the recording signal:
- true: Mute the recording signal.
- false: (Default) Do not mute the recording signal.
Return Values
- 0: Success.
- < 0: Failure.
setInEarMonitoringVolume
Sets the in-ear monitoring volume.
virtual int setInEarMonitoringVolume(int volume) = 0;
Timing
You can call this method before or after joining the channel.
Parameters
- volume
- The user's volume. The range is [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.
- -2: Invalid parameter setting, such as volume out of valid range (less than 0 or greater than 400).
Audio Pre-processing and Post-processing
Raw Audio Data
getEarMonitoringAudioParams
Callback for setting the audio format of the onEarMonitoringAudioFrame callback.
virtual AudioParams getEarMonitoringAudioParams() = 0;
When registering the audio frame observer using registerAudioFrameObserver, you need to implement this callback. After successful registration, the SDK triggers this callback, and you can set the audio format in the return value.
Return Values
When the method call succeeds, returns an AudioParams object representing the audio format of the ear monitoring data. See AudioParams.
getMixedAudioParams
Callback for setting the audio format of the onMixedAudioFrame callback.
virtual AudioParams getMixedAudioParams() = 0;
When registering the audio frame observer using the registerAudioFrameObserver method, you need to implement this callback. After successfully registering the audio frame observer, the SDK triggers this callback, and you can set the audio format through the return value of this callback.
samplePerCall / (sampleRate × channel). Make sure the sampling interval is ≥ 0.01 seconds.Return Values
When the method call succeeds, returns an instance of AudioParams, representing the mixed capture and playback audio data. See AudioParams.
getObservedAudioFramePosition
Sets the audio data observation position.
virtual int getObservedAudioFramePosition() = 0;
- onRecordAudioFrame
- onPlaybackAudioFrame
- onPlaybackAudioFrameBeforeMixing
- onMixedAudioFrame
- onEarMonitoringAudioFrame
Return Values
AUDIO_FRAME_POSITION_PLAYBACK(0x0001): Observe the playback audio after mixing all remote users. Corresponding callback: onPlaybackAudioFrame.AUDIO_FRAME_POSITION_RECORD(0x0002): Observe the audio captured by the local user. Corresponding callback: onRecordAudioFrame.AUDIO_FRAME_POSITION_MIXED(0x0004): Observe the playback audio after mixing the local user and all remote users. Corresponding callback: onMixedAudioFrame.AUDIO_FRAME_POSITION_BEFORE_MIXING(0x0008): Observe the audio of a single remote user before mixing. Corresponding callback: onPlaybackAudioFrameBeforeMixing.AUDIO_FRAME_POSITION_EAR_MONITORING(0x0010): Observe the local user's ear monitoring audio. Corresponding callback: onEarMonitoringAudioFrame.
getPlaybackAudioParams
Sets the audio format for the onPlaybackAudioFrame callback.
virtual AudioParams getPlaybackAudioParams() = 0;
You need to register the callback when calling the registerAudioFrameObserver method. After successful registration, the SDK triggers the callback, and you can set the audio format in the return value of this callback.
samplePerCall / (sampleRate × channel). Make sure the sampling interval is ≥ 0.01 seconds.Return Values
When the method call succeeds, returns an audio parameter for playback. See AudioParams.
getRecordAudioParams
Callback for setting the audio format of the onRecordAudioFrame callback.
virtual AudioParams getRecordAudioParams() = 0;
After calling registerAudioFrameObserver to register the audio frame observer, the SDK triggers this callback. You can set the audio format in the return value of this callback.
samplePerCall / (sampleRate × channel). Make sure the sampling interval is ≥ 0.01 seconds.Return Values
When the method call succeeds, returns an instance of AudioParams. See AudioParams.
registerAudioFrameObserver
Registers an audio frame observer object.
virtual int registerAudioFrameObserver(IAudioFrameObserver* observer) = 0;
Call this method to register an audio frame observer object. You need to call this method to register if you want the SDK to trigger the onMixedAudioFrame, onRecordAudioFrame, onPlaybackAudioFrame, onPlaybackAudioFrameBeforeMixing, or onEarMonitoringAudioFrame callbacks.
Timing
Call this method before joining a channel.
Parameters
- observer
- Audio frame observer instance. Set to NULL to release the instance. It is recommended to call this method to release the audio frame observer after receiving the onLeaveChannel callback. See IAudioFrameObserver.
Return Values
- 0: Success.
- < 0: Failure.
setEarMonitoringAudioFrameParameters
Sets the format of the ear monitoring audio data.
virtual int setEarMonitoringAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) = 0;
This method sets the format of the audio data reported in the onEarMonitoringAudioFrame callback.
- Before calling this method, you must call enableInEarMonitoring and set
includeAudioFilterstoEAR_MONITORING_FILTER_BUILT_IN_AUDIO_FILTERSorEAR_MONITORING_FILTER_NOISE_SUPPRESSION. - The SDK calculates the sampling interval based on
samplesPerCall,sampleRate, andchannel. Sampling interval (in seconds) =samplesPerCall/ (sampleRate×channel). Make sure the interval is ≥ 0.01 seconds. The SDK triggers the onEarMonitoringAudioFrame callback based on this interval.
Parameters
- sampleRate
- The sampling rate reported in the onEarMonitoringAudioFrame callback. Can be set to 8000, 16000, 32000, 44100, or 48000 Hz.
- channel
- The number of audio channels reported in the onEarMonitoringAudioFrame callback.
- 1: Mono.
- 2: Stereo.
- mode
- The usage mode of the audio frame. See RAW_AUDIO_FRAME_OP_MODE_TYPE.
- samplesPerCall
- The number of samples reported in each onEarMonitoringAudioFrame callback, e.g., 1024 for media streaming.
Return Values
- 0: Success.
- < 0: Failure.
setMixedAudioFrameParameters
Sets the format of the mixed raw audio data used for capture and playback.
virtual int setMixedAudioFrameParameters(int sampleRate, int channel, int samplesPerCall) = 0;
setMixedAudioFrameParameters calculates the sampling interval based on the set samplesPerCall, sampleRate, and channel. Sampling interval (in seconds) = samplesPerCall / (sampleRate × channel). Make sure the interval is ≥ 0.01 seconds. The SDK triggers the onMixedAudioFrame callback based on this interval.
Timing
Call this method before joining a channel.
Parameters
- sampleRate
- The sampling rate returned in the callback. Can be set to 8000, 16000, 32000, 44100, or 48000 Hz.
- channel
- Number of audio channels. Can be set to:
- 1: Mono.
- 2: Stereo.
- samplesPerCall
- The number of samples per call, e.g., 1024 for media streaming.
Return Values
- 0: Success.
- < 0: Failure.
setPlaybackAudioFrameBeforeMixingParameters [1/2]
Sets the format of raw audio playback data before mixing.
virtual int setPlaybackAudioFrameBeforeMixingParameters(int sampleRate, int channel) = 0;
The SDK triggers the onPlaybackAudioFrameBeforeMixing callback based on the sampling interval. Call this method before joining a channel.
Timing
Call this method before joining a channel.
Parameters
- sampleRate
- The sampling rate returned in the callback. Can be set to 8000, 16000, 32000, 44100, or 48000 Hz.
- channel
- Number of audio channels. Can be set to:
- 1: Mono.
- 2: Stereo.
Return Values
- 0: Success.
- < 0: Failure.
setPlaybackAudioFrameBeforeMixingParameters [2/2]
Sets the format of the audio data returned in the onPlaybackAudioFrameBeforeMixing callback.
virtual int setPlaybackAudioFrameBeforeMixingParameters(int sampleRate, int channel, int samplesPerCall) = 0;
Sets the sampling rate, number of channels, and number of samples per callback for the audio data returned in the onPlaybackAudioFrameBeforeMixing callback.
Timing
Call this method before joining a channel.
Parameters
- sampleRate
- Sets the sampling rate of the audio data returned in the onPlaybackAudioFrameBeforeMixing callback. Valid values: 8000, 16000, 32000, 44100, or 48000.
- channel
- Sets the number of channels of the audio data returned in the onPlaybackAudioFrameBeforeMixing callback.
- 1: Mono.
- 2: Stereo.
- samplesPerCall
- Sets the number of samples of the audio data returned in the onPlaybackAudioFrameBeforeMixing callback. For RTMP streaming scenarios, it is recommended to set this to 1024.
Return Values
- 0: Success.
- < 0: Failure.
setPlaybackAudioFrameParameters
Sets the format of the raw playback audio data.
virtual int setPlaybackAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) = 0;
The SDK calculates the sampling interval based on the samplesPerCall, sampleRate, and channel parameters. Sampling interval (in seconds) = samplesPerCall / (sampleRate × channel). Make sure the sampling interval is ≥ 0.01 seconds. The SDK triggers the onPlaybackAudioFrame callback based on the sampling interval.
Timing
Call this method before joining a channel.
Parameters
- sampleRate
- Sampling rate returned in the callback. Can be set to 8000, 16000, 24000, 32000, 44100, or 48000 Hz.
- channel
- Number of audio channels. Can be set to:
- 1: Mono.
- 2: Stereo.
- mode
- Usage mode of the audio frame. See RAW_AUDIO_FRAME_OP_MODE_TYPE for details.
- samplesPerCall
- Number of audio samples per callback, for example, 1024 for media streaming.
Return Values
- 0: Method call succeeded.
- < 0: Method call failed.
setRecordingAudioFrameParameters
Sets the format of the captured raw audio data.
virtual int setRecordingAudioFrameParameters(int sampleRate, int channel, RAW_AUDIO_FRAME_OP_MODE_TYPE mode, int samplesPerCall) = 0;
setRecordingAudioFrameParameters calculates the sampling interval based on samplesPerCall, sampleRate, and channel. Sampling interval (in seconds) = samplesPerCall / (sampleRate × channel). Make sure the interval is ≥ 0.01 seconds. The SDK triggers the onRecordAudioFrame callback based on this interval.
Timing
Call this method before joining a channel.
Parameters
- sampleRate
- The sampling rate returned in the callback. Can be set to 8000, 16000, 32000, 44100, or 48000 (Hz).
- channel
- Number of audio channels. Can be set to:
- 1: Mono.
- 2: Stereo.
- mode
- The usage mode of the audio frame. See RAW_AUDIO_FRAME_OP_MODE_TYPE.
- samplesPerCall
- The number of samples per callback, e.g., 1024 for media streaming.
Return Values
- 0: Success.
- < 0: Failure.
onEarMonitoringAudioFrame
Ear monitoring audio frame callback.
virtual bool onEarMonitoringAudioFrame(AudioFrame& audioFrame) = 0;
- Method 1: Call setEarMonitoringAudioFrameParameters to set the audio data format, and then call registerAudioFrameObserver to register the audio frame observer object. The SDK calculates the sampling interval based on the set parameters and triggers this callback at that interval.
- Method 2: Call registerAudioFrameObserver to register the audio frame observer object, and set the audio data format in the return value of the getObservedAudioFramePosition callback. The SDK calculates the sampling interval based on the return value of the getEarMonitoringAudioParams callback and triggers this callback at that interval.
Parameters
- audioFrame
- Raw audio data. See AudioFrame.
Return Values
- true: Callback processed successfully.
- false: Callback processing failed.
onMixedAudioFrame
Callback for mixed capture and playback audio frame.
virtual bool onMixedAudioFrame(const char* channelId, AudioFrame& audioFrame) = 0;
- Method 1: Call setMixedAudioFrameParameters to set the audio data format, and then call registerAudioFrameObserver to register the audio frame observer object. The SDK calculates the sampling interval based on the set parameters and triggers this callback at that interval.
- Method 2: After calling registerAudioFrameObserver to register the audio frame observer object, set the audio data format in the return value of the getObservedAudioFramePosition callback. The SDK calculates the sampling interval based on the return value of the getMixedAudioParams callback and triggers this callback at that interval.
Parameters
- channelId
- Channel ID.
- audioFrame
- An output parameter. Raw audio data. See AudioFrame.
Return Values
- true: Callback processed successfully.
- false: Callback processing failed.
onPlaybackAudioFrame
onPlaybackAudioFrame callback: retrieves the raw audio frame for playback.
virtual bool onPlaybackAudioFrame(const char* channelId, AudioFrame& audioFrame) = 0;
- Method 1: Call setPlaybackAudioFrameParameters to set the audio data format, and then call registerAudioFrameObserver to register the audio frame observer object. The SDK calculates the sampling interval based on the set parameters and triggers this callback at that interval.
- Method 2: After calling registerAudioFrameObserver to register the audio frame observer object, set the audio data format in the return value of the getObservedAudioFramePosition callback. The SDK calculates the sampling interval based on the return value of the getPlaybackAudioParams callback and triggers this callback at that interval.
Parameters
- channelId
- Channel ID.
- audioFrame
- An output parameter. Raw audio data. See AudioFrame.
Return Values
- true: Callback processed successfully.
- false: Callback processing failed.
onPlaybackAudioFrameBeforeMixing
Callback for retrieving the audio frame of a subscribed remote user before mixing.
virtual bool onPlaybackAudioFrameBeforeMixing(const char* channelId, base::user_id_t userId, AudioFrame& audioFrame)
Parameters
- channelId
- Channel ID.
- userId
- User ID of the subscribed remote user.
- audioFrame
- An output parameter. Raw audio data. See AudioFrame.
Return Values
- true: Callback processed successfully.
- false: Callback processing failed.
onRecordAudioFrame
Callback triggered when an audio frame is captured.
virtual bool onRecordAudioFrame(const char* channelId, AudioFrame& audioFrame) = 0;
- Method 1: Call setRecordingAudioFrameParameters to set the audio data format, and register the audio frame observer object using registerAudioFrameObserver. The SDK calculates the sampling interval based on the set parameters and triggers this callback accordingly.
- Method 2: After registering the audio frame observer object using registerAudioFrameObserver, set the audio data format in the return value of getObservedAudioFramePosition. The SDK then calculates the sampling interval based on the return value of getRecordAudioParams and triggers this callback accordingly.
Trigger Timing
The SDK triggers this callback based on the sampling interval.
Parameters
- channelId
- Channel ID.
- audioFrame
- Output parameter, raw audio data. See AudioFrame.
Return Values
- true: Callback processed successfully.
- false: Callback processing failed.
Encoded Audio Data
registerAudioEncodedFrameObserver
Registers an observer for encoded audio data.
virtual int registerAudioEncodedFrameObserver(const AudioEncodedFrameObserverConfig& config, IAudioEncodedFrameObserver *observer) = 0;
startAudioRecording to set the recording type and quality of the audio file, but Agora does not recommend using both methods at the same time. Only the method called later takes effect.Parameters
- config
- Configuration for the encoded audio observer. See AudioEncodedFrameObserverConfig.
- observer
- Observer for encoded audio data. See IAudioEncodedFrameObserver.
Return Values
- 0: Success.
- < 0: Failure.
onMixedAudioEncodedFrame
Callback for mixed encoded audio data of the local and all remote users.
virtual void onMixedAudioEncodedFrame(const uint8_t* frameBuffer, int length, const EncodedAudioFrameInfo& audioEncodedFrameInfo) = 0;
After calling registerAudioEncodedFrameObserver and setting the audio configuration to AUDIO_ENCODED_FRAME_OBSERVER_POSITION_MIXED, you can use this callback to get the mixed encoded audio data of the local and all remote users.
Parameters
- frameBuffer
- Audio data buffer.
- length
- Byte length of the audio data.
- audioEncodedFrameInfo
- Information about the encoded audio frame. See EncodedAudioFrameInfo.
onPlaybackAudioEncodedFrame
Callback for retrieving encoded audio data of all remote users.
virtual void onPlaybackAudioEncodedFrame(const uint8_t* frameBuffer, int length, const EncodedAudioFrameInfo& audioEncodedFrameInfo) = 0;
After calling registerAudioEncodedFrameObserver and setting the encoded audio position to AUDIO_ENCODED_FRAME_OBSERVER_POSITION_PLAYBACK, you can use this callback to get the encoded audio data of all remote users.
Parameters
- frameBuffer
- Audio data buffer.
- length
- Length of the audio data in bytes.
- audioEncodedFrameInfo
- Information about the encoded audio frame. See EncodedAudioFrameInfo.
onRecordAudioEncodedFrame
Callback for encoded audio data of the local user.
virtual void onRecordAudioEncodedFrame(const uint8_t* frameBuffer, int length, const EncodedAudioFrameInfo& audioEncodedFrameInfo) = 0;
After calling registerAudioEncodedFrameObserver and setting the encoded audio position to AUDIO_ENCODED_FRAME_OBSERVER_POSITION_RECORD, you can use this callback to get the encoded audio data of the local user.
Parameters
- frameBuffer
- Audio data buffer.
- length
- Byte length of the audio data.
- audioEncodedFrameInfo
- Information about the encoded audio frame. See EncodedAudioFrameInfo.
Custom Audio Capture and Rendering
adjustCustomAudioPlayoutVolume
Adjusts the volume of custom audio tracks played locally.
virtual int adjustCustomAudioPlayoutVolume(track_id_t trackId, int volume) = 0;
If you want to change the volume of the audio played locally, you need to call this method again.
Parameters
- trackId
- Audio track ID, set to the custom audio track ID returned by createCustomAudioTrack.
- volume
- Volume of the audio source, ranging from 0 to 100.
- 0: Mute.
- 100: Original volume.
Return Values
- 0: Success.
- < 0: Failure.
adjustCustomAudioPublishVolume
Adjusts the volume of custom audio tracks played remotely.
virtual int adjustCustomAudioPublishVolume(track_id_t trackId, int volume) = 0;
If you want to change the volume of the audio played remotely, you need to call this method again.
Parameters
- trackId
- Audio track ID, set to the custom audio track ID returned by createCustomAudioTrack.
- volume
- Volume of the audio source, ranging from 0 to 100.
- 0: Mute.
- 100: Original volume.
Return Values
- 0: Success.
- < 0: Failure.
createCustomAudioTrack
Creates a custom audio track.
virtual rtc::track_id_t createCustomAudioTrack(rtc::AUDIO_TRACK_TYPE trackType, const rtc::AudioTrackConfig& config) = 0;
- Call this method to create a custom audio track and obtain the track ID.
- Call
joinChannelto join a channel. In ChannelMediaOptions, setpublishCustomAudioTrackIdto the track ID andpublishCustomAudioTrackto true. - Call pushAudioFrame, and set
trackIdto the track ID from step 2 to publish the custom audio source in the channel.
Timing
Call this method before joining a channel.
Parameters
- trackType
- Type of custom audio track. See AUDIO_TRACK_TYPE.
Note: If this parameter is set to
AUDIO_TRACK_DIRECT, you must setpublishMicrophoneTrackto false in ChannelMediaOptions when callingjoinChannel, otherwise the channel join will fail and return error code -2. - config
- Configuration of the custom audio track. See AudioTrackConfig.
Return Values
- On success, returns the audio track ID as a unique identifier.
- On failure, returns
0xffffffff.
destroyCustomAudioTrack
Destroys the specified audio track.
virtual int destroyCustomAudioTrack(rtc::track_id_t trackId) = 0;
Parameters
- trackId
- Custom audio track ID returned by createCustomAudioTrack.
Return Values
- 0: Success.
- < 0: Failure.
enableCustomAudioLocalPlayback
Enables or disables local playback of external audio sources.
virtual int enableCustomAudioLocalPlayback(track_id_t trackId, bool enabled) = 0;
Call this method to enable local playback of external audio sources. To stop playback, call this method again and set enabled to false. You can adjust the local playback volume of the custom audio track using the adjustCustomAudioPlayoutVolume method.
Parameters
- trackId
- The audio track ID, set to the ID returned by createCustomAudioTrack.
- enabled
- Whether to play the external audio source:
- true: Play the external audio source.
- false: (Default) Do not play the external audio source.
Return Values
- 0: Success.
- < 0: Failure.
pullAudioFrame
Pulls mixed remote audio data.
virtual int pullAudioFrame(IAudioFrameObserverBase::AudioFrame* frame) = 0;
After calling this method, the app pulls decoded and mixed audio data for playback. Call this method after joining a channel. Before calling this method, call setExternalAudioSink to enable and configure external audio rendering.
- After calling pullAudioFrame, the app automatically pulls audio data from the SDK. By configuring audio data parameters, the SDK adjusts the frame buffer to help the app handle latency and avoid audio jitter.
- After registering the onPlaybackAudioFrame callback, the SDK sends audio data to the app via callback. If there is delay in audio frame processing, audio jitter may occur.
Timing
Call this method after joining a channel.
Parameters
- frame
- Output parameter, a pointer to AudioFrame. See AudioFrame.
Return Values
- 0: Success.
- < 0: Failure.
pushAudioFrame
Pushes external audio frames.
virtual int pushAudioFrame(IAudioFrameObserverBase::AudioFrame* frame, rtc::track_id_t trackId = 0) = 0;
Timing
- Call createCustomAudioTrack to create a custom audio track and obtain the track ID.
- Call
joinChannelto join a channel. In ChannelMediaOptions, setpublishCustomAudioTrackIdto the audio track ID you want to publish, and setpublishCustomAudioTrackto true.
Parameters
- frame
- External audio frame. See AudioFrame.
- trackId
- Audio track ID. Set this parameter to the custom audio track ID if you want to publish a custom audio source.
Return Values
- 0: Success.
- < 0: Failure.
setExternalAudioSink
Sets the external audio renderer.
virtual int setExternalAudioSink(bool enabled, int sampleRate, int channels) = 0;
After enabling the external audio renderer, you can call pullAudioFrame to pull remote audio frames, process them, and play them using custom audio effects. This is suitable for scenarios where external audio playback is needed.
Timing
Call this method before joining a channel.
Parameters
- enabled
- Whether to enable the external audio renderer:
- true: Enable.
- false: (Default) Disable.
- sampleRate
- Sample rate (Hz) of the external audio renderer. Can be 16000, 32000, 44100, or 48000.
- channels
- Number of channels for the external audio renderer:
- 1: Mono.
- 2: Stereo.
Return Values
- 0: Success.
- < 0: Failure.
setExternalAudioSource
Sets external audio source parameters.
virtual int setExternalAudioSource(bool enabled, int sampleRate, int channels, bool localPlayback = false, bool publish = true) __deprecated = 0;
- Deprecated
- This method is deprecated. Use createCustomAudioTrack instead.
Timing
Call this method before joining a channel.
Parameters
- enabled
- Whether to enable the external audio source:
- true: Enable external audio source.
- false: (Default) Do not enable external audio source.
- sampleRate
- Sample rate (Hz) of the external audio source. Can be 8000, 16000, 32000, 44100, or 48000.
- channels
- Number of channels of the external audio source. Can be 1 (mono) or 2 (stereo).
- localPlayback
- Whether to play the external audio source locally:
- true: Play locally.
- false: (Default) Do not play locally.
- publish
- Whether to publish audio to remote users:
- true: (Default) Publish audio to remote users.
- false: Do not publish audio to remote users.
Return Values
- 0: Success.
- < 0: Failure.
Audio Spectrum
disableAudioSpectrumMonitor
Disables audio spectrum monitoring.
virtual int disableAudioSpectrumMonitor() = 0;
After calling enableAudioSpectrumMonitor, you can call this method to disable audio spectrum monitoring.
Return Values
- 0: Success.
- < 0: Failure.
enableAudioSpectrumMonitor
Enables audio spectrum monitoring.
virtual int enableAudioSpectrumMonitor(int intervalInMS = 100) = 0;
Scenario
You can call this method before or after joining a channel.
Parameters
- intervalInMS
- The interval in milliseconds at which the SDK triggers the onLocalAudioSpectrum and onRemoteAudioSpectrum callbacks (default is 100). This value must not be less than 10; otherwise, the method call will fail.
Return Values
- 0: Success.
- < 0: Failure.
- -2: Invalid parameter.
registerAudioSpectrumObserver
Registers an audio spectrum observer.
virtual int registerAudioSpectrumObserver(agora::media::IAudioSpectrumObserver * observer) = 0;
After successfully registering the audio spectrum observer and calling enableAudioSpectrumMonitor, the SDK triggers the callbacks implemented in IAudioSpectrumObserver at the set interval.
Parameters
- observer
- The audio spectrum observer. See IAudioSpectrumObserver.
Return Values
- 0: Success.
- < 0: Failure.
unregisterAudioSpectrumObserver
Unregisters the audio spectrum observer.
virtual int unregisterAudioSpectrumObserver(agora::media::IAudioSpectrumObserver * observer) = 0;
After calling registerAudioSpectrumObserver, you can call this method to disable audio spectrum monitoring.
Parameters
- observer
- The audio spectrum observer. See IAudioSpectrumObserver.
Return Values
- 0: Success.
- < 0: Failure.
onLocalAudioSpectrum
Callback for local audio spectrum data.
virtual bool onLocalAudioSpectrum(const AudioSpectrumData& data) = 0;
After calling registerAudioSpectrumObserver to register the IAudioSpectrumObserver interface and implementing the onLocalAudioSpectrum callback, and calling enableAudioSpectrumMonitor to enable audio spectrum monitoring, the SDK triggers this callback at the set interval before encoding to report local audio spectrum data.
Parameters
- data
- Audio spectrum data of the local user. See AudioSpectrumData.
Return Values
- true: Spectrum data received.
- false: Spectrum data not received.
onRemoteAudioSpectrum
Callback for remote audio spectrum.
virtual bool onRemoteAudioSpectrum(const UserAudioSpectrumInfo* spectrums, unsigned int spectrumNumber) = 0;
After successfully calling registerAudioSpectrumObserver to implement the onRemoteAudioSpectrum callback and calling enableAudioSpectrumMonitor to enable audio spectrum monitoring, the SDK triggers this callback at the interval you set to report the received remote audio spectrum data.
Trigger Timing
The SDK triggers this callback at the interval you set to report the received remote audio spectrum data.
Parameters
- spectrums
- Audio spectrum information of remote users. The array length equals the number of remote users detected by the SDK. If the array is NULL, it means no remote audio spectrum is detected. See UserAudioSpectrumInfo.
- spectrumNumber
- Number of remote users.
Return Values
- true: Spectrum data received.
- false: Spectrum data not received.