This is a pattern that integrates the Amazon Polly service into an AWS Lambda Function so that you can synthesize text into speech using a serverless stack. It also integrates with Amazon Translate to allow you to choose the language for the spoken text.
Some Useful References:
Author | Link |
---|---|
Amazon Polly | Amazon Polly Site |
Polly Pricing | Polly Pricing |
Polly Permissions | Polly IAM Permissions |
Amazon Translate | What Is Amazon Translate? |
Translate Pricing | Translate Pricing |
AWS Blogs | Giving your content a voice with the Newscaster speaking style from Amazon Polly |
AWS Docs | Using Amazon Polly with Amazon Translate |
Timothy Mugayi | Text-to-Speech: Build Apps That Talk With AWS Polly and Node.js |
Philip Kiely | Text-To-Speech With AWS (Part 1) |
After deployment you will have an API Gateway HTTP API configured where all traffic points to a Lambda Function that calls the Polly / Translate service.
This is setup with basic settings where all traffic is routed to our Lambda Function
Takes in whatever voice you want and whatever text you want, translates it to whatever language you want then sends it to the Polly service and returns an Audio stream
After deployment in the deploy logs you will see the url for the API Gateway.
If you open that URL in chrome it will play an audio recording saying "To hear your own script, you need to include text in the message body of your restful request to the API Gateway"
For examples of the voice clips produced checkout the mp3 files in the recordings folder
You can customise this message based on how you call the url:
You can pick from 3 voices "Matthew" (the default), "Joanna" or "Lupe". This is using the newsreader style of voice which AWS recently launched so it currently only supports these 3.
To change voices just add a query param onto your url like:
https://{api-url}/?voice=Lupe
https://{api-url}/?voice=Joanna
https://{api-url}/?voice=Matthew
This Lambda Function is integrated with Amazon Translate so you can have Polly speak a variety of languages
To have Lupe speak Spanish just add the translateTo query param
https://{api-url}/?voice=Lupe&translateTo=es
If the text you are translating is in a language other than english you can use the translateFrom parameter
To understand what languages are possible please refer to the documentation
If you use a tool like Postman to send text in the body of a POST request to the url it will use Polly to synthesize your text
dotnet build src
compile this appcdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template
- Create an Ubuntu AWS Cloud9 EC2 development environment
- Add the Microsoft repository
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
- Install the .NET Core SDK
sudo apt-get update; \ sudo apt-get install -y apt-transport-https && \ sudo apt-get update && \ sudo apt-get install -y dotnet-sdk-3.1
- Clone the CDK Patterns repo
git clone https://github.com/cdk-patterns/serverless.git
- Change directory
cd serverless/the-efs-lambda/csharp
- Build the project to see if .NET Core has been setup correctly (optional)
dotnet build src
- Deploy the stack
cdk deploy