This project leverages AWS services to create a serverless text-to-speech application. Users can input text into a web interface, which is then sent to an AWS Lambda function via API Gateway. The Lambda function utilizes Amazon Polly, a service that converts text into lifelike speech, to generate an audio file of the input text. The audio is then played back to the user, allowing them to hear the synthesized speech.
By completing this project, you'll learn how to:
- Set up and manage AWS services, including AWS Amplify for web hosting, API Gateway for communication, Lambda for processing data, and Polly for text-to-speech conversion.
- Implement a serverless architecture for a real-world application.
- Integrate these services to provide a seamless user experience from text input to speech output.
Note: Fees may apply when using AWS services. It is recommended to delete all unused services after completing the project to avoid unnecessary charges.
Create an IAM role with the following permissions:
- AmazonPollyReadOnlyAccess
- AWSLambdaBasicExecutionRole
- Runtime: Python 3.12
- Execution Role: Use an existing role (
Lambda_Polly_Role
) - Code: Deploy the provided code in the Code source section.
Optional: To test the function, configure a test event using the following JSON:
{
"text": "Hello, this is a test of the text-to-speech system.",
"language": "en-US"
}
- API Endpoint Type: Edge-optimized
- Method: POST
- Integration Type: Lambda Function
- Lambda Function:
Text2Speech_Function
- CORS: Enable CORS on the root resource
/
- Access-Control-Allow-Methods: POST
- Deployment: Deploy the API to a new stage named
dev
- Invoke URL: Copy the Invoke URL for later use
- Use a text editor (e.g., VS Code) to create an
index.html
file. - Insert the provided HTML code.
- Replace the placeholder in line 70 with your API Gateway Invoke URL, ensuring it ends with a backslash (
/dev/
):fetch("Invoke URL", requestOptions)
- Compress the
index.html
file into a ZIP archive (it must be a.zip
file, not.rar
or another format).
- Create New App: Choose "Deploy without Git."
- Upload ZIP File: Drag and drop the ZIP file containing
index.html
, then save and deploy. - Access: Click "Visit deployed URL" or use the provided Domain URL to access your app.
- Enter a sentence to synthesize.
- Select a language.
- Click "Synthesize" to hear the generated speech.
For more details on the SynthesizeSpeech
API, refer to the Polly SynthesizeSpeech documentation.