Android User Guide

更新时间:
复制 MD 格式

Integrate Real-time Conversational AI audio and video agents into your Android application.

Source Code Overview

Download the Source Code

Download the source code from the GitHub open source project.

Source Code Structure

├── Android       		// Root directory of the Android project
│   ├── AUIBaseKits     // AUI base components
│   ├── AUIAICall       // UI components
│   ├── README.md
│   ├── app             // Demo entry point
│   ├── build.gradle  
│   └── settings.gradle

Environment Requirements

  • Android Studio plugin version 4.1.3

  • Gradle 7.0.2

  • JDK 11 bundled with Android Studio

Prerequisites

You must have developed the required APIs on your server or deployed the provided server source code. For more information, see Project deployment.

Run the Demo

  1. After you download the source code, open the Android folder in Android Studio.

  2. Open the project file build.gradle and update the package ID.

  3. Open the agent scene configuration file /AUIAICall/src/main/assets/AgentConfig/agent_scenes.json. In this file, enter the agent ID and region based on your agent type. For example, to configure a voice agent, locate the Scenes node where agent_type is VoiceAgent, and then set the values for the agent_id and region fields.

    // The following example shows how to configure a voice call agent
        {
          "agent_type": "VoiceAgent",
          "scenes": [
            {
              "agent_id": "<Voice call agent ID>",
              "region": "<Region of the voice call agent ID>",
              "title": "Voice Call",
              "tags": [],
              "limit_seconds": 1800,
              "description": "",
              "asr_model_id": "xxx",
              "tts_model_id": "xxx",
              "voice_styles": []
            }
          ]
        }
    Note

    If you want to test only one type of agent, you only need to set the agent_id and region fields for that agent type. For the region field, use one of the Region ID values listed in the table below.

    Region Name

    Region ID

    China (Hangzhou)

    cn-hangzhou

    China (Shanghai)

    cn-shanghai

    China (Beijing)

    cn-beijing

    China (Shenzhen)

    cn-shenzhen

    Singapore

    ap-southeast-1

  4. After the agent configuration is complete, you can start the agent in one of the following two ways:

    • AppServer already deployed: If you have deployed the AppServer source code provided by Alibaba Cloud on your server, open the AppServiceConst.java file and update the server domain name.

      // AppServiceConst.java
      String HOST = "your application server domain name";
    • AppServer not deployed: If you have not deployed the AppServer source code but want to quickly run the demo to test the agent, open the AUIAICallAuthTokenHelper.java file. Set the EnableDevelopToken parameter to `true`, and then copy the ARTC App ID and App Key from the console. This configuration generates an authentication token on the client side for testing purposes.

      Important

      This method requires you to enter sensitive information, such as the AppKey, locally. This method is suitable only for testing and development. It must not be used in production to prevent security risks that can result from a leaked AppKey.

      // AUIAICallAuthTokenHelper.java
      public class AUIAICallAuthTokenHelper {
          // Set to true to enable Develop mode
          private static final boolean EnableDevelopToken = true;
      
          // Copy the RTC AppId for audio and video calls from the console
          private static final String AICallRTCDevelopAppId = "RTC AppId used by the agent";
          // Copy the RTC AppKey for audio and video calls from the console
          private static final String AICallRTCDevelopAppKey = "RTC AppKey used by the agent";
      }

      Follow these steps to obtain the AppId and AppKey for your ARTC application:

      1. Go to the IMS console and click your AI agent to open its details page.

        On the Basic Information tab, find the Workflow Configuration section and note the RTC App ID listed under ARTC application.

      2. Click the RTC App ID to open the ApsaraVideo Live console and get the App ID and AppKey.

        On the Application Management page, click your application name, go to the Basic Information tab, and copy the App ID and AppKey.

Quickly Develop Your Own AI Calling Feature

Quickly integrate AUIAICall into your app to add agent-based audio and video calling.

Integrate the Source Code

  1. Import AUIAICall: After you download the source code from the repository, open Android Studio. Then, choose File > New > Import Module and import the AUIAICall and AUIBaseKits folders.

  2. In the build.gradle file of the imported module, update the third-party library dependencies.

    dependencies {
        implementation 'androidx.appcompat:appcompat:x.x.x'                     // Replace x.x.x with your project's compatible version
        implementation 'com.google.android.material:material:x.x.x'             // Replace x.x.x with your project's compatible version
        androidTestImplementation 'androidx.test.espresso:espresso-core:x.x.x'  // Replace x.x.x with your project's compatible version
        implementation 'com.aliyun.aio:AliVCSDK_ARTC:x.x.x'                  // Replace x.x.x with your project's compatible version
        implementation 'com.aliyun.auikits.android:ARTCAICallKit:x.x.x'
        implementation 'com.alivc.live.component:PluginAEC:2.0.0'
    }
    Note
    • Latest ARTC SDK version: 7.10.0

    • Latest AICallKit SDK version: 2.11.0

  3. Wait for the Gradle sync to complete. The source code is now integrated.

Source Code Configuration

  • You have completed the prerequisite steps.

  • Open the AppServiceConst.java file and update the server domain name.

    // AppServiceConst.java
    String HOST = "your application server domain name";
    Note

    If you have not deployed AppServer, you can generate an authentication token on the client side to quickly test and run the demo. For more information, see AppServer not deployed.

Call the API

After you complete the preceding steps, call the component API from another module or your application's homepage to start an AI call. Modify the source code as needed for your business scenario.

/** Ensure microphone and camera permissions are granted before starting */
Context currentActivity = AUIAICallEntranceActivity.this;
Intent intent = new Intent(currentActivity, AUIAICallInCallActivity.class);

// Set the call type (voice, digital human, or visual understanding). This must match the agent ID type.
ARTCAICallEngine.ARTCAICallAgentType aiCallAgentType = 
    ARTCAICallEngine.ARTCAICallAgentType.VoiceAgent;
// Agent ID. Must not be empty.
String aiAgentId = "";
// Region where the agent is located. Must not be empty.
String aiAgentRegion = "";
// User ID for joining the RTC session. We recommend using your business login user ID.
String userId = "123";
// Call authentication token. See: https://help.aliyun.com/zh/ims/user-guide/generate-artc-authentication-token?spm=a2c4g.11186623.0.0.1ce65bc4BKdQy7
String token = "";

intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_LOGIN_USER_ID, userId);
// Agent type
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_TYPE, aiCallAgentType);
// Agent ID
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_ID, aiAgentId);
// Agent region
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_AI_AGENT_REGION, aiAgentRegion);
// Set the call authentication token
intent.putExtra(AUIAIConstStrKey.BUNDLE_KEY_RTC_AUTH_TOKEN, token);

currentActivity.startActivity(intent);
Note

For more information about how to generate the call authentication token, see Generate an ARTC authentication token.