Edge tts running on fastapi with swagger
418
A free, OpenAI-compatible text-to-speech API backed by Microsoft Edge Neural TTS. Drop-in replacement for applications using OpenAI's TTS endpoint.
/v1/audio/speech endpointedge-tts library, no API keys or credits neededdocker run -d \
-p 5050:5050 \
-e DEFAULT_VOICE=en-US-AriaNeural \
-e DEFAULT_RESPONSE_FORMAT=mp3 \
-e DEFAULT_SPEED=1.0 \
--name edge-tts-fastapi \
dattm24/edge-tts-fastapi
docker run -d \
-p 5050:5050 \
-e INSTALL_FFMPEG_ARG=true \
--name edge-tts-fastapi \
dattm24/edge-tts-fastapi
services:
tts:
image: dattm24/edge-tts-fastapi
container_name: edge-tts-fastapi
restart: unless-stopped
ports:
- "5050:5050"
environment:
DEFAULT_VOICE: en-US-AriaNeural
DEFAULT_RESPONSE_FORMAT: mp3
DEFAULT_SPEED: 1.0
POST /v1/audio/speech
Generate audio from text. Accepts JSON body.
Request Body:
{
"model": "tts-1",
"input": "Hello, world!",
"voice": "nova",
"response_format": "mp3",
"speed": 1.0
}
| Parameter | Type | Default | Description |
|---|---|---|---|
model | string | tts-1 | TTS model name |
input | string | (required) | Text to synthesize |
voice | string | en-US-AvaNeural | Voice ID or Azure Neural Voice name |
response_format | string | mp3 | Output audio format |
speed | number | 1.0 | Playback speed (0.5 – 2.0) |
Available Voices (Preset IDs):
| Preset ID | Azure Neural Voice | Language |
|---|---|---|
alloy | en-US-JennyNeural | English (US, Female) |
ash | en-US-AndrewNeural | English (US, Male) |
ballad | en-GB-ThomasNeural | English (GB, Male) |
coral | en-AU-NatashaNeural | English (AU, Female) |
echo | en-US-GuyNeural | English (US, Male) |
fable | en-GB-SoniaNeural | English (GB, Female) |
nova | en-US-AriaNeural | English (US, Female) |
onyx | en-US-EricNeural | English (US, Male) |
sage | en-US-JennyNeural | English (US, Female) |
shimmer | en-US-EmmaNeural | English (US, Female) |
verse | en-US-BrianNeural | English (US, Male) |
Or use any Azure Neural Voice name directly (e.g. zh-CN-XiaoxiaoNeural).
Response: Binary audio file with Content-Type matching the requested format.
cURL Example:
curl -X POST http://localhost:5050/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{"input": "Hello, world!", "voice": "nova", "response_format": "mp3"}' \
--output speech.mp3
OpenAI Python Client Example:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:5050/v1",
api_key="fake-key"
)
response = client.audio.speech.create(
model="tts-1",
voice="nova",
input="Hello, world!",
response_format="mp3",
speed=1.0
)
response.stream_to_file("output.mp3")
Add "stream_format": "sse" to request body for real-time streaming:
curl -X POST http://localhost:5050/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{"input": "Hello, world!", "voice": "nova", "stream_format": "sse"}'
Response format (SSE events):
{"type": "speech.audio.delta", "audio": "base64EncodedChunk"}
{"type": "speech.audio.delta", "audio": "base64EncodedChunk"}
{"type": "speech.audio.done", "usage": {"input_tokens": 3}}
GET /v1/models
Response:
{
"models": [
{"id": "tts-1", "name": "Text-to-speech v1"},
{"id": "tts-1-hd", "name": "Text-to-speech v1 HD"},
{"id": "gpt-4o-mini-tts", "name": "GPT-4o mini TTS"}
]
}
GET /v1/voices
GET /v1/voices/all
Returns available voices filtered by optional ?language=en-US query parameter.
Compatible with third-party client integrations. Requires EXPAND_API=True.
| Endpoint | Method | Description |
|---|---|---|
/elevenlabs/v1/text-to-speech/{voice_id} | POST | ElevenLabs-style TTS (expects text field) |
/azure/cognitiveservices/v1 | POST | Azure SSML-style TTS (expects SSML body) |
/v1/audio/speech, /audio/speech | POST | OpenAI-compatible speech generation |
| Variable | Type | Default | Description |
|---|---|---|---|
PORT | int | 5050 | Server port |
HOST | string | 0.0.0.0 | Bind address |
DEFAULT_VOICE | string | en-US-AvaNeural | Default voice |
DEFAULT_RESPONSE_FORMAT | string | mp3 | Output audio format |
DEFAULT_SPEED | float | 1.0 | Playback speed |
DEFAULT_LANGUAGE | string | en-US | Default language for voice listing |
REQUIRE_API_KEY | bool | False | Require X-API-Key header |
REMOVE_FILTER | bool | False | Skip markdown/emoji text preprocessing |
EXPAND_API | bool | True | Enable ElevenLabs & Azure endpoints |
DETAILED_ERROR_LOGGING | bool | True | Verbose error output in logs |
[Add your license here]
Content type
Image
Digest
sha256:f95b68165…
Size
78.9 MB
Last updated
20 days ago
docker pull dattm24/edge-tts-fastapi