forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDescribeVoices.cs
72 lines (63 loc) · 2.33 KB
/
DescribeVoices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/// <summary>
/// Displays information about the voices available for Amazon Polly. This
/// example was created using the AWS SDK for .NET version 3.7 and .NET Core 5.
/// </summary>
namespace DescribeVoicesExample
{
// snippet-start:[Polly.dotnetv3.DescribeVoicesExample]
using System;
using System.Threading.Tasks;
using Amazon.Polly;
using Amazon.Polly.Model;
public class DescribeVoices
{
public static async Task Main()
{
var client = new AmazonPollyClient();
var allVoicesRequest = new DescribeVoicesRequest();
var enUsVoicesRequest = new DescribeVoicesRequest()
{
LanguageCode = "en-US",
};
try
{
string nextToken;
do
{
var allVoicesResponse = await client.DescribeVoicesAsync(allVoicesRequest);
nextToken = allVoicesResponse.NextToken;
allVoicesRequest.NextToken = nextToken;
Console.WriteLine("\nAll voices: ");
allVoicesResponse.Voices.ForEach(voice =>
{
DisplayVoiceInfo(voice);
});
}
while (nextToken is not null);
do
{
var enUsVoicesResponse = await client.DescribeVoicesAsync(enUsVoicesRequest);
nextToken = enUsVoicesResponse.NextToken;
enUsVoicesRequest.NextToken = nextToken;
Console.WriteLine("\nen-US voices: ");
enUsVoicesResponse.Voices.ForEach(voice =>
{
DisplayVoiceInfo(voice);
});
}
while (nextToken is not null);
}
catch (Exception ex)
{
Console.WriteLine("Exception caught: " + ex.Message);
}
}
public static void DisplayVoiceInfo(Voice voice)
{
Console.WriteLine($" Name: {voice.Name}\tGender: {voice.Gender}\tLanguageName: {voice.LanguageName}");
}
}
// snippet-end:[Polly.dotnetv3.DescribeVoicesExample]
}