POST /v1/audio/speech
Text to speech API: OpenAI-compatible voices, processed in the EU
The speech endpoint turns text into spoken audio with open text to speech models. It uses the same request as OpenAI's `/v1/audio/speech`, so voice features built for that API, from read-aloud buttons to phone menus and voice agents, can switch to models running in European data centres by changing the base URL, key, model and voice.
- 01API format: OpenAI
- 02EU data centres
- 03Covered by one DPA
curl https://api.inference.eu/v1/audio/speech \
-H "Authorization: Bearer $INFERENCE_EU_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kokoro-82m",
"voice": "bf_emma",
"input": "Your parcel has left our depot in Rotterdam and will arrive tomorrow between nine and twelve.",
"response_format": "mp3",
"speed": 1.0
}' \
--output delivery-update.mp3What the endpoint does
POST /v1/audio/speech takes a JSON body with the model, the input text and a voice, and returns the audio file itself as the response body rather than JSON. Save it straight to a file, as in the curl example with --output, or play it in your application. The response Content-Type header tells you the audio format.
Open voice models differ in the languages and voices they offer. Each model page lists its voices and languages, and the voice ids are specific to the model: an OpenAI voice name such as alloy will not exist on an open model, so pick one of the model's own voices.
Key request fields
input is the text to speak. Write it the way it should sound: spell out abbreviations, units and unusual numbers if the model reads them oddly, and use punctuation to control pauses. Long texts should be split at sentence boundaries into several requests.
response_format sets the audio format: mp3 is a good default for web and apps, opus is small and suited to streaming and telephony, wav and pcm are uncompressed for further processing, and aac and flac are also available on most models. speed changes the speaking rate, where 1.0 is normal. Models that support it accept instructions to steer tone and delivery.
A practical pattern for voice features
A voice assistant chains three calls: speech to text for the user's question, chat completions for the answer, and text to speech for the reply. To keep it responsive, stream the chat response, split it into sentences as they arrive, and send each sentence to the speech endpoint while the next one is still being generated. Play the audio clips in order.
For fixed messages, such as phone menu prompts or onboarding audio, generate the files once and cache them rather than calling the API on every play. Store the model and voice used, so that later additions sound the same.
Errors and edge cases
An unknown voice for the chosen model returns a 400 error that names the voice; check the model page or ask us for the list. Empty input, or text longer than the per-request limit, also returns 400. Because a successful response is binary audio, check the HTTP status before saving the body, otherwise you may write a JSON error into an mp3 file.
Pronunciation of names, brands and mixed-language text varies between models. Test with your real content, and if a word is consistently wrong, respell it phonetically in input. If people hear the audio, tell them it was generated by AI where the law or your own policy requires it.
Text to speech: common questions
The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.
Related
- Speech to textTranscribe audio with Whisper through an OpenAI-compatible speech to text API. Meetings, calls and voice notes, processed in EU data centres.Endpoints
- Chat completionsSend chat messages to open-weight models with the OpenAI chat completions format. Requests are processed in EU data centres and never used for training.Endpoints
- StreamingStream tokens from open models as they are generated, with OpenAI and Anthropic server-sent events. Examples, chunk format and error handling.Guides
Move your AI workloads to EU infrastructure
Tell us which models you use and roughly how much traffic you have. We reply within one working day with pricing and next steps.
- Reply within one working day
- Pricing for your volume
- DPA ready to sign