This topic describes how to use AICallKit SDK to create and initialize an engine instance, as well as how to start and end a call.
Flowchart

Before calling the call()
method, you must start a call instance by calling the GenerateAIAgentCall operation.
Perform the following steps:
Create an engine instance and use it as a member variable.
Configure callbacks.
Initialize the configurations, including whether to disable the microphone, enable the handset, and use the front camera.
Configure call settings:
Set the rendering view if a digital human agent is used.
Set the preview screen and mode if a visual understanding agent is used.
Sample code
ARTCAICallEngine mARTCAICallEngine = null;
void setupEngine(Context context) {
mARTCAICallEngine = new ARTCAICallDepositEngineImpl(context, userId);
mARTCAICallEngine.setEngineCallback(mCallEngineCallbackWrapper);
ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig();
artcaiCallConfig.aiAgentId = aiAgentId;
mARTCAICallEngine.init(artcaiCallConfig);
mARTCAICallEngine.setAiAgentType(aiAgentType);
if (aiAgentType == AvatarAgent) {
mARTCAICallEngine.setAvatarAgentView(
avatarlayer,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)
);
}
else if (aiAgentType == VisionAgent) {
mARTCAICallEngine.setVisionPreviewView(previewLayer,
new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT)
);
}
}
void start() {
mARTCAICallEngine.call(rtc_auth_token, agent_instance_id,
ai_agent_user_id, channle_id);
}
void handup() {
mARTCAICallEngine.handup();
}
ARTCAICallEngine.IARTCAICallEngineCallback mCallEngineCallbackWrapper = new ARTCAICallEngine.IARTCAICallEngineCallback() {
@Override
public void onErrorOccurs(ARTCAICallEngine.AICallErrorCode errorCode) {
mARTCAICallEngine.handup();
}
@Override
public void onCallBegin() {
}
@Override
public void onCallEnd() {
}
};
import ARTCAICallKit
let engine = ARTCAICallEngineFactory.createEngine()
let agentType: ARTCAICallAgentType
let userId: String
deinit {
self.engine.destroy()
}
public func setup() {
self.engine.delegate = self
if self.agentType == .AvatarAgent {
let viewConfig = ARTCAICallViewConfig(view: self.avatarAgentView)
self.engine.setAgentViewConfig(viewConfig: viewConfig)
}
else if self.agentType == .VisionAgent {
let visionConfig = ARTCAICallVisionConfig(preview: self.visionCameraView, viewMode: .Auto, frameRate: 5, bitrate: 340)
self.engine.visionConfig = visionConfig
}
}
public func start() {
let agentInfo = ARTCAICallAgentInfo(agentType: self.agentType, channelId: channel_id, uid: ai_agent_user_id, instanceId: agent_instance_id)
self.engine.call(userId: self.userId, token: rtc_auth_token, agentInfo: agentInfo) { [weak self] error in
if let error = error {
}
else {
}
}
}
public func handup() {
self.engine.handup(true)
}
func onErrorOccurs(code: ARTCAICallErrorCode) {
self.engine.handup()
}
func onCallBegin() {
}
func onCallEnd() {
}
import ARTCAICallEngine from 'aliyun-auikit-aicall';
let engine;
const setup = () => {
engine = new ARTCAICallEngine();
engine.on('errorOccurred', (errorCode) => {
engine.handup();
console.error('AICallErrorOccurred', errorCode);
});
engine.on('callBegin', () => {
console.log('AICallBegin');
});
engine.on('callEnd', () => {
console.log('AICallEnd');
});
};
const start = async () => {
try {
engine.call(
userId,
agentInfo,
config
);
} catch (error) {
}
};
const handup = () => {
engine.handup();
};