实时数字人会话接入指南

更新时间:
复制为 MD 格式

该文档详细说明了通过万相数字人平台创建实时数字人会话的步骤,包括获取项目ID、license和实例ID,并提供了SDK集成与示例代码。

操作流程

  1. 在万相数字人控制台获取对话数字人的项目ID。

  2. 获取万相数字人平台颁发的license。

  3. 获取数字人实时交互服务对应的实例ID。

  4. 依据获取的参数,通过创建实时数字人会话接口获取入会信息。

1 获取对话数字人项目ID

使用API创建实时数字人会话前,需前往万相数字人控制台对话互动页面获取对话数字人项目ID:

image

重要

如果官方形象无法满足需求,可参考数字人实时对话创建自定义数字人形象,需要注意的是:在创建实时数字人会话前,需要保证形象处于创建完成状态,否则会导致会话创建失败。

2 获取万相数字人平台颁发的license

说明

该字段非必传字段,仅在使用端渲染数字人的场景下必填。

通过API创建实时数字人会话时,需要获取万相数字人平台颁发的license,具体获取方式如下:

image

3 获取订单实例ID

该参数需要在数字人实时交互服务页面完成对应的服务购买,如果已经完成购买,当前拥有可用服务时,前往阿里云-我的订单页面对应详情下进行查询。

3.1 购买服务

image

3.2 查询实例ID

image

4 通过创建实时数字人会话接口获取入会信息

通过上述步骤获取到接口所需参数后,调用创建实时数字人会话接口可以获取到入会所需信息,即返回结果中的 rtcParams,后续需要根据该结果,通过具体的SDK请求入会,拉取推流信息。具体参考文档:数字人对话AndroidSDK数字人对话IOS SDK数字人对话WebSDK

实时数字人会话完整调用实例代码

引入SDK

<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>lingmou20250527</artifactId>
    <!-- 请将 'the-latest-version' 替换为最新版本号:https://mvnrepository.com/artifact/com.aliyun/lingmou20250527 -->
    <version>${the-latest-version:1.6.0}</version>
</dependency>

示例代码

import com.aliyun.tea.*;

public class Sample {

    /**
     * <b>description</b> :
     * <p>使用凭据初始化账号Client</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.lingmou20250527.Client createClient() throws Exception {
        // 工程代码建议使用更安全的无AK方式,凭据配置方式请参见:https://help.aliyun.com/document_detail/378657.html。
        com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setCredential(credential);
        // Endpoint 请参考 https://api.aliyun.com/product/LingMou
        config.endpoint = "lingmou.cn-beijing.aliyuncs.com";
        return new com.aliyun.lingmou20250527.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        
        com.aliyun.lingmou20250527.Client client = Sample.createClient();
        com.aliyun.lingmou20250527.models.CreateChatSessionRequest createChatSessionRequest = new com.aliyun.lingmou20250527.models.CreateChatSessionRequest()
                // 替换为具体的参数值
                .setLicense("license")
                .setPlatform("platform")
                .setInstanceId("instanceId");
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        try {
            // id 为获取到的数字人项目ID.
            com.aliyun.lingmou20250527.models.CreateChatSessionResponse resp = client.createChatSessionWithOptions("id", createChatSessionRequest, headers, runtime);
            System.out.println(new com.google.gson.Gson().toJson(resp));
        } catch (TeaException error) {
            // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
        }        
    }
}