- AWS Code Sample

DescribeVoicesSample produces a list of all voices available for use when requesting speech synthesis with Amazon Polly.

/** * Copyright, Inc. or its affiliates. All Rights Reserved. * * This file is licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. A copy of * the License is located at * * * * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ package com.example.polly; import; import; import; import; import; import; import java.util.Collection; import java.util.Iterator; public class DescribeVoicesSample { public static void main(String args[]) { PollyClient polly = PollyClient.builder() .region(Region.US_WEST_2) .build(); describeVoice(polly) ; } public static void describeVoice(PollyClient polly) { try { DescribeVoicesRequest voicesRequest = DescribeVoicesRequest.builder() .languageCode("en-US") .build(); DescribeVoicesResponse enUsVoicesResult = polly.describeVoices(voicesRequest); Collection<Voice> voices = enUsVoicesResult.voices(); Iterator<Voice> iterator = voices.iterator(); // Get each voice while (iterator.hasNext()) { Voice myVoice =; System.out.println("The ID of the voice is "; System.out.println("The gender of the voice is " + myVoice.gender()); } } catch (PollyException e) { System.err.println("Exception caught: " + e); System.exit(1); } } }

Sample Details

Service: Amazon Polly

Last tested: 5/7/2020

Author: scmacdon AWS

Type: full-example