curl --request POST \
--url https://api.example.com/tts \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>"
}
'Convert text to speech audio using ElevenLabs
curl --request POST \
--url https://api.example.com/tts \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>"
}
'ELEVENLABS_API_KEY - Your ElevenLabs API keyaudio/mpeg
Headers:
Content-Disposition: inline; filename=speech.mp3
.mp3 extension{
"error": "No text provided"
}
{
"error": "ELEVENLABS_API_KEY not set in .env"
}
{
"error": "<error details from ElevenLabs or Python exception>"
}
# JSON request
curl -X POST http://localhost:5000/tts \
-H "Content-Type: application/json" \
-d '{"text": "Hello, welcome to our pizza restaurant!"}' \
--output speech.mp3
# Form data request
curl -X POST http://localhost:5000/tts \
-F "text=Hello, welcome to our pizza restaurant!" \
--output speech.mp3
JBFqnCBsd6RMkjVDRZzbeleven_turbo_v2_5text = "Very long text..." * 1000 # 10,000+ characters
# Only first 1500 chars will be converted
collect_audio_bytes() function to handle different audio stream formats from the ElevenLabs client:
Content-Type: application/json with {"text": "..."}Content-Type: application/x-www-form-urlencoded with text=...Content-Type: audio/mpeg
Content-Disposition: inline; filename=speech.mp3
Content-Type: audio/mpeg tells the browser it’s MP3 audioContent-Disposition: inline suggests playing in-browser rather than downloadingfilename=speech.mp3 provides a default filename if the user saves it