Skip to main content
AOQ SDK Features

Audio features

AOQ SDK audio capture, playback, and codec configuration

The AOQ Client SDK provides comprehensive audio capabilities, covering audio capture, playback, codec configuration, speaker management, file mixing, external audio stream injection, and audio frame data callbacks. This document introduces common audio features across Android (Java), iOS (Objective-C), and HarmonyOS (ArkTS).

Audio capture

Audio capture opens the device microphone and feeds real-time audio data into the SDK encoding pipeline. The SDK supports two capture modes:
  • Internal capture (default): The SDK automatically manages the microphone -- opening, recording, and closing it.
  • External capture: The application manages the microphone directly and feeds the captured PCM data into the SDK through the external audio stream API.

Configuration parameters

ParameterTypeDefaultDescription
isExternalboolfalseWhether to use external capture mode
isVoipModeboolfalseWhether to enable VoIP mode (hardware AEC). Valid on mobile. If both capture and playback are configured, whichever is set first takes effect.
channelint1Number of capture channels. Supports 1 (mono) or 2 (stereo).

API reference

FunctionAndroidiOSHarmonyOS
Start capturestartAudioCapture(config)startAudioCapture:config:startAudioCapture(config)
Stop capturestopAudioCapture()stopAudioCapturestopAudioCapture()
Mute/unmutemuteAudioCapture(mute)muteAudioCapture:muteAudioCapture(mute)

Example

Android
AoqAudioCaptureConfig config = new AoqAudioCaptureConfig();
config.isVoipMode = true;
config.channel = 1;
engine.startAudioCapture(config);
iOS
AoqAudioCaptureConfig *config = [[AoqAudioCaptureConfig alloc] init];
config.isVoipMode = YES;
config.channel = 1;
[engine startAudioCapture:config];
HarmonyOS
const config: AoqAudioCaptureConfig = { isVoipMode: true, channel: 1 };
engine.startAudioCapture(config);

Audio playback

Audio playback renders received remote audio data to the local speaker or headset. The SDK supports advanced controls including pause/resume with fade in/out and interrupting the current turn of an audio conversation.

Configuration parameters

ParameterTypeDefaultDescription
isVoipModeboolfalseWhether to enable VoIP mode (hardware AEC). Valid on mobile. If both capture and playback are configured, whichever is set first takes effect.
isDefaultSpeakerbooltrueWhether to use the speaker by default. Valid on mobile and only in non-VoIP mode.
isExternalboolfalseWhether to use external playback mode.
channelint1Number of playback channels. Supports 1 (mono) or 2 (stereo).

API reference

FunctionAndroidiOSHarmonyOS
Start playbackstartAudioPlayer(config)startAudioPlayer:config:startAudioPlayer(config)
Stop playbackstopAudioPlayer()stopAudioPlayerstopAudioPlayer()
Pause playbackpauseAudioPlayer(fadeMs)pauseAudioPlayer:pauseAudioPlayer(fadeMs)
Resume playbackresumeAudioPlayer(fadeMs)resumeAudioPlayer:resumeAudioPlayer(fadeMs)
Interrupt conversationinterruptAudioPlayer(trackType, fadeMs)interruptAudioPlayer:fadeMs:interruptAudioPlayer(trackType, fadeMs)
fadeMs parameter: The fade-in or fade-out duration in milliseconds when pausing or resuming playback. Set to 0 for an immediate switch.

Speaker management

Switch the audio output device between the speaker and earpiece.
FunctionAndroidiOSHarmonyOS
Switch speakerenableSpeakerphone(enable)enableSpeakerphone:enableSpeakerphone(enable)
Query speaker stateisSpeakerphoneEnabled()isSpeakerphoneEnabledisSpeakerphoneEnabled()
Speaker switching is only allowed in VoIP mode. When not in VoIP mode, calling enableSpeakerphone triggers an OnError(AoqECAudioDeviceEarpieceRequiresVoipMode) error notification.
iOS-specific behavior: iPad devices have only speaker mode. When the AVAudioSession category is not PlayAndRecord, this method always returns YES.

Audio codec configuration

Configure the encoding format, sample rate, channel count, and bitrate for audio uplink (encoder) and downlink (decoder). These settings determine the format for publishing and pulling streams.

Configuration parameters

ParameterTypeDefaultDescription
trackTypeAoqTrackTypeAudioAudio track type. Currently only one audio stream is supported.
codecTypeAoqEncoderTypeAudioPCMEncoding type: AudioPCM(1) or AudioOpus(2)
sampleRateint48000Sample rate. Opus supports 8K/16K/48K. PCM supports 8K/16K/32K/48K.
channelint1Channel count. Supports 1 (mono) or 2 (stereo).
bitrateint32000Bitrate in bps.

API reference

FunctionAndroidiOSHarmonyOS
Set encoder configsetAudioEncoderConfig(config)setAudioEncoderConfig:setAudioEncoderConfig(config)
Set decoder configsetAudioDecoderConfig(config)setAudioDecoderConfig:setAudioDecoderConfig(config)

Supported encoding formats

Enum valueNumberDescription
AoqEncoderTypeAudioPCM1Raw PCM audio
AoqEncoderTypeAudioOpus2Opus encoding

Audio file mixing

Mix a local audio file into the current audio stream for publishing and/or local playback. Each audio file is identified by an application-assigned fileId, allowing multiple file instances to be managed simultaneously.

Mixing configuration parameters

ParameterTypeDefaultDescription
fileNameString-Audio file path (including filename)
cyclesint-1Number of loops. -1 means loop indefinitely.
startPosMslong0Start playback position in milliseconds
publishVolumeint100Publishing volume [0-100]
playoutVolumeint100Local playback volume [0-100]

API reference

FunctionAndroidiOSHarmonyOS
Start playbackstartAudioFile(fileId, config)startAudioFile:config:startAudioFile(fileId, config)
Stop playbackstopAudioFile(fileId)stopAudioFile:stopAudioFile(fileId)
PausepauseAudioFile(fileId)pauseAudioFile:pauseAudioFile(fileId)
ResumeresumeAudioFile(fileId)resumeAudioFile:resumeAudioFile(fileId)
Get file durationgetAudioFileDuration(fileId)getAudioFileDuration:getAudioFileDuration(fileId)
Get current positiongetAudioFileCurrentPosition(fileId)getAudioFileCurrentPosition:getAudioFileCurrentPosition(fileId)
Seek to positionsetAudioFilePositionMillis(fileId, pos)setAudioFilePositionMillis:positionMillis:setAudioFilePositionMillis(fileId, pos)
Set volumesetAudioFileVolume(fileId, type, vol)setAudioFileVolume:type:volume:setAudioFileVolume(fileId, type, vol)
Get volumegetAudioFileVolume(fileId, type)getAudioFileVolume:type:getAudioFileVolume(fileId, type)
Volume direction (type): AoqAudioStreamPublish(0) controls the publishing volume. AoqAudioStreamPlayout(1) controls the local playback volume.

State callbacks

State codeValueDescription
AoqAudioFileNone0Initial state
AoqAudioFileStarted1Playback started
AoqAudioFileStopped2Playback stopped
AoqAudioFilePaused3Playback paused
AoqAudioFileResumed4Playback resumed
AoqAudioFileEnded5Playback ended
AoqAudioFileBuffering6Buffering
AoqAudioFileBufferingEnd7Buffering ended
AoqAudioFileFailed8Playback failed

External audio streams

External audio streams let you inject application-generated PCM audio data into the SDK's audio pipeline for publishing and/or local playback. Typical use cases include TTS synthesis output, AI model audio output, and background sound effects. Each external audio stream is identified by an application-assigned streamId.

Configuration parameters

ParameterTypeDefaultDescription
trackTypeAoqTrackTypeAudioAudio track type
codecTypeAoqEncoderTypeAudioPCMAudio stream format
channelsint1Channel count
sampleRateint48000Sample rate. Supports 8/12/16/24/32/44.1/48/64/88.2/96/176.4/192 kHz.
playoutVolumeint100Local playback volume [0-100]
publishVolumeint100Publishing volume [0-100]
maxBufferDurationint600000Maximum buffer duration in milliseconds. Valid range: [100, ~]. Push fails if the buffer is full.
enable3AboolfalseWhether to apply 3A processing to the input PCM

API reference

FunctionAndroidiOSHarmonyOS
Add external streamaddAudioExternalStream(streamId, config)addAudioExternalStream:config:addAudioExternalStream(streamId, config)
Push audio datapushAudioExternalStreamData(streamId, data)pushAudioExternalStreamData:data:pushAudioExternalStreamData(streamId, data)
Set volumesetAudioExternalStreamVolume(streamId, type, vol)setAudioExternalStreamVolume:type:volume:setAudioExternalStreamVolume(streamId, type, vol)
Get volumegetAudioExternalStreamVolume(streamId, type)getAudioExternalStreamVolume:type:getAudioExternalStreamVolume(streamId, type)
Clear bufferclearAudioExternalStreamBuffer(streamId, fadeoutMs)clearAudioExternalStreamBuffer:fadeoutMs:clearAudioExternalStreamBuffer(streamId, fadeoutMs)
Remove streamremoveAudioExternalStream(streamId)removeAudioExternalStream:removeAudioExternalStream(streamId)

Best practices for pushing data

  • Call pushAudioExternalStreamData in a loop to ensure data is pushed successfully.
  • If error code 110 (buffer full) is returned, sleep for 30 ms and retry. Do not discard data.
  • Before the engine exits, stop the push loop first, then call removeAudioExternalStream.
  • For real-time capture, each frame is 10 ms -- call push whenever data is available. For file-based input, each frame is 40 ms -- call push once every 30 ms.

Audio frame callbacks

Audio frame callbacks let you obtain raw PCM data at different points in the audio pipeline, for use in audio analysis, custom processing, recording, and similar scenarios.

Supported data source positions

Data sourceEnum valueDescription
Captured0Raw audio data after capture, before 3A processing
ProcessCaptured1Audio data after 3A processing. Callbacks start only after a successful connection.
Publish2Audio data about to be published. Requires a successful connection.
Playback3Audio data about to be played back (remote downlink)

Callback configuration parameters

ParameterTypeDefaultDescription
sampleRateint48000Sample rate for callback audio
channelsint1Channel count for callback audio. Supports 1 or 2.
modeAoqAudioObserverModeReadOnlyRead-only (0) or read-write (1) mode

Usage steps

  1. Register the observer: Call setAudioFrameObserver to set the audio frame callback listener.
  2. Enable the data source: Call enableAudioFrameObserver to select the data source position and start callbacks.
  3. Handle callback data: Process PCM data in the callback.

API reference

FunctionAndroidiOSHarmonyOS
Register observersetAudioFrameObserver(listener)setAudioFrameObserver:setAudioFrameObserver(observer)
Enable callbacksenableAudioFrameObserver(enabled, source, config)enableAudioFrameObserver:audioSource:config:enableAudioFrameObserver(enabled, source, config)

Callback methods

CallbackAndroidiOSHarmonyOS
Captured dataonCapturedAudioFrame(frame)onCapturedAudioFrame:onCapturedAudioFrame(frame)
Post-3A dataonProcessCapturedAudioFrame(frame)onProcessCapturedAudioFrame:onProcessCapturedAudioFrame(frame)
Publish dataonPublishAudioFrame(trackType, frame)onPublishAudioFrame:frame:onPublishAudioFrame(trackType, frame)
Playback dataonPlaybackAudioFrame(frame)onPlaybackAudioFrame:onPlaybackAudioFrame(frame)

Audio state and routing

The SDK automatically monitors audio device state changes and routing switches, and notifies the application layer through callbacks.

Device state codes

State codeValueDescription
AoqAudioDeviceNone0Initial state
RecordStarting1Capture starting
RecordStarted2Capture started
RecordStopping3Capture stopping
RecordStopped4Capture stopped
RecordFail5Capture failed
PlayStarting6Playback starting
PlayStarted7Playback started
PlayStopping8Playback stopping
PlayStopped9Playback stopped
PlayFail10Playback failed

Device routing types

RouteValueDescription
Default0Default
Headset1Wired headset
Earpiece2Earpiece
HeadsetNoMic3Headset without microphone
SpeakerPhone4Speaker
Usb5USB device
Bluetooth6Bluetooth SCO
BluetoothA2dp7Bluetooth A2DP

Callback reference

CallbackAndroidiOSHarmonyOS
Device state changeonAudioDeviceStateChanged(state)onAudioDeviceStateChanged:onAudioDeviceStateChanged(state, reason)
Route changeonAudioDeviceRouteChanged(routeType)onAudioDeviceRouteChanged:onAudioDeviceRouteChanged(routeType)
Device interruptedonAudioDeviceInterrupted(interrupt)onAudioDeviceInterrupted:onAudioDeviceInterrupted(interrupt)
File stateonAudioFileState(state)onAudioFileState:onAudioFileState(fileId, stateCode, errorCode)

Audio error and warning codes

Audio error codes

Error codeValueDescription
AoqErrorCodeAudio100General audio error
AudioExternalBufferFull110External buffer full
AudioDevice120General device error
RecordingAuthFailed121Microphone permission denied
RecordingOccupied122Microphone in use by another process
RecordingBackgroundStart123Started recording in the background
RecordingStartFail124Failed to start recording
PlayoutOccupied125Playback device in use by another process
PlayoutBackgroundStart126Started playback in the background
PlayoutStartFail127Failed to start playback
EarpieceRequiresVoipMode128Earpiece requires VoIP mode to be enabled

Audio warning codes

Warning codeValueDescription
AoqWCAudio100General audio warning
AudioHowling101Howling detected
AudioDevice120General device warning
MicEnumerateError121Microphone enumeration error
MicStartTimeout122Microphone start timeout
RecordingError123Recording error
SpeakerEnumerateError124Speaker enumeration error
SpeakerStartTimeout125Speaker start timeout
PlayoutError126Playback error

iOS only: AVAudioSession control

On iOS, the setAudioSessionRestriction API gives you fine-grained control over how the SDK manages the system AVAudioSession.
ControlDescription
SetCategoryWhether the SDK can set the session category
ConfigureSessionWhether the SDK can configure session parameters
DeactivateSessionWhether the SDK can deactivate the session
ActivateSessionWhether the SDK can activate the session
Pass a bitwise combination of restriction values to limit the SDK's control over AVAudioSession and prevent conflicts with other audio components in the application layer.