forked from awsdocs/aws-doc-sdk-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DescribeVoices.go
56 lines (49 loc) · 1.75 KB
/
DescribeVoices.go
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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
// snippet-start:[polly.go.describe_voices]
package main
// snippet-start:[polly.go.describe_voices.imports]
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/polly"
"github.com/aws/aws-sdk-go/service/polly/pollyiface"
)
// snippet-end:[polly.go.describe_voices.imports]
// GetVoices retrieves a list of the voices for US English.
// Inputs:
// svc is an Amazon Polly service client
// Output:
// If success, the list of voices and nil
// Otherwise, nil and an error from the call to DescribeVoices
func GetVoices(svc pollyiface.PollyAPI) (*polly.DescribeVoicesOutput, error) {
// snippet-start:[polly.go.describe_voices.call]
resp, err := svc.DescribeVoices(&polly.DescribeVoicesInput{
LanguageCode: aws.String("en-US"),
})
// snippet-end:[polly.go.describe_voices.call]
return resp, err
}
func main() {
// snippet-start:[polly.go.describe_voices.session]
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
svc := polly.New(sess)
// snippet-end:[polly.go.describe_voices.session]
resp, err := GetVoices(svc)
if err != nil {
fmt.Println("Got error calling DescribeVoices:")
fmt.Print(err.Error())
return
}
// snippet-start:[polly.go.describe_voices.display]
for _, v := range resp.Voices {
fmt.Println("Name: " + *v.Name)
fmt.Println("Gender: " + *v.Gender)
fmt.Println("")
}
// snippet-end:[polly.go.describe_voices.display]
}
// snippet-end:[polly.go.describe_voices]