API operation details

更新时间:
复制 MD 格式

The iOS SDK provides engine interfaces, delegate callbacks, and factory methods for AI call management.

API overview

Note

Deprecated parameters and methods exist in earlier SDK versions. We recommend that you upgrade the SDK to the latest version. For more information, see iOS user guide.

Class/Protocol

API

Description

ARTCAICallEngineInterface

Engine interface definition

userId

The user ID of the current call.

isOnCall

Indicates whether a call is in progress.

agentInfo

Information about the current agent.

agentState

The state of the current agent.

delegate

Sets and gets callback events.

call[1/2]

Starts a call.

call[2/2]

Starts a call using the call configuration.

handup[1/2]

Hangs up a call.

handup[2/2]

Hangs up the call and destroys the current call engine.

audioConfig

Audio configuration, including encoding settings such as sample rate, the number of sound channels, and bitrate, and scenario settings such as default and music scenarios.

videoConfig

Video configuration.

setLocalViewConfig

Sets the rendering view and configuration for the local camera.

setAgentViewConfig

Sets the rendering view configuration for the agent. This is required when the agent has image rendering. This is valid only for AvatarAgent and VideoAgent.

interruptSpeaking

Interrupts the agent's speech.

enableVoiceInterrupt

Enables or disables smart interruption.

switchVoiceId

Switches the voice.

enableSpeaker

Enables or disables the speaker.

enablePushToTalk

Enables or disables the push-to-talk mode.

startPushToTalk

Starts speaking in push-to-talk mode.

finishPushToTalk

Stops speaking in push-to-talk mode.

cancelPushToTalk

Cancels the current speech in push-to-talk mode.

muteMicrophone

Mutes or unmutes the microphone.

muteAgentAudioPlaying

Stops or resumes the playback of the agent's audio stream.

visionConfig

Parameter settings for visual understanding calls.

muteLocalCamera

Disables or enables the camera.

switchCamera

Switches between the front and rear cameras.

parseShareAgentCall

Parses the information of a shared agent.

generateShareAgentCall

Starts a shared agent call.

getRTCInstance

Obtain the RTC engine.

sendTextToAgent

Sends a text message to the agent.

sendCustomMessageToServer

Sends a custom message to the server. Must be called after the call is connected.

updateLlmSystemPrompt

Updates the system prompt for the large language model (LLM). This operation must be called after the call is connected.

updateBailianAppParams

Updates the parameters for Alibaba Cloud Model Studio.

updateVcrConfig

Updates the VCR configuration.

startVisionCustomCapture

For a visual understanding agent, starts custom frame capture. After this is started, you cannot talk to the agent by voice. This operation must be called after the call is connected.

stopVisionCustomCapture

For a visual understanding agent, stops custom frame capture. This operation must be called after the call is connected.

updateAsrMaxSilence

Updates the threshold for voice activity detection.

updateTtsSpeechRate

Updates the text-to-speech (TTS) playback speed.

createRTCEngine

Creates an ARTC engine in advance. If not called, the engine is created when the call starts.

destroy

Releases resources.

ARTCAICallEngineDelegate

Engine callback events

onErrorOccurs

An error occurred.

onAgentStarted

The call agent has started.

onCallBegin

The call has started.

onCallEnd

The call has ended.

onAgentVideoAvailable

Indicates whether the agent's video is available.

onAgentAudioAvailable

Indicates whether the agent's audio is available.

onRTCEngineCreated

The RTC engine was created successfully.

onPushToTalk

Indicates whether the push-to-talk mode is enabled for the current call.

onAgentWillLeave

The current agent is about to leave (end the current call).

onReceivedAgentCustomMessage

A custom message is received from the current agent.

onAgentStateChanged

The agent's state has changed.

onNetworkStatusChanged

The network status has changed.

onVoiceVolumeChanged

The volume has changed.

onUserSubtitleNotify

A notification that the user's question is recognized by the agent.

onVoiceAgentSubtitleNotify

A notification of the agent's response.

onLLMReplyCompleted

The LLM has finished responding in the current call.

onVoiceIdChanged

The voice of the current call has changed.

onVoiceInterrupted

Indicates whether voice interruption is enabled for the current call.

onSpeakingInterrupted

The agent's current speech is interrupted. Only callbacks for interruptions by specific words are supported.

onVisionCustomCapture

Indicates whether custom frame capture mode is enabled for the current visual understanding call.

onAgentAvatarFirstFrameDrawn

The first frame of the agent's digital human is rendered.

onHumanTakeoverWillStart

A human is about to take over the current agent.

onHumanTakeoverConnected

The human takeover is connected.

onAgentEmotionNotify

A notification of the agent's emotion.

onAgentDataChannelAvailable

A callback for the availability of the agent's message channel.

onReceivedAgentVcrResult

A VCR result is received from the current agent.

onConnectionStatusChange

The connection status changes during the call.

onAudioDelayInfo

Audio loopback latency.

onAudioAccompanyStateChanged

If you play background music through the ARTC instance during the current call, this playback callback is triggered.

ARTCAICallEngineFactory

Engine creation factory

createEngine

Creates a default engine instance.

API details

ARTCAICallEngineInterface details

userId

The user ID for the current call.

var userId: String? {get}

isOnCall

Indicates whether a call is in progress. The value is true from the time the call is connected until it ends or an error occurs. Otherwise, the value is false.

var isOnCall: Bool { get }

agentInfo

Information about the current agent, including the agent type, channel ID, agent UID in the channel, and the agent's running instance ID. For more information, see ARTCAICallAgentInfo.

var agentInfo: ARTCAICallAgentInfo? { get }

agentState

The state of the current agent, such as listening, thinking, and speaking. For more information, see ARTCAICallAgentState.

var agentState: ARTCAICallAgentState { get }

delegate

Sets and retrieves callback events. For more information about callback events, see ARTCAICallEngineDelegate.

weak var delegate: ARTCAICallEngineDelegate? { get set }

call[1/2]

Starts a call.

Note

The client calls this operation when the server initiates the call. For more information about how to initiate an agent call from the server, see Initiate a call to an agent using a server-side API operation.

func call(userId: String, token: String, agentInfo: ARTCAICallAgentInfo, completed:((_ error: NSError?) -> Void)?)

Parameter details:

Parameter

Type

Description

userId

String

The UID of the current user.

token

String

The token for joining the call.

agentInfo

ARTCAICallAgentInfo

The agent information.

completed

((_ error: NSError?) -> Void)?

The completion callback.

call[2/2]

Starts a call using the call configuration.

Note

This operation is called on the client to call an agent. This is the default call method. For more information, see iOS user guide.

func call(config: ARTCAICallConfig) -> Bool

Parameter details:

Parameter

Type

Description

config

ARTCAICallConfig

The call configuration.

handup[1/2]

Ends a call.

 func handup(_ stopAIAgent: Bool)

Parameter details:

Parameter

Type

Description

stopAIAgent

Bool

Specifies whether to end the current agent task at the same time.

handup[2/2]

Hangs up the call and destroys the current call engine. First, a message is sent to notify the agent to stop the call. Then, the system waits for 100 ms before it ends the call.

func handup(destroy: Bool)

Parameter details:

Parameter

Type

Description

destroy

Bool

Specifies whether to destroy the current engine after hanging up. If set to true, the destroy() method is called internally after the call is completely hung up.

audioConfig

The audio configuration, covering encoding settings (sample rate, number of channels, and bitrate) and scenario settings (default and music). For more information, see ARTCAICallAudioConfig. This parameter takes effect only when it is set before the call.

var audioConfig: ARTCAICallAudioConfig { set get }

videoConfig

The video configuration. Valid only for VisionAgent and VideoAgent. Takes effect only when set before the call. For more information, see ARTCAICallVideoConfig.

var videoConfig: ARTCAICallVideoConfig { set get }

setLocalViewConfig

Sets the rendering view and configuration for the local camera. Valid only for VisionAgent and VideoAgent. For more information, see ARTCAICallViewConfig.

func setLocalViewConfig(viewConfig: ARTCAICallViewConfig?)

Parameter details:

Parameter

Type

Description

viewConfig

ARTCAICallViewConfig

The view configuration. An empty value indicates that no view needs to be rendered.

setAgentViewConfig

Sets the rendering view configuration for the agent. Required when the agent has image rendering capabilities. Valid only for VisionAgent and VideoAgent. For more information, see ARTCAICallViewConfig.

func setAgentViewConfig(viewConfig: ARTCAICallViewConfig?)

Parameter details:

Parameter

Type

Description

viewConfig

ARTCAICallViewConfig?

The rendering view configuration, including the rendering view, rendering mode, mirror mode, and rotation mode.

interruptSpeaking

Interrupts the agent's speech.

func interruptSpeaking() -> Bool

enableVoiceInterrupt

Enables or disables smart interruption.

func enableVoiceInterrupt(enable: Bool) -> Bool

Parameter details:

Parameter

Type

Description

enable

Bool

Enables or disables the feature.

switchVoiceId

Switches the voice.

func switchVoiceId(voiceId: String) -> Bool

Parameter details:

Parameter

Type

Description

voiceId

String

Voice ID

enableSpeaker

Enables or disables the speaker.

func enableSpeaker(enable: Bool) -> Bool

Parameter details:

Parameter

Type

Description

enable

Bool

Start/Stop

enablePushToTalk

Enables or disables the push-to-talk mode. In this mode, the agent reports the result only after finishPushToTalk is called.

func enablePushToTalk(enable: Bool) -> Bool

Parameter details:

Parameter

Type

Description

enable

Bool

Disables or enables the mode.

startPushToTalk

Starts speaking in push-to-talk mode.

func startPushToTalk() -> Bool

finishPushToTalk

Stops speaking in push-to-talk mode.

func finishPushToTalk() -> Bool

cancelPushToTalk

Cancels the current speech in push-to-talk mode.

func cancelPushToTalk() -> Bool

muteMicrophone

Mutes or unmutes the microphone.

func muteMicrophone(mute: Bool) -> Bool

Parameter details:

Parameter

Type

Description

mute

Bool

Mutes or unmutes the microphone.

muteAgentAudioPlaying

Stops or resumes the playback of the agent's audio stream.

func muteAgentAudioPlaying(mute: Bool) -> Bool

Parameter details:

Parameter

Type

Description

mute

Bool

Specifies whether to mute the playback.

visionConfig

This parameter must be set when you use a visual agent and takes effect only when it is set before the call. The visual configuration includes the resolution and frame rate. For more information, see ARTCAICallVisionConfig.

var visionConfig: ARTCAICallVisionConfig { set get }

muteLocalCamera

Disables or enables the camera.

func muteLocalCamera(mute: Bool) -> Bool

Parameter details:

Parameter

Type

Description

mute

Bool

Disables or enables mute.

switchCamera

Switches between the front and rear cameras.

func switchCamera() -> Bool

parseShareAgentCall

Parses the information of a shared agent. On success, returns an ARTCAICallAgentShareConfig instance that you can use to start a shared agent call.

func parseShareAgentCall(shareInfo: String) -> ARTCAICallAgentShareConfig?

Parameter details:

Parameter

Type

Description

shareInfo

String

The information of the shared agent, which can be generated in the console.

generateShareAgentCall

Starts a shared agent call.

func generateShareAgentCall(shareConfig: ARTCAICallAgentShareConfig, userId: String, completed: ((_ rsp: ARTCAICallAgentInfo?, _ token: String?, _ error: NSError?, _ reqId: String) -> Void)?)

Parameter details:

Parameter

Type

Description

shareConfig

ARTCAICallAgentShareConfig

The configuration of the shared agent, including the share ID, agent type, time-to-live (TTL), template configuration, and region. You can view the definition in the SDK.

userId

String

The ID of the currently logged-on user.

completed

((_ rsp: ARTCAICallAgentInfo?, _ token: String?, _ error: NSError?, _ reqId: String) -> Void)?

The event for operation completion.

getRTCInstance

Obtain the RTC engine.

func getRTCInstance() -> AnyObject?

sendTextToAgent

Sends a text message to the agent.

func sendTextToAgent(req: ARTCAICallSendTextToAgentRequest) -> Bool

Parameter details:

Parameter

Type

Description

req

ARTCAICallSendTextToAgentRequest

The message struct to send.

sendCustomMessageToServer

Sends a custom message to the server. Must be called after the call is connected.

func sendCustomMessageToServer(msg: String) -> Bool

Parameter details:

Parameter

Type

Description

msg

String

The content to send.

updateLlmSystemPrompt

Updates the system prompt for the large language model (LLM). Must be called after the call is connected.

func updateLlmSystemPrompt(prompt: String) -> Bool

Parameter details:

Parameter

Type

Description

prompt

String

The prompt.

updateBailianAppParams

Updates the parameters for Alibaba Cloud Model Studio.

func updateBailianAppParams(params: [String: Any]) -> Bool

Parameter details:

Parameter

Type

Description

params

[String: Any]

The parameters for Alibaba Cloud Model Studio.

updateVcrConfig

Updates the Video Content Recognition (VCR) configuration.

 func updateVcrConfig(vcrConfig: ARTCAICallAgentVcrConfig) -> Bool

Parameter details:

Parameter

Type

Description

vcrConfig

ARTCAICallAgentVcrConfig

VCR configuration.

startVisionCustomCapture

Starts custom frame capture for a visual understanding agent. After this is started, voice interaction is disabled. Must be called after the call is connected.

func startVisionCustomCapture(req: ARTCAICallVisionCustomCaptureRequest) -> Bool

Parameter details:

Parameter

Type

Description

req

ARTCAICallVisionCustomCaptureRequest

The configuration information.

stopVisionCustomCapture

Stops custom frame capture for a visual understanding agent. Must be called after the call is connected.

func stopVisionCustomCapture() -> Bool

updateAsrMaxSilence

Updates the threshold for voice activity detection. A period of silence longer than this threshold is considered a sentence break.

func updateAsrMaxSilence(duration: Int32) -> Bool

Parameter details:

Parameter

Type

Description

duration

Int32

The duration in milliseconds. The value ranges from 200 ms to 1200 ms.

updateTtsSpeechRate

Updates the Text-to-Speech (TTS) playback speed. All TTS types are supported. The value ranges from 0.5 to 2.0.

func updateTtsSpeechRate(rate: Double) -> Bool

Parameter details:

Parameter

Type

Description

rate

Double

The speech rate. The value ranges from 0.5 to 2.0.

createRTCEngine

Creates an ARTC engine in advance. If not called, the engine is created when the call starts.

func createRTCEngine()

destroy

Releases resources.

func destroy()

ARTCAICallEngineDelegate details

onErrorOccurs

The call encountered an error.

@objc optional func onErrorOccurs(code: ARTCAICallErrorCode)

Parameter details:

Parameter

Type

Description

code

ARTCAICallErrorCode

The error type.

onAgentStarted

The Call Agent is now running.

@objc optional func onAgentStarted()

onCallBegin

The call has started.

@objc optional func onCallBegin()

onCallEnd

Call ended

@objc optional func onCallEnd()

onAgentVideoAvailable

Is the agent video active?

@objc optional func onAgentVideoAvailable(available: Bool)

Parameter details:

Parameter

Type

Description

available

Bool

Available

onAgentAudioAvailable

Is the agent's audio active?

@objc optional func onAgentAudioAvailable(available: Bool)

Parameter details:

Parameter

Type

Description

available

Bool

Indicates whether the audio is available.

onRTCEngineCreated

This callback is triggered when the ARTC engine is created. You can call getRTCInstance in this callback to retrieve the ARTC engine instance.

@objc optional func onRTCEngineCreated()

onPushToTalk

Specifies whether walkie-talkie mode is enabled for the current call.

@objc optional func onPushToTalk(enable: Bool)

Parameter details:

Parameter

Type

Description

enable

Bool

Indicates whether the mode is enabled.

onAgentWillLeave

The current agent is about to end the call.

@objc optional func onAgentWillLeave(reason: Int32, message: String)

Parameter details:

Parameter

Type

Description

reason

Int32

The reason for leaving: 2001 (idle exit) or 0 (other).

message

String

The description of the reason for leaving.

onReceivedAgentCustomMessage

This callback is triggered when a custom message is received from the current agent.

@objc optional func onReceivedAgentCustomMessage(data: [String: Any]?)

Parameter details:

Parameter

Type

Description

data

[String: Any]?

The message content.

onAgentStateChanged

Agent status changes

@objc optional func onAgentStateChanged(state: ARTCAICallAgentState)

Parameter details:

Parameter

Type

Description

state

ARTCAICallAgentState

The current state of the agent: listening, thinking, or speaking.

onNetworkStatusChanged

Network state changes

@objc optional func onNetworkStatusChanged(uid: String, quality: ARTCAICallNetworkQuality)

Parameter details:

Parameter

Type

Description

uid

String

The ID of the current speaker.

quality

ARTCAICallNetworkQuality

The network quality, including excellent, good, fair, poor, very poor, disconnected, and unknown.

onVoiceVolumeChanged

A notification of a volume change.

@objc optional func onVoiceVolumeChanged(uid: String, volume: Int32)

Parameter details:

Parameter

Type

Description

uid

String

The UID of the current speaker.

volume

Int32

The volume, ranging from 0 to 255.

onUserSubtitleNotify

A notification that the user's question is recognized by the agent.

@objc optional func onUserSubtitleNotify(text: String, isSentenceEnd: Bool, sentenceId: Int)

Parameter details:

Parameter

Type

Description

text

String

The question text recognized by the agent.

isSentenceEnd

Bool

Indicates whether the current text is the final result for this sentence.

sentenceId

Int

The ID of the sentence to which the current text belongs.

onVoiceAgentSubtitleNotify

A notification of the agent's response.

@objc optional func onVoiceAgentSubtitleNotify(text: String, isSentenceEnd: Bool, userAsrSentenceId: Int)

Parameter details:

Parameter

Type

Description

text

String

The response text from the agent.

isSentenceEnd

Bool

Indicates whether the current text is the last sentence of this response.

userAsrSentenceId

Int

The ID of the sentence that answers the user's question.

onLLMReplyCompleted

The LLM has completed its response.

@objc optional func onLLMReplyCompleted(text: String, userAsrSentenceId: Int)

Parameter details:

Parameter

Type

Description

text

String

The text output by the LLM.

userAsrSentenceId

Int

The ID of the sentence that answers the user's question.

onVoiceIdChanged

The tone for the current call has changed.

@objc optional func onVoiceIdChanged(voiceId: String)

Parameter details:

Parameter

Type

Description

voiceId

String

The current voice ID.

onVoiceInterrupted

Indicates whether voice barge-in is enabled for the current call.

@objc optional func onVoiceInterrupted(enable: Bool)

Parameter details:

Parameter

Type

Description

enable

Bool

Indicates whether the feature is enabled.

onSpeakingInterrupted

The agent has been interrupted.

@objc optional func onSpeakingInterrupted(reason: ARTCAICallSpeakingInterruptedReason)

Parameter details:

Parameter

Type

Description

reason

ARTCAICallSpeakingInterruptedReason

The reason, such as interruption by a specific word.

onVisionCustomCapture

This callback indicates whether custom frame capture mode is enabled for the current visual understanding call.

@objc optional func onVisionCustomCapture(enable: Bool)

Parameter details:

Parameter

Type

Description

enable

Bool

Indicates whether the mode is enabled.

onAgentAvatarFirstFrameDrawn

Agent digital human: First-frame rendering

@objc optional func onAgentAvatarFirstFrameDrawn()

onHumanTakeoverWillStart

When a human agent is about to take over

@objc optional func onHumanTakeoverWillStart(takeoverUid: String, takeoverMode: Int)

Parameter details:

Parameter

Type

Description

takeoverUid

String

The UID of the human.

takeoverMode

Int

1: indicates that the human's voice is used for output. 0: indicates that the agent's voice is used for output.

onHumanTakeoverConnected

This callback is triggered when the human takeover is connected.

@objc optional func onHumanTakeoverConnected(takeoverUid: String)

Parameter details:

Parameter

Type

Description

takeoverUid

String

The UID of the human.

onAgentEmotionNotify

A notification of the agent's emotion.

@objc optional func onAgentEmotionNotify(emotion: String, userAsrSentenceId: Int)

Parameter details:

Parameter

Type

Description

emotion

String

The emotion label, such as neutral, happy, angry, or sad.

userAsrSentenceId

Int

The ID of the sentence that answers the user's question.

onAgentDataChannelAvailable

A callback for the availability of the agent's message channel. After this callback is triggered, you can send messages to the agent.

@objc optional func onAgentDataChannelAvailable()

onReceivedAgentVcrResult

This callback is triggered when a VCR result is received from the current agent. For more information, see ARTCAICallAgentVcrResult.

@objc optional func onReceivedAgentVcrResult(result: ARTCAICallAgentVcrResult)

onConnectionStatusChange

The connection status can change during a call.

@objc optional func onConnectionStatusChange(status: ARTCAICallConnectionStatus, reason: Int32)

Parameter details:

Parameter

Type

Description

status

ARTCAICallConnectionStatus

The status code:

  • Init: The initialization is complete.

  • Disconnected: The network connection is disconnected.

  • Connecting: A network connection is being established.

  • Connected: The network is connected.

  • Reconnecting: The network connection is being re-established.

  • Failed: The network connection failed.

reason

Int

Cause

onAudioDelayInfo

Audio loopback latency.

@objc optional func onAudioDelayInfo(sentenceId: Int32, delayMs: Int64)

Parameter details:

Parameter

Type

Description

sentenceId

Int32

The sentence ID.

delayMs

Int64

The audio loopback latency in milliseconds.

onAudioAccompanyStateChanged

If you play background music through the ARTC instance during the current call, this playback callback is triggered.

 @objc optional func onAudioAccompanyStateChanged(state: ARTCAICallAudioAccompanyState, errorCode: ARTCAICallAudioAccompanyErrorCode)

Parameter details:

Parameter

Type

Description

state

ARTCAICallAudioAccompanyState

The playback state of the background music:
• ARTCAICallAudioAccompanyStarted (100): Playback starts.
• ARTCAICallAudioAccompanyStopped (101): Playback stops.
• ARTCAICallAudioAccompanyPaused (102): Playback is paused.
• ARTCAICallAudioAccompanyResumed (103): Playback resumes.
• ARTCAICallAudioAccompanyEnded (104): Playback is complete.
• ARTCAICallAudioAccompanyBuffering (105): Buffering.
• ARTCAICallAudioAccompanyBufferingEnd (106): Buffering ends.
• ARTCAICallAudioAccompanyFailed (107): Playback failed.




















































errorCode

ARTCAICallAudioAccompanyErrorCode

The playback error code:
• ARTCAICallAudioAccompanyNoError (0): No error.
• ARTCAICallAudioAccompanyUnknowError (-1): An unknown error occurred.
• ARTCAICallAudioAccompanyOpenFailed (-100): Failed to open the file.
• ARTCAICallAudioAccompanyDecodeFailed (-101): Failed to decode the file.
























ARTCAICallEngineFactory details

createEngine

Creates a default engine instance.

public static func createEngine() -> ARTCAICallEngineInterface