Amazon Polly
开发人员指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

DescribeVoices

以下 Java 代码示例显示如何使用基于 Java 的应用程序生成可在请求语音合成时使用的语音列表。您可以选择指定语言代码以筛选可用语音。例如,如果您指定 en-US,则该操作将返回所有可用美国英语语音的列表。

有关此操作的更多信息,请参阅 DescribeVoices API 参考。

package com.amazonaws.polly.samples; import com.amazonaws.services.polly.AmazonPolly; import com.amazonaws.services.polly.AmazonPollyClientBuilder; import com.amazonaws.services.polly.model.DescribeVoicesRequest; import com.amazonaws.services.polly.model.DescribeVoicesResult; public class DescribeVoicesSample { AmazonPolly client = AmazonPollyClientBuilder.defaultClient(); public void describeVoices() { DescribeVoicesRequest allVoicesRequest = new DescribeVoicesRequest(); DescribeVoicesRequest enUsVoicesRequest = new DescribeVoicesRequest().withLanguageCode("en-US"); try { String nextToken; do { DescribeVoicesResult allVoicesResult = client.describeVoices(allVoicesRequest); nextToken = allVoicesResult.getNextToken(); allVoicesRequest.setNextToken(nextToken); System.out.println("All voices: " + allVoicesResult.getVoices()); } while (nextToken != null); do { DescribeVoicesResult enUsVoicesResult = client.describeVoices(enUsVoicesRequest); nextToken = enUsVoicesResult.getNextToken(); enUsVoicesRequest.setNextToken(nextToken); System.out.println("en-US voices: " + enUsVoicesResult.getVoices()); } while (nextToken != null); } catch (Exception e) { System.err.println("Exception caught: " + e); } } }