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