全部產品
Search
文件中心

Intelligent Media Services:語音播報

更新時間:Aug 07, 2025

本文將為您介紹在音視訊通話中如何傳入文本進行語音播報。

功能描述

語音播報允許您通過調用OpenAPI介面,將需要播報的常值內容作為參數傳入。用戶端在接收到傳入的常值內容後,即刻啟動語音合成技術,將文本轉化為語音並進行播報,使得資訊以語音形式清晰傳達給使用者。

應用情境

在智能家居裝置應用情境中,如智能傢具裝置,使用者通過手機應用或語音助手對智能家居裝置發出指令後,如調節空調溫度、開啟燈光等,系統調用 OpenAPI傳入操作結果文本,智能體主動播報告知使用者裝置操作是否成功;在智能車載系統中同樣適用,當車輛的智能系統監測到異常情況,如胎壓過低、油量不足等,通過調用OpenAPI將相關文本資訊傳遞給智能體,智能體主動向駕駛員播報,及時提醒駕駛員注意車輛狀況,保障行車安全。

功能實現

服務端實現主動播報

SendAIAgentSpeech - 發送AI智能體語音

package com.aliyun.rtc;

import com.aliyun.tea.*;

public class SampleSendAIAgentSpeech {

    /**
     * <b>description</b> :
     * <p>使用AK&amp;SK初始化帳號Client</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.ice20201109.Client createClient() throws Exception {
        // 工程代碼泄露可能會導致 AccessKey 泄露,並威脅帳號下所有資源的安全性。以下程式碼範例僅供參考。
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填,請確保代碼運行環境設定了環境變數 ALIBABA_CLOUD_ACCESS_KEY_ID。
                .setAccessKeyId("yourak")
                // 必填,請確保代碼運行環境設定了環境變數 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
                .setAccessKeySecret("yoursk");
        // Endpoint 請參考 https://api.aliyun.com/product/ICE
        config.endpoint = "ice.cn-shanghai.aliyuncs.com";
        return new com.aliyun.ice20201109.Client(config);
    }

    private static void sendAIAgentSpeech() throws Exception {
        com.aliyun.ice20201109.Client client = createClient();

        com.aliyun.ice20201109.models.SendAIAgentSpeechRequest request = new com.aliyun.ice20201109.models.SendAIAgentSpeechRequest()
            .setInstanceId("xxx")
            .setText("yourtext");

        try {
            com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
            
            client.sendAIAgentSpeechWithOptions(request, runtime);
        } catch (TeaException error) {
            System.out.println(error.getMessage());
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            System.out.println(error.getMessage());
            com.aliyun.teautil.Common.assertAsString(error.message);
        }   
    }
    
    public static void main(String[] args) throws Exception {
        sendAIAgentSpeech();
    }
}