A text-to-speech service using AWS Polly, built with FastAPI.
- Python 3.12+
- uv (Python package manager)
- Docker and Docker Compose
- AWS credentials configured (for Polly access)
Install dependencies using uv:
uv syncFor development dependencies (testing, etc.):
uv sync --dev| Variable | Required | Description |
|---|---|---|
DATABASE_URL |
Yes | PostgreSQL connection string (e.g., postgres://user:pass@localhost:5432/dbname) |
ADMIN_API_TOKEN |
Yes | Admin API authentication token |
MAXIMUM_CHARACTERS_PER_REQUEST |
No | Max characters per TTS request (default: 2048) |
LRU_CACHE_SIZE |
No | Size of the LRU cache (default: 64) |
HF_HOME |
No | HuggingFace cache directory for Kokoro model downloads (useful when mounting as a Docker volume). See HuggingFace environment variables for more options. |
This service requires AWS credentials with access to Amazon Polly. You can configure credentials using any of the standard AWS methods:
- Environment variables: Set
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, and optionallyAWS_REGION - Shared credentials file: Configure
~/.aws/credentials - IAM role: When running on AWS infrastructure (EC2, ECS, Lambda), use an attached IAM role
- AWS SSO: Use
aws sso loginwith a configured profile
The IAM policy must include the polly:SynthesizeSpeech permission.
Start PostgreSQL and run migrations using Docker Compose:
docker compose -f docker-compose.test.yml up -dIf you've added new database migrations, rebuild the containers:
docker compose -f docker-compose.test.yml up -d --buildDATABASE_URL="postgres://postgres:postgres@localhost:5432/postgres" \
ADMIN_API_TOKEN="your_token" \
uv run uvicorn src.main:app --reloadThe API will be available at http://localhost:8000.
First, ensure the database is running:
docker compose -f docker-compose.test.yml up -dThen run the tests:
uv run pytestFor verbose test output:
uv run pytest -vTo run a specific test file:
uv run pytest tests/routers/test_users.py