Files
audiobook/backend
Paul Bailey 271a127167 Implement audio generation endpoint
- Add POST /api/tts endpoint with full request validation
- Validate text, language code, speed range, and roles list
- Integrate TTSService to generate multi-voice audiobooks
- Fix Kokoro pipeline generator handling to properly collect audio
- Stream audio response with correct Content-Type (audio/wav)
- Add Content-Disposition header with filename (audiobook.wav)
- Handle errors gracefully with appropriate HTTP status codes
- Add comprehensive test suite for endpoint validation

Requirements: 6.1, 6.7, 6.8, 9.5
2025-12-09 01:21:39 +00:00
..
2025-12-09 01:21:39 +00:00
2025-12-09 01:21:39 +00:00
2025-12-09 00:57:46 +00:00

Text to Audiobook Backend

FastAPI backend service for converting text to multi-voice audiobooks using Kokoro TTS.

Setup

Prerequisites

  • Python 3.10 or higher
  • espeak-ng (system dependency)

Install espeak-ng

macOS:

brew install espeak-ng

Linux (Ubuntu/Debian):

sudo apt-get update
sudo apt-get install espeak-ng

Python Environment Setup

  1. Create a virtual environment:
python -m venv venv
  1. Activate the virtual environment:
# macOS/Linux
source venv/bin/activate

# Windows
venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create environment file:
cp .env.example .env

Running the Server

uvicorn main:app --reload --host 0.0.0.0 --port 8000

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

API documentation: http://localhost:8000/docs

API Endpoints

  • GET /api/health - Health check endpoint
  • POST /api/tts/roles - Detect roles in text
  • POST /api/tts - Generate audiobook