This topic describes how to input text for voice broadcast in audio and video calls.
Feature description
Voice broadcast allows you to call OpenAPI operations and pass the text content to be broadcast as a parameter. After the client receives the input text content, it immediately initiates speech synthesis technology to convert the text into speech and broadcast it, delivering information clearly to users in voice form.
Scenarios
In smart home device scenarios, such as smart furniture devices, when users issue commands to smart home devices through mobile applications or voice assistants, such as adjusting air conditioner temperature or turning on lights, the system calls OpenAPI to input operation result text, and the agent actively broadcasts to inform users whether the device operation is successful. This is also applicable in intelligent vehicle systems. When the vehicle's intelligent system detects abnormal conditions, such as low tire pressure or insufficient fuel, it calls OpenAPI to transmit relevant text information to the agent, which actively broadcasts to the driver, promptly reminding the driver to pay attention to the vehicle condition and ensuring driving safety.
Feature implementation
Server-side implementation of active broadcast
package com.aliyun.rtc;
import com.aliyun.tea.*;
public class SampleSendAIAgentSpeech {
/**
* <b>description</b> :
* <p>Use your AccessKey pair to initialize the client</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.ice20201109.Client createClient() throws Exception {
// If the project code is leaked, the AccessKey pair may be disclosed, which may compromise the security of resources in your account. The following code is for reference only.
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.
.setAccessKeyId("yourak")
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.
.setAccessKeySecret("yoursk");
// For more information about Endpoint, see https://api.alibabacloud.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();
}
}