Integrate with Android apps

Updated at: 2025-03-05 09:19

This topic describes how to integrate AICallKit SDK with your Android app.

Environment requirements

  • Android Studio plug-in V4.1.3

  • Gradle 7.0.2

  • Java Development Kit (JDK) 11 in Android Studio

Integrate the SDK

  1. Add the URLs of the Alibaba Cloud Maven repository to the build.gradle file of your project.

    allprojects {
        repositories {
            google()
            jcenter()
            maven { url 'https://maven.aliyun.com/repository/google' }
            maven { url 'https://maven.aliyun.com/repository/public' }
        }
    }
  2. Add the ARTCAICallKit dependency to the build.gradle file of your project.

    dependencies {
        implementation 'com.aliyun.aio:AliVCSDK_ARTC:x.x.x'                  // Replace x.x.x with a version that is adapted to your project.
        implementation 'com.aliyun.auikits.android:ARTCAICallKit:1.4.0'
    }
    Note

    You can go to the official website to download ARTC SDK of the latest version.

Sample code for using the SDK

ARTCAICallEngine mARTCAICallEngine = null;

// Create an engine instance.
void initEngine(Context context, String userId) {
    // Initialize the engine instance.
    // context -> Android Context
    // userId -> The ID of the user who joins the Real-Time Communication (RTC) channel.
    mARTCAICallEngine = new ARTCAICallDepositEngineImpl(context, userId);   
}

// Configure callback events.
void initCallback() {
    mARTCAICallEngine.setEngineCallback(mCallEngineCallbackWrapper); 
}

// Start a call after an intelligent agent is started.
void call() {
    // Configure the startup parameters of the engine.
    ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig = new ARTCAICallEngine.ARTCAICallConfig();
    // Specify a temporary intelligent agent ID, if required.
    artcaiCallConfig.aiAgentId = aiAgentId;
    mARTCAICallEngine.init(artcaiCallConfig);
    
    // Specify the type of the intelligent agent, such as voice agent, digital human agent, or visual understanding agent.
    ARTCAICallEngine.ARTCAICallAgentType aiAgentType = VoiceAgent;
    mARTCAICallEngine.setAiAgentType(aiAgentType);

    // Configure a view if a digital human agent is used.
    if (aiAgentType == AvatarAgent) {
        ViewGroup avatarlayer;
        mARTCAICallEngine.setAvatarAgentView(
            avatarlayer,
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                       ViewGroup.LayoutParams.MATCH_PARENT)
        );
    }
    // Configure a view for local video preview if a visual understanding agent is used.
    else if (aiAgentType == VisionAgent) {
        ViewGroup previewLayer;
        mARTCAICallEngine.setVisionPreviewView(previewLayer,
            new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                         ViewGroup.LayoutParams.MATCH_PARENT)
        );
    }

    // Join a channel.
    String aIAgentInstanceId = "XXX";
    String rtcAuthToken = "XXX";
    String aIAgentUserId = "XXX";
    String channelId = "XXX";
    mARTCAICallEngine.call(rtcAuthToken, aIAgentInstanceId, 
                           aIAgentUserId, channelId);
}

// End the call.
void handup() {
    mARTCAICallEngine.handup();
}

// For more information about how to call other API operations, see the "API reference" section of this topic.

// The callback events. The following examples include only callback events that do not require specialized main code.
ARTCAICallEngine.IARTCAICallEngineCallback mCallEngineCallbackWrapper = new ARTCAICallEngine.IARTCAICallEngineCallback() {
    @Override
    public void onErrorOccurs(ARTCAICallEngine.AICallErrorCode errorCode) {
        // An error occurs and the call ends.
        mARTCAICallEngine.handup();
    }

    @Override
    public void onCallBegin() {
        // The call starts and the user joins the meeting.
    }

    @Override
    public void onCallEnd() {
        // The call ends and the user leaves the meeting.
    }

    @Override
    public void onAICallEngineRobotStateChanged(ARTCAICallEngine.ARTCAICallRobotState oldRobotState, ARTCAICallEngine.ARTCAICallRobotState newRobotState) {
        // The status of the intelligent agent changes.
    }

    @Override
    public void onUserSpeaking(boolean isSpeaking) {
        // Indicate whether the user is speaking.
    }

    @Override
    public void onUserAsrSubtitleNotify(String text, boolean isSentenceEnd, int sentenceId) {
        // The speech of the user is recognized by automatic speech recognition (ASR).
    }

    @Override
    public void onAIAgentSubtitleNotify(String text, boolean end, int userAsrSentenceId) {
        // The intelligent agent returns a response.
    }

    @Override
    public void onNetworkStatusChanged(String uid, ARTCAICallEngine.ARTCAICallNetworkQuality quality) {
        // The network status changes.
    }

    @Override
    public void onVoiceVolumeChanged(String uid, int volume) {
        // The voice volume changes.
    }

    @Override
    public void onVoiceIdChanged(String voiceId) {
        // The voice tone of the current call changes.
    }

    @Override
    public void onVoiceInterrupted(boolean enable) {
        // Indicate whether intelligent interruption is enabled for the current call.
    }

    @Override
    public void onAgentVideoAvailable(boolean available) {
        // Indicate whether the ingested video stream of the intelligent agent is available.
    }

    @Override
    public void onAgentAudioAvailable(boolean available) {
        // Indicate whether the ingested audio stream of the intelligent agent is available.
    }
    
    @Override
    public void onAgentAvatarFirstFrameDrawn() {
        // Render the first frame of the digital human video.
    }

    @Override
    public void onUserOnLine(String uid) {
        // Indicate whether the user is online.
    }

};

API reference

Overview

Category

Operation

Description

ARTCAICallEngine

Engine definition

init

Initializes an engine instance.

setAICallAgentType

Specifies the type of an intelligent agent.

call

Creates and starts a call.

handup

Ends a call.

switchMicrophone

Changes the microphone status.

interruptSpeaking

Interrupts the speech of an intelligent agent.

enableVoiceInterrupt

Enables or disables intelligent interruption.

enableSpeaker

Enables or disables the speaker.

enablePushToTalk

Enables or disables the intercom mode.

isPushToTalkEnable

Checks whether the intercom mode is enabled.

startPushToTalk

Starts a speech in intercom mode.

finishPushToTalk

Ends a speech in intercom mode.

cancelPushToTalk

Cancels a speech in intercom mode.

switchRobotVoice

Changes the voice tone.

getRobotVoiceId

Queries the voice tone in use.

setEngineCallback

Configures callback events.

isMicrophoneOn

Checks whether the microphone is enabled.

isSpeakerOn

Checks whether the speaker is enabled.

isVoiceInterruptEnable

Checks whether intelligent interruption is enabled.

setAvatarAgentView

Configures a view for a digital human agent.

setVisionPreviewView

Configures a view for local video preview.

muteLocalCamera

Turns on or off a camera.

isLocalCameraMute

Checks whether a camera is turned off.

switchCamera

Switches between the front camera and the rear camera.

getRtcEngine

Queries the information about an RTC engine instance.

getIARTCAICallService

Queries the implementation class of the official protocol.

IARTCAICallEngineCallback

Callback event

onErrorOccurs

An error occurs.

onCallBegin

A call starts.

onCallEnd

A call ends.

onAICallEngineRobotStateChanged

The status of an intelligent agent changes.

onUserSpeaking

A user is speaking.

onUserAsrSubtitleNotify

The speech of a user is recognized by ASR.

onAIAgentSubtitleNotify

An intelligent agent returns a response.

onNetworkStatusChanged

The network status changes.

onVoiceVolumeChanged

The voice volume changes.

onVoiceIdChanged

The voice tone of the current call changes.

onVoiceInterrupted

The status of intelligent interruption changes.

onAgentVideoAvailable

The first video frame of an intelligent agent is ingested.

onAgentAudioAvailable

The first audio frame of an intelligent agent is ingested.

onAgentAvatarFirstFrameDrawn

The first frame of a digital human video is rendered.

onUserOnLine

A user is online.

onAgentWillLeave

The current intelligent agent is leaving and the call ends.

onReceivedAgentCustomMessage

A custom message is received from an intelligent agent.

IARTCAICallService

generateAIAgentShareCall

Initiates a request to start a call with a shared intelligent agent.

ARTCAIAgentUtil

parseAiAgentShareInfo

Parses the information about a shared intelligent agent.

parseAiAgentInfo

Parses the response of an intelligent agent when the intelligent agent is started.

ARTCAICallEngine

init

Initializes an engine instance.

/**
 * Initialize an engine instance.
 * @param config The configurations to be initialized.
 */
public abstract void init(ARTCAICallConfig config);

setAICallAgentType

Specifies the type of an intelligent agent.

/**
 * Specify the type of an intelligent agent.
 * @param aiAgentType
 */
public abstract void setAICallAgentType(ARTCAICallAgentType aiAgentType);

call

Creates and starts a call.

/**
 * Create and start a call.
 */
public abstract void call(String rtcToken, String aiAgentInstanceId, String aiAgentUserId, String channelId);

handup

Ends a call.

/**
 * End a call.
 */
public abstract void handup();

switchMicrophone

Changes the microphone status.

/**
 * Change the microphone status.
 * @param on
 */
public abstract void switchMicrophone(boolean on);

interruptSpeaking

Interrupts the speech of an intelligent agent.

/**
 * Interrupt the speech of an intelligent agent.
 */
public abstract boolean interruptSpeaking();

enableVoiceInterrupt

Enables or disables intelligent interruption.

/**
 * Enable or disable intelligent interruption.
 */
public abstract boolean enableVoiceInterrupt(boolean enable);

enableSpeaker

Enables or disables the speaker.

/**
 * Enable or disable the speaker.
 */
public abstract boolean enableSpeaker(boolean enable);

enablePushToTalk

Enables or disables the intercom mode.

/**
 * Enable or disable the intercom mode. In intercom mode, the intelligent agent returns a result only after the finishPushToTalk operation is called.
 * @param enable
 * @return
 */
public abstract boolean enablePushToTalk(boolean enable);

isPushToTalkEnable

Checks whether the intercom mode is enabled.

/**
 * Check whether the intercom mode is enabled.
 * @return
 */
public abstract boolean isPushToTalkEnable();

startPushToTalk

Starts a speech in intercom mode.

/**
 * Start a speech in intercom mode.
 * @return
 */
public abstract boolean startPushToTalk();

finishPushToTalk

Ends a speech in intercom mode.

/**
 * End a speech in intercom mode.
 * @return
 */
public abstract boolean finishPushToTalk();

cancelPushToTalk

Cancels a speech in intercom mode.

/**
 * Cancel a speech in intercom mode.
 * @return
 */
public abstract boolean cancelPushToTalk();

switchRobotVoice

Changes the voice tone.

/**
 * Change the voice tone.
 */
public abstract boolean switchRobotVoice(String voiceId);

getRobotVoiceId

Queries the voice tone in use.

/**
 * Query the voice tone in use.
 * @return
 */
public abstract String getRobotVoiceId();

setEngineCallback

Configures callback events.

/**
 * Configure callback events.
 * @param engineCallback
 */
public abstract void setEngineCallback(IARTCAICallEngineCallback engineCallback);

isMicrophoneOn

Checks whether the microphone is enabled.

/**
 * Check whether the microphone is enabled.
 * @return
 */
public abstract boolean isMicrophoneOn();

isSpeakerOn

Checks whether the speaker is enabled.

/**
 * Check whether the speaker is enabled.
 * @return
 */
public abstract boolean isSpeakerOn();

isVoiceInterruptEnable

Checks whether intelligent interruption is enabled.

/**
 * Check whether intelligent interruption is enabled.
 * @return
 */
public abstract boolean isVoiceInterruptEnable();

setAvatarAgentView

Configures a view for a digital human agent.

/**
 * Configure a view for a digital human agent.
 * @param viewGroup
 * @param avatarLayoutParams
 */
public abstract void setAvatarAgentView(ViewGroup viewGroup, ViewGroup.LayoutParams avatarLayoutParams);

setVisionPreviewView

Configures a view for local video preview.

/**
 * Configure a view for local video preview.
 * @param viewGroup
 * @param visionLayoutParams
 */
public abstract void setVisionPreviewView(ViewGroup viewGroup, ViewGroup.LayoutParams visionLayoutParams);

muteLocalCamera

Turns on or off a camera.

/**
 * Turn on or off a camera.
 */
public abstract boolean muteLocalCamera(boolean mute);

isLocalCameraMute

Checks whether a camera is turned off.

/**
 * Check whether a camera is turned off.
 * @return
 */
public abstract boolean isLocalCameraMute();

switchCamera

Switches between the front camera and the rear camera.

/**
 * Switch between the front camera and the rear camera.
 */
public abstract boolean switchCamera();

getRtcEngine

Queries the information about an RTC engine instance.

/**
 * Query the information about an RTC engine instance.
 * @return
 */
public abstract AliRtcEngine getRtcEngine();

getIARTCAICallService

Queries the implementation class of the official protocol.

/**
 * Query the implementation class of the official protocol.
 * @return
 */
public abstract IARTCAICallService getIARTCAICallService();

IARTCAICallEngineCallback

onErrorOccurs

An error occurs.

/**
 * An error occurs.
 * @param errorCode The error code.
 */
void onErrorOccurs(AICallErrorCode errorCode);

onCallBegin

A call starts and a user joins the meeting.

/**
 * A call starts and a user joins the meeting.
 */
void onCallBegin();

onCallEnd

A call ends and a user leaves the meeting.

/**
 * A call ends and a user leaves the meeting.
 */
void onCallEnd();

onAICallEngineRobotStateChanged

The status of an intelligent agent changes.

/**
 * The status of an intelligent agent changes.
 * @param oldRobotState
 * @param newRobotState
 */
void onAICallEngineRobotStateChanged(ARTCAICallRobotState oldRobotState, ARTCAICallRobotState newRobotState);

onUserSpeaking

A user is speaking.

/**
 * A user is speaking.
 * @param isSpeaking Indicates whether the user is speaking.
 */
void onUserSpeaking(boolean isSpeaking);

onUserAsrSubtitleNotify

The speech of a user is recognized by ASR.

/**
 * The speech of a user is recognized by ASR.
 * @param text The specific text that is recognized by ASR.
 * @param isSentenceEnd Indicates whether the current text is the end of the sentence.
 * @param sentenceId The ID of the sentence to which the current text belongs.
 */
void onUserAsrSubtitleNotify(String text, boolean isSentenceEnd, int sentenceId);

onAIAgentSubtitleNotify

An intelligent agent returns a response.

/**
 * An intelligent agent returns a response.
 * @param text The response of the intelligent agent.
 * @param end Indicates whether the current response ends.
 * @param userAsrSentenceId The ID of the sentence to which the speech of the user recognized by a large language model (LLM) belongs.
 */
void onAIAgentSubtitleNotify(String text, boolean end, int userAsrSentenceId);

onNetworkStatusChanged

The network status changes.

/**
 * The network status changes.
 * @param uid The ID of the user who joins the meeting.
 * @param quality The network status.
 */
void onNetworkStatusChanged(String uid, ARTCAICallNetworkQuality quality);

onVoiceVolumeChanged

The voice volume changes.

/**
 * The voice volume changes.
 * @param uid The user ID.
 * @param volume The voice volume. Valid values: 0 to 255.
 */
void onVoiceVolumeChanged(String uid, int volume);

onVoiceIdChanged

The voice tone of the current call changes.

/**
 * The voice tone of the current call changes.
 */
void onVoiceIdChanged(String voiceId);

onVoiceInterrupted

The status of intelligent interruption changes.

/**
 * The status of intelligent interruption changes.
 */
void onVoiceInterrupted(boolean enable);

onAgentVideoAvailable

The first video frame of an intelligent agent is ingested.

/**
 * The first video frame of an intelligent agent is ingested.
 */
void onAgentVideoAvailable(boolean available);

onAgentAudioAvailable

The first audio frame of an intelligent agent is ingested.

/**
 * The first audio frame of an intelligent agent is ingested.
 */
void onAgentAudioAvailable(boolean available);

onAgentAvatarFirstFrameDrawn

The first frame of a digital human video is rendered.

/**
* The first frame of a digital human video is rendered.
*/
void onAgentAvatarFirstFrameDrawn();

onUserOnLine

A user is online.

/**
* A user is online.
*/
void onUserOnLine(String uid);

onAgentWillLeave

The current intelligent agent is leaving and the call ends.

/**
 * The current intelligent agent is leaving and the call ends.
 * @param reason The reason for the end of the call. A value of 2001 indicates a session timeout. A value of 0 indicates other reasons.
 @param message The description of the reason.
 */
void onAgentWillLeave(int reason, String message);

onReceivedAgentCustomMessage

A custom message is received from an intelligent agent.

/**
 * A custom message is received from an intelligent agent.
 * @param data The custom message body, which is a JSON string.
 */
public void onReceivedAgentCustomMessage(String data);

IARTCAICallService

generateAIAgentShareCall

Initiates a request to start a call with a shared intelligent agent.

/**
 * Initiate a request to start a call with a shared intelligent agent.
 * @param userId The ID of the current user.
 * @param aiAgentId The ID of the intelligent agent.
 * @param aiAgentType The type of the intelligent agent.
 * @param artcaiCallConfig The configurations of the intelligent agent.
 @param callback The request for a callback.
 */
void generateAIAgentShareCall(String userId, String aiAgentId, ARTCAICallEngine.ARTCAICallAgentType aiAgentType, ARTCAICallEngine.ARTCAICallConfig artcaiCallConfig, IARTCAICallServiceCallback callback);

ARTCAIAgentUtil

parseAiAgentShareInfo

Parses the information about a shared intelligent agent.

/**
 * Parse the information about a shared intelligent agent.
 * @param shareInfoText
 * @return The structured configurations of the shared intelligent agent.
 */
public static ARTCAIAgentShareInfo parseAiAgentShareInfo(String shareInfoText);

parseAiAgentInfo

Parses the response of an intelligent agent when the intelligent agent is started.

/**
 * Parse the response of an intelligent agent when the intelligent agent is started.
 * @param jsonObject The response of the intelligent agent.
 * @return The structured response of the intelligent agent.
 */
public static ARTCAIAgentInfo parseAiAgentInfo(JSONObject jsonObject);
  • On this page (1, O)
  • Environment requirements
  • Integrate the SDK
  • Sample code for using the SDK
  • API reference
  • Overview
  • ARTCAICallEngine
  • IARTCAICallEngineCallback
  • IARTCAICallService
  • ARTCAIAgentUtil
Feedback
phone Contact Us

Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

alicare alicarealicarealicare