A text to speech API turns an article, video script or bot reply into an audio file with a single request. llmbox provides ElevenLabs models for this purpose. They use the same key and balance as the text models. This guide covers choosing a model and voice, receiving a file or stream, and three scenarios: a video voiceover, a podcast with two voices and voice replies from a Telegram bot. For an overview of all audio capabilities, including speech recognition and music, see the news post Audio API.
What you need
- An llmbox key. Create it in the cabinet's Keys section; the steps are in the Quickstart documentation page.
- For the Python examples, Python 3.10 or newer and an official SDK:
pip install elevenlabsfor the ElevenLabs format orpip install openaifor the OpenAI format. For your first request, curl is sufficient.
Keep the key in an environment variable, not in code:
export LLMBOX_API_KEY="sk-your-key"
How to choose a model
All text to speech models use the same request format but offer different balances of expressiveness and speed. The characteristics below come from ElevenLabs documentation:
| Model | When to use it | Languages | Text per request |
|---|---|---|---|
| Eleven v4 | Video, courses, audiobooks, characters: where delivery matters | 90+ | up to 10,000 characters |
| Eleven v4 Turbo | Voice assistants and bots, live conversation | 90+ | — |
| Eleven Multilingual v2 | Long-form, steady narration with many numbers, dates and phone numbers | 29 | up to 10,000 characters |
| Eleven Flash v2.5 | Voice assistants and bulk generation of short voice clips | 32 | up to 40,000 characters |
| Eleven v3 | Projects already voiced on v3 | 70+ | up to 5,000 characters |
As a rule of thumb, start with Eleven v4 for finished content and Eleven v4 Turbo for bots and assistants. One caveat with Flash v2.5 is that, according to ElevenLabs documentation, it does not normalize numbers by default. Spell out phone numbers and amounts in advance. All of the vendor's models are on the ElevenLabs API page, and other audio models are in the audio model collection.
How to send your first request with curl
In the ElevenLabs format, text to speech uses POST /v1/text-to-speech/{voice_id}. The path contains the voice ID, the body contains the text and model, and the output_format URL parameter sets the file format. The key goes in the xi-api-key header.
curl -X POST "https://llmbox.cc/v1/text-to-speech/VOICE_ID?output_format=mp3_44100_128" \
-H "xi-api-key: $LLMBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Welcome to the course. Today is the first lesson.",
"model_id": "eleven_v4",
"voice_settings": {"stability": 0.5, "similarity_boost": 0.75}
}' \
-o speech.mp3
The response is an audio file, which curl saves as speech.mp3. If you do not pass model_id, the default is Eleven Multilingual v2. The voice section below explains how to get a VOICE_ID.
How to use the ElevenLabs and OpenAI SDKs
To use the official ElevenLabs SDK with llmbox, set the base URL and key. Specify the base URL without /v1; the SDK adds the path itself.
import os
from elevenlabs.client import ElevenLabs
client = ElevenLabs(base_url="https://llmbox.cc", api_key=os.environ["LLMBOX_API_KEY"])
audio = client.text_to_speech.convert(
voice_id="VOICE_ID",
text="Welcome to the course. Today is the first lesson.",
model_id="eleven_v4",
output_format="mp3_44100_128",
)
with open("speech.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)
If your project already uses the OpenAI SDK, use the /v1/audio/speech path. Here the base URL includes /v1, and voice can be a familiar OpenAI voice name: alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, shimmer or verse. These names map to ElevenLabs voices, and any other value is treated as an ElevenLabs voice ID.
import os
from openai import OpenAI
client = OpenAI(base_url="https://llmbox.cc/v1", api_key=os.environ["LLMBOX_API_KEY"])
speech = client.audio.speech.create(
model="eleven_v4",
voice="nova",
input="Welcome to the course. Today is the first lesson.",
response_format="mp3",
speed=1.0,
)
speech.write_to_file("speech.mp3")
In either format, you can specify the model with the short ElevenLabs ID (eleven_v4) or the full catalog ID (elevenlabs/eleven_v4). In the OpenAI format, the speed parameter sets speech speed from 0.7 to 1.2.
How to choose a voice
A voice determines the timbre, apparent age and speaking style, so choose one before generating the entire recording. GET /v2/voices returns a searchable, paginated voice list. These requests are free.
curl "https://llmbox.cc/v2/voices?page_size=20&search=anna" \
-H "xi-api-key: $LLMBOX_API_KEY"
With the ElevenLabs SDK:
voices = client.voices.search(page_size=20)
for v in voices.voices:
print(v.voice_id, v.name, v.labels, v.preview_url)
Each voice has a voice_id for text to speech requests, labels that describe it (gender, age, accent and intended use) and a preview_url for a sample. You can therefore listen to a voice before your first paid request. In addition to your own list, you can access a shared voice library through GET /v1/shared-voices, with the filters language, gender, age, accent and use_cases.
Adjust the chosen voice with the voice_settings field: stability controls how even the delivery is, similarity_boost controls closeness to the original timbre, and the other settings are style, use_speaker_boost and speed. In Eleven v4 and Eleven v3, set emotions directly in the text with audio tags in square brackets, such as [whispers] or [laughs].
How to turn on streaming speech
A finished file works well for video and podcasts, but a bot or assistant should start playback as early as possible. The /stream path returns audio as it is generated, so you can play the first chunks while the rest is still in progress.
curl -N -X POST "https://llmbox.cc/v1/text-to-speech/VOICE_ID/stream?output_format=mp3_44100_128&optimize_streaming_latency=2" \
-H "xi-api-key: $LLMBOX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Let me look at your order.", "model_id": "eleven_v4_turbo"}' \
-o reply.mp3
In the ElevenLabs SDK, use the stream method for the same path. Chunks arrive one after another, and you can pass them directly to a player or client:
audio = client.text_to_speech.stream(
voice_id="VOICE_ID",
text="Let me look at your order.",
model_id="eleven_v4_turbo",
output_format="mp3_44100_128",
)
with open("reply.mp3", "wb") as f:
for chunk in audio:
f.write(chunk)
The optimize_streaming_latency parameter accepts an integer from 0 to 4. For streaming speech, choose a model built for real-time use: Eleven v4 Turbo or Eleven Flash v2.5.
How to choose an audio format
Set the format in output_format; the default is mp3_44100_128. Recommended formats by task:
| Task | Format |
|---|---|
| Podcast, article narration, bot replies | mp3_44100_128 or mp3_44100_192 |
| Video editing | wav_44100 or wav_48000 |
| Web and mobile apps, compact files | opus_48000_64 and other opus_48000_* |
| Processing in your own code, raw audio | pcm_16000 … pcm_48000 |
| Telephony | ulaw_8000 or alaw_8000 |
| Apple players | m4a_aac_44100_128 |
In the OpenAI format, set the format with the response_format parameter: mp3, opus, wav or pcm. The full list of values is in the ElevenLabs-compatible API documentation page.
How to voice text for a video
For a video or course, use Eleven v4 and the lossless WAV format, which editing software widely supports. Split the script into paragraphs so that each fragment becomes a separate file. If one phrase needs rewriting, you can regenerate only that fragment rather than the entire text.
import os
from elevenlabs.client import ElevenLabs
client = ElevenLabs(base_url="https://llmbox.cc", api_key=os.environ["LLMBOX_API_KEY"])
VOICE_ID = "VOICE_ID"
SETTINGS = {"stability": 0.5, "similarity_boost": 0.75}
with open("script.txt", encoding="utf-8") as f:
paragraphs = [p.strip() for p in f.read().split("\n\n") if p.strip()]
for i, text in enumerate(paragraphs):
audio = client.text_to_speech.convert(
voice_id=VOICE_ID,
text=text,
model_id="eleven_v4",
output_format="wav_48000",
voice_settings=SETTINGS,
)
with open(f"part_{i:03}.wav", "wb") as out:
for chunk in audio:
out.write(chunk)
Using the same voice and settings for every fragment keeps the sound consistent across the video. If the script has many numbers, dates and phone numbers, compare the result with Eleven Multilingual v2: according to ElevenLabs documentation, it reads them more carefully.
How to build a podcast with two voices
A dialogue podcast is assembled from lines generated with two voices. Generate each line separately with the appropriate voice, then join the files into one episode. A catalog text model can write the episode script with the same key; the guide DeepSeek API in Python: chat, streaming, JSON and functions shows how to do this in Python.
script = [
("VOICE_ID_HOST", "Hi! Today we're looking at how to voice texts through an API."),
("VOICE_ID_GUEST", "And we'll start with the main thing: choosing a voice."),
("VOICE_ID_HOST", "Then let's listen to the samples first."),
]
for i, (voice_id, line) in enumerate(script):
audio = client.text_to_speech.convert(
voice_id=voice_id,
text=line,
model_id="eleven_v4",
output_format="mp3_44100_128",
)
with open(f"line_{i:03}.mp3", "wb") as out:
for chunk in audio:
out.write(chunk)
You can join the lines into one file with ffmpeg:
for f in line_*.mp3; do echo "file '$f'"; done > list.txt
ffmpeg -f concat -safe 0 -i list.txt -c copy podcast.mp3
For the host and the guest, pick voices with clearly different timbres so listeners can tell them apart easily.
How to generate voice replies for a bot
The bot receives a question, a text model prepares the answer, and Eleven v4 Turbo generates the speech. Both models work with one key through the OpenAI SDK. In the example below, a Telegram bot built with aiogram replies with a voice message and includes the reply text in the caption. The guide An AI Telegram bot in 15 minutes: Python and one API key explains how to create a bot and get its token.
import asyncio, os
from aiogram import Bot, Dispatcher
from aiogram.types import BufferedInputFile, Message
from dotenv import load_dotenv
from openai import AsyncOpenAI
load_dotenv()
client = AsyncOpenAI(base_url="https://llmbox.cc/v1", api_key=os.environ["LLMBOX_API_KEY"])
bot = Bot(os.environ["BOT_TOKEN"])
dp = Dispatcher()
@dp.message()
async def answer(msg: Message):
if not msg.text:
return
r = await client.chat.completions.create(
model="deepseek/deepseek-v4.1-flash",
messages=[
{"role": "system", "content": "Answer briefly, in two or three sentences: the answer will be read aloud."},
{"role": "user", "content": msg.text},
],
)
text = r.choices[0].message.content or ""
speech = await client.audio.speech.create(
model="eleven_v4_turbo", voice="nova", input=text, response_format="mp3",
)
voice = BufferedInputFile(speech.content, filename="answer.mp3")
await msg.answer_voice(voice, caption=text[:1024])
asyncio.run(dp.start_polling(bot))
The system message asks the model to answer briefly because long monologues are tiring to hear and text to speech is billed per character. Send text to speech requests from your own server; users can extract keys embedded in browser or mobile code.
How to estimate the cost
Text to speech is billed per character at the model's rate per 1,000 characters. Audio tags in square brackets are part of the text and also count toward the total. The length and format of the resulting audio do not affect the price, so you can estimate the cost of a book, course or podcast episode in advance from the text length. Rates and a calculator are on each model's page: Eleven v4, Eleven v4 Turbo, Eleven Multilingual v2, Eleven Flash v2.5.
Requests to the voice list are free. A request rejected before speech generation because of an error in the body, an invalid key or an insufficient balance costs nothing.
Charges are deducted from a prepaid balance based on actual usage, with no subscription. The cost of each request is shown in the Logs section of the cabinet. To track video voiceover and a voice-enabled bot separately, issue a separate key for each project and set a Spend limit for it.
Where to go next
All text to speech parameters, the full list of formats and the error codes are in the ElevenLabs-compatible API documentation page, and connecting the Python and Node SDKs is covered in OpenAI and ElevenLabs SDKs. To compare models on your own material, generate the same paragraph with one voice and two similar models; only the model string changes.
Questions
Do I need an ElevenLabs account and key?
No. Requests use your llmbox key from the cabinet's Keys section. The same key works with the catalog's text models, so one application can generate both the text and its voiceover.
How long can the text be in a single request?
A request accepts up to 50,000 characters, but each model has its own limit. According to ElevenLabs documentation, Eleven v4 and Multilingual v2 accept up to 10,000 characters, Eleven v3 up to 5,000, and Flash v2.5 up to 40,000. Split long text into paragraphs or chapters.
Can I generate speech with the OpenAI SDK?
Yes, through the /v1/audio/speech path. OpenAI voices such as alloy or nova are mapped to ElevenLabs voices, and any other voice value is treated as an ElevenLabs voice ID.
Are requests to the voice list billed?
No. Accessing and searching the voice list and using the shared voice library are free and do not draw on your balance.
How do I add emotion, laughter or whispering to the speech?
In Eleven v4 and Eleven v3, use audio tags in square brackets directly in the text, for example [whispers] or [laughs]. Use the voice_settings field to adjust the voice's steadiness and character.
Published November 15, 2026


