Skip to content

jspaulsen/tts

Repository files navigation

TTS Service

A text-to-speech service using AWS Polly, built with FastAPI.

Prerequisites

  • Python 3.12+
  • uv (Python package manager)
  • Docker and Docker Compose
  • AWS credentials configured (for Polly access)

Installation

Install dependencies using uv:

uv sync

For development dependencies (testing, etc.):

uv sync --dev

Environment Variables

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.

AWS Authentication

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 optionally AWS_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 login with a configured profile

The IAM policy must include the polly:SynthesizeSpeech permission.

Local Development

Starting the Database

Start PostgreSQL and run migrations using Docker Compose:

docker compose -f docker-compose.test.yml up -d

If you've added new database migrations, rebuild the containers:

docker compose -f docker-compose.test.yml up -d --build

Running the Application

DATABASE_URL="postgres://postgres:postgres@localhost:5432/postgres" \
ADMIN_API_TOKEN="your_token" \
uv run uvicorn src.main:app --reload

The API will be available at http://localhost:8000.

Testing

Running Unit Tests

First, ensure the database is running:

docker compose -f docker-compose.test.yml up -d

Then run the tests:

uv run pytest

Debugging

For verbose test output:

uv run pytest -v

To run a specific test file:

uv run pytest tests/routers/test_users.py

About

TTS Service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors