2023-03-31 05:36:53 -07:00
# Amazon Polly code examples for the SDK for Python
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
## Overview
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
Shows how to use the AWS SDK for Python (Boto3) to work with Amazon Polly.
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
<!--custom.overview.start-->
<!--custom.overview.end-->
2021-01-29 18:17:30 -08:00
2024-01-05 10:05:03 -05:00
_ Amazon Polly is a Text-to-Speech (TTS) cloud service that converts text into lifelike speech. _
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
## ⚠ Important
2024-01-09 12:33:12 -05:00
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing ](https://aws.amazon.com/pricing/ ) and [Free Tier ](https://aws.amazon.com/free/ ).
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege ).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services ](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services ).
2021-11-29 16:35:53 -08:00
2023-03-31 05:36:53 -07:00
<!--custom.important.start-->
<!--custom.important.end-->
2021-11-29 16:35:53 -08:00
2023-03-31 05:36:53 -07:00
## Code examples
2023-04-13 11:38:14 -07:00
### Prerequisites
For prerequisites, see the [README ](../../README.md#Prerequisites ) in the `python` folder.
Install the packages required by these examples by running the following in a virtual environment:
```
python -m pip install -r requirements.txt
```
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->
2023-03-31 05:36:53 -07:00
### Single actions
2021-11-29 16:35:53 -08:00
2023-03-31 05:36:53 -07:00
Code excerpts that show you how to call individual service functions.
2021-11-29 16:35:53 -08:00
2024-04-30 12:22:08 -07:00
- [DescribeVoices ](polly_wrapper.py#L35 )
- [GetLexicon ](polly_wrapper.py#L267 )
- [GetSpeechSynthesisTask ](polly_wrapper.py#L229 )
- [ListLexicons ](polly_wrapper.py#L286 )
- [PutLexicon ](polly_wrapper.py#L249 )
- [StartSpeechSynthesisTask ](polly_wrapper.py#L147 )
2024-09-16 07:20:14 -04:00
- [SynthesizeSpeech ](polly_wrapper.py#L54 )
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
### Scenarios
Code examples that show you how to accomplish a specific task by calling multiple
functions within the same service.
2021-01-29 18:17:30 -08:00
2024-08-27 14:32:38 -04:00
- [Create a lip-sync application ](../../example_code/polly )
2024-01-05 10:05:03 -05:00
2024-01-09 12:33:12 -05:00
2024-01-05 10:05:03 -05:00
<!--custom.examples.start-->
<!--custom.examples.end-->
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
## Run the examples
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
### Instructions
2024-01-09 12:33:12 -05:00
2023-03-31 05:36:53 -07:00
<!--custom.instructions.start-->
<!--custom.instructions.end-->
2024-01-09 12:33:12 -05:00
2023-03-31 05:36:53 -07:00
#### Create a lip-sync application
This example shows you how to create a lip-sync application with Amazon Polly.
2024-01-09 12:33:12 -05:00
2023-04-13 11:38:14 -07:00
<!--custom.scenario_prereqs.polly_LipSync.start-->
2024-01-05 10:05:03 -05:00
Start the example by running the following at a command prompt:
2023-04-13 11:38:14 -07:00
<!--custom.scenario_prereqs.polly_LipSync.end-->
2024-01-09 12:33:12 -05:00
2024-01-05 10:05:03 -05:00
<!--custom.scenarios.polly_LipSync.start-->
2023-03-31 05:36:53 -07:00
Start the example by running the following at a command prompt:
2021-01-29 18:17:30 -08:00
```
python polly_lipsync.py
```
2023-03-31 05:36:53 -07:00
This example is a GUI application. Enter text into the input field, then select engine,
language, and voice parameters. Choose the **Say it ** button to see and hear the
2021-01-29 18:17:30 -08:00
synthesized speech.
If you enter text that is too long for synchronous synthesis, you are asked for the
2024-01-05 10:05:03 -05:00
name of an existing Amazon Simple Storage Service (Amazon S3) bucket. This bucket is used
by Amazon Polly to store the output of the asynchronous synthesis task. After the task
completes, the application downloads the output and deletes the S3 object.
2023-03-31 05:36:53 -07:00
<!--custom.scenarios.polly_LipSync.end-->
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
### Tests
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
⚠ Running tests might result in charges to your AWS account.
2021-01-29 18:17:30 -08:00
2024-01-09 12:33:12 -05:00
2023-03-31 05:36:53 -07:00
To find instructions for running these tests, see the [README ](../../README.md#Tests )
in the `python` folder.
2021-01-29 18:17:30 -08:00
2024-01-09 12:33:12 -05:00
2023-03-31 05:36:53 -07:00
<!--custom.tests.start-->
<!--custom.tests.end-->
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
## Additional resources
2021-01-29 18:17:30 -08:00
2024-01-05 10:05:03 -05:00
- [Amazon Polly Developer Guide ](https://docs.aws.amazon.com/polly/latest/dg/what-is.html )
- [Amazon Polly API Reference ](https://docs.aws.amazon.com/polly/latest/dg/API_Reference.html )
- [SDK for Python Amazon Polly reference ](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/polly.html )
2021-01-29 18:17:30 -08:00
2023-03-31 05:36:53 -07:00
<!--custom.resources.start-->
<!--custom.resources.end-->
2021-01-29 18:17:30 -08:00
---
2023-03-31 05:36:53 -07:00
2021-01-29 18:17:30 -08:00
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2024-01-09 12:33:12 -05:00
SPDX-License-Identifier: Apache-2.0