本文将为您介绍在音视频通话中如何传入文本进行语音播报。
功能描述
语音播报允许您通过调用OpenAPI接口,将需要播报的文本内容作为参数传入。客户端在接收到传入的文本内容后,即刻启动语音合成技术,将文本转化为语音并进行播报,使得信息以语音形式清晰传达给用户。
应用场景
在智能家居设备应用场景中,如智能家具设备,用户通过手机应用或语音助手对智能家居设备发出指令后,如调节空调温度、打开灯光等,系统调用 OpenAPI传入操作结果文本,智能体主动播报告知用户设备操作是否成功;在智能车载系统中同样适用,当车辆的智能系统监测到异常情况,如胎压过低、油量不足等,通过调用OpenAPI将相关文本信息传递给智能体,智能体主动向驾驶员播报,及时提醒驾驶员注意车辆状况,保障行车安全。
功能实现
服务端实现主动播报
package com.aliyun.rtc;
import com.aliyun.tea.*;
public class SampleSendAIAgentSpeech {
/**
* <b>description</b> :
* <p>使用AK&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();
}
}
该文章对您有帮助吗?