Reference · API
Text-to-speech API
Last updated
Turn **written text into spoken audio** — voice assistants, accessibility, podcasts, and in-app narration.
Turn **written text into spoken audio** — voice assistants, accessibility, podcasts, and in-app narration.
#When to use
Pair with transcription (Whisper) for full voice ↔ text loops.
#Endpoint (OpenAI pattern)
POST https://api.openai.com/v1/audio/speech#Request shape (sketch)
{
"model": "tts-1",
"input": "Welcome back. Here is your daily summary.",
"voice": "alloy",
"response_format": "mp3"
}Returns raw audio bytes — stream to client or save to object storage.
#Python sketch
from openai import OpenAI
client = OpenAI()
speech = client.audio.speech.create(
model="tts-1",
voice="nova",
input="Explain embeddings in one sentence.",
)
speech.stream_to_file("out.mp3")#Common pitfalls
| Pitfall | Fix |
|---------|-----|
| SSML / markup in plain `input` | Strip HTML; some models ignore tags |
| Very long inputs | Chunk text; add pauses between files |
| No disclosure for synthetic voice | Label AI-generated audio in UX |
| Caching identical phrases | Cache MP3 by hash to cut cost |