- Created FastAPI application with CORS middleware - Defined Pydantic models (RoleDetectionRequest, RolesResponse, TTSRequest, ErrorResponse) - Implemented /api/health endpoint - Set up error handling middleware for validation and general exceptions - Configured logging with INFO level - Added test script to verify API functionality - Validates Requirements: 9.1, 9.2, 9.4
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
- Create a virtual environment:
python -m venv venv
- Activate the virtual environment:
# macOS/Linux
source venv/bin/activate
# Windows
venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- 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 endpointPOST /api/tts/roles- Detect roles in textPOST /api/tts- Generate audiobook