How travisvn/openai-edge-tts works
Project Type & Purpose
• This is a backend microservice (an OpenAI-compatible TTS API) written in Python.
• Purpose: expose /v1/audio/speech, /v1/models, /v1/voices, etc., translate requests into calls to Microsoft Edge’s online TTS (via edge-tts), optionally run audio through ffmpeg for format conversion, and return audio to the client.
File Structure
• Top-level files:
• .env.example / .env for configuration
• Dockerfile + docker-compose.yml for containerization
• requirements.txt for Python deps
• README.md, LICENSE
• app/ directory contains core Python modules:
• server.py – defines HTTP endpoints & routing
• handle_text.py – validates/parses incoming payloads
• tts_handler.py – interacts with edge-tts library
• utils.py – shared helpers (e.g., mapping OpenAI voices to edge-tts voices, speed/format utilities)
README for Additional Insights
• Supported endpoints and their parameters
• Use of environment variables (API_KEY, PORT, defaults for voice/speed/format, feature toggles)
• Optional dependencies: ffmpeg for conversion
• Container workflow: Docker Compose / Docker run
Main Components & Relationships
1. Client (e.g. curl, Open WebUI, AnythingLLM)
2. API Gateway / HTTP Server (app/server.py)
3. Request Validator & Text Handler (app/handle_text.py)
4. TTS Orchestrator (app/tts_handler.py)
5. Utility Layer (app/utils.py)
6. External Service: Microsoft Edge Online TTS (via edge-tts library)
7. (Optional) ffmpeg process for audio format conversion
8. Configuration Store: Environment variables (.env)
9. Container Platform: Docker + Docker Compose
b. Data flow / interactions
• Client → HTTP Server (POST /v1/audio/speech with JSON)
• Server → handle_text → tts_handler
• tts_handler → edge-tts (external HTTP calls) → audio stream
• audio stream → [ffmpeg] → desired format
• binary audio → HTTP Response → Client
c. Architectural patterns & design principles
• Layered: API layer, business logic (handlers), utilities
• Separation of Concerns: parsing vs. orchestration vs. I/O
• 12-factor app style: config via env vars, stateless service, containerized
d. Key technologies
• Python 3.x, fastapi or flask (depending on server.py)
• edge-tts library (Microsoft Edge TTS)
• ffmpeg CLI (optional)
• Docker & Docker Compose
Detailed Elements to Capture
• Environment / Config: show .env driving server port, API key enforcement, defaults
• Container Boundary: group all Python modules inside one Docker container
• Library Calls: annotate edge-tts invocation within TTS Orchestrator
• Audio Pipeline: illustrate branching to ffmpeg for format conversion (mp3, wav, etc.)