Step 2.1: Set up the AWS CLI
Follow these steps to download and configure the AWS CLI to work with Amazon Polly.
Important
You don't need the AWS CLI to perform the steps in this exercise. However, some of the exercises in this guide use the AWS CLI. You can skip this step and go to Step 2.2: Getting started exercise using the AWS CLI, and then set up the AWS CLI later when you need it.
Set up the AWS CLI
To set up the AWS Command Line Interface
-
Download and configure the AWS CLI. For instructions, see the following topics in the AWS Command Line Interface User Guide:
-
Add a named profile for the administrator user in the AWS CLI AWS Config file. You can use this profile when running the AWS CLI commands. For more information about named profiles, see Named Profiles in the AWS Command Line Interface User Guide.
[profile adminuser] aws_access_key_id =
adminuser access key ID
aws_secret_access_key =adminuser secret access key
region =aws-region
For a list of available AWS Regions and those supported by Amazon Polly, see Regions and Endpoints in the Amazon Web Services General Reference.
Note
If you're using a Region supported by Amazon Polly that you specified when you configured the AWS CLI, omit the following line from the AWS CLI code examples.
--region
aws-region
-
Verify the setup by typing the following help command at the command prompt.
aws help
A list of valid AWS commands should appear in the AWS CLI window.
Activate Amazon Polly from the AWS CLI
If you've previously downloaded and configured the AWS CLI, Amazon Polly may be unavailable unless you reconfigure the AWS CLI. The following procedure checks to see if this is necessary.
To activate Amazon Polly from the AWS CLI
-
Verify the availability of Amazon Polly by typing the following help command at the AWS CLI command prompt.
aws polly help
If you see a description of Amazon Polly and a list of valid commands appears in the AWS CLI window, you can use Amazon Polly from the AWS CLI immediately. In this case, you can skip the rest of this procedure. If this is not displayed, continue with Step 2.
-
Activate Amazon Polly using one of the two following options:
-
Uninstall and reinstall the AWS CLI.
For instructions, see Installing the AWS Command Line Interface in the AWS Command Line Interface User Guide.
or
-
Download the file service-2.json.
At the command prompt, run the following command.
aws configure add-model --service-model
file://service-2.json
--service-name polly
-
-
Reverify the availability of Amazon Polly.
aws polly help
The description of Amazon Polly should be visible.
Set up a voice engine from the AWS CLI
From the AWS CLI, the engine
parameter is optional, with four
possible values: generative
, long-form
,
neural
, and standard
. For example, if you use the
following code to run the start-speech-synthesis-task
AWS CLI command
in the US West-2 (Oregon) region:
aws polly start-speech-synthesis-task \ --engine
neural
--regionus-west-2
\ --endpoint-url "https://polly.us-west-1.amazonaws.com/
" \ --output-format mp3 \ --output-s3-bucket-nameyour-bucket-name
\ --output-s3-key-prefixoptional/prefix/path/file
\ --voice-id Joanna \ --textfile://text_file.txt
The output will resemble the following:
"SynthesisTask":
{
"CreationTime": [..],
"Engine": "neural",
"OutputFormat": "mp3",
"OutputUri": "https://s3.us-west-1.amazonaws.com/your-bucket-name/optional/prefix/path/file.<task_id>.mp3",
"TextType": "text",
"RequestCharacters": [..],
"TaskStatus": "scheduled",
"TaskId": [task_id],
"VoiceId": "Joanna"
}