https://github.com/lsafonso/tts-aws-lambda-polly
https://github.com/lsafonso/tts-aws-lambda-polly
Last synced: 25 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/lsafonso/tts-aws-lambda-polly
- Owner: lsafonso
- Created: 2025-06-08T17:27:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-19T09:24:02.000Z (about 1 year ago)
- Last Synced: 2025-10-28T01:08:38.681Z (9 months ago)
- Language: TypeScript
- Size: 555 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Link to the page
https://my-tts-app-frontend.s3.eu-north-1.amazonaws.com/index.html
## How It Works

This is a simple serverless Text-to-Speech (TTS) web app built with:
- **React + Vite** for the frontend UI
- **AWS API Gateway** (HTTP API) to expose a `/synthesize` endpoint
- **AWS Lambda** (Node.js) as the backend integration
- **Amazon Polly** to perform the actual speech synthesis
- **S3 + CloudFront** to host the React build with CDN
---
### 1. User Interface (React + Vite)
1. The user types or pastes text into the **TextInput** component.
2. They pick a voice (Joanna, Matthew, etc.) in the **VoiceSelector**.
3. They adjust **Speech Rate**, **Pitch**, and choose **Standard** vs **Neural** voices in **SpeechControls**.
4. Clicking **Generate Speech** fires a `POST /synthesize` call to the deployed API.
---
### 2. HTTP API (API Gateway)
- Receives the JSON payload:
```json
{
"text": "Hello world!",
"voiceId": "Joanna",
"engine": "neural",
"outputFormat": "mp3",
"speechRate": "1.0",
"pitch": "0"
}
---
### 3. Serverless Function (Lambda)
1. **Parse the event**
Extracts `text`, `voiceId`, `engine`, `outputFormat`, `speechRate`, and `pitch` from the incoming payload.
2. **Call Amazon Polly**
Uses the AWS SDK v3:
```ts
import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly";
const client = new PollyClient({ region: "eu-north-1" });
const command = new SynthesizeSpeechCommand({
Text: text,
VoiceId: voiceId,
Engine: engine,
OutputFormat: outputFormat,
SpeechRate: speechRate,
Pitch: pitch,
});
const pollyResponse = await client.send(command);
3. Return HTTP response
```json
{
"statusCode": 200,
"isBase64Encoded": true,
"headers": {
"Content-Type": "audio/mpeg",
"Access-Control-Allow-Origin": "*"
},
"body": ""
}
```
---
## Preview
