ElevenLabs Text to Dialogue
Generate dialogue with per-line voices over HTTP or send turns incrementally over a WebSocket.
Text to Dialogue assigns a voice_id to each input line. Set the ModelSell URLs, API key, and an accessible voice ID as shown in the ElevenLabs quickstart. Text to Dialogue overview
| Transport | Supported models | Default |
|---|---|---|
| HTTP | eleven_v4, eleven_v3 | eleven_v3 |
| Single-context WebSocket | eleven_v4, eleven_v4_turbo, eleven_v3, eleven_v3_conversational | eleven_v3_conversational |
| Multi-context WebSocket | eleven_v3, eleven_v3_conversational | eleven_v3_conversational |
HTTP dialogue
Submit the full script as a JSON inputs array. Each entry requires text and voice_id. Use up to 10 distinct voices and keep the combined input to 2,000 characters per request for reliable output. Optional settings controls delivery. On supported models, previous_text and future_text can each provide up to 100 characters of surrounding context. Create dialogue request
| POST path | Response |
|---|---|
/elevenlabs/v1/text-to-dialogue | Binary audio for the full script |
/elevenlabs/v1/text-to-dialogue/stream | Streaming binary audio |
/elevenlabs/v1/text-to-dialogue/with-timestamps | JSON with Base64 audio, alignment, and voice segments |
/elevenlabs/v1/text-to-dialogue/stream/with-timestamps | Stream of JSON objects with Base64 audio, alignment, and voice segments |
The example uses jq to build the JSON request. Set ELEVENLABS_SECOND_VOICE_ID to a second accessible voice for two speakers. If it is omitted, both lines use the same voice.
jq -n \
--arg first "$ELEVENLABS_VOICE_ID" \
--arg second "${ELEVENLABS_SECOND_VOICE_ID:-$ELEVENLABS_VOICE_ID}" \
'{model_id: "eleven_v4", inputs: [
{text: "Are we ready to record?", voice_id: $first},
{text: "Yes. Let us begin.", voice_id: $second}
]}' | curl --fail-with-body --no-buffer \
"$MODELSELL_BASE_URL/elevenlabs/v1/text-to-dialogue/stream?output_format=mp3_44100_128" \
-H "xi-api-key: $MODELSELL_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary @- \
--output dialogue.mp3Use output_format to choose the audio encoding, sample rate, and bitrate. For timestamp responses, decode audio_base64 and use voice_segments to associate portions of audio with the input line and voice. Buffer complete JSON objects in the timestamp stream before decoding. Stream binary audio · Dialogue with timestamps · Stream timestamps
Single-context WebSocket
Connect to GET /elevenlabs/v1/text-to-dialogue/stream-input?model_id=.... Send voices first, then send inputs with registered voice IDs. Register one voice for eleven_v4_turbo or eleven_v3_conversational. Set new_turn: true to start a turn explicitly. Changing voice_id also starts a new turn. Realtime dialogue guide
Use flush to synthesize buffered short lines while the socket stays open. close_socket flushes the remaining audio and ends the session. Decode each Base64 audio field. is_final_audio_for_turn marks the end of a turn and is_final ends the connection. sync_alignment=true requests alignment when available. Dialogue WebSocket
Install websocket-client before running this example.
import base64
import json
import os
from websocket import create_connection
base = os.environ["MODELSELL_WS_URL"].rstrip("/")
voice = os.environ["ELEVENLABS_VOICE_ID"]
socket = create_connection(
f"{base}/elevenlabs/v1/text-to-dialogue/stream-input"
"?model_id=eleven_v4_turbo&output_format=mp3_44100_128",
header=[f"Authorization: Bearer {os.environ['MODELSELL_API_KEY']}"],
timeout=30,
)
try:
socket.send(json.dumps({"voices": [voice]}))
socket.send(json.dumps({
"inputs": [{"text": "Welcome to the studio.", "voice_id": voice}]
}))
socket.send(json.dumps({"close_socket": True}))
with open("dialogue-ws.mp3", "wb") as output:
while True:
event = json.loads(socket.recv())
if event.get("error"):
raise RuntimeError(event)
if event.get("audio"):
output.write(base64.b64decode(event["audio"]))
if event.get("is_final"):
break
finally:
socket.close()Multi-context WebSocket
Connect to GET /elevenlabs/v1/text-to-dialogue/multi-stream-input?model_id=eleven_v3 for up to five simultaneous dialogue contexts. Use a separate context_id for each context and register its voices in the first frame. Include context_id in the corresponding input and control frames and use it to route received audio. close_context flushes that context and returns its final frame. Use keep_alive to reset the context's 20-second inactivity timer and close_socket to finish all contexts. Multi-context dialogue · Model support by socket
For shared channels, omit provider-owned pronunciation dictionaries and historical request IDs. HTTP usage uses the upstream character-cost when present and otherwise estimates submitted text. WebSocket usage counts submitted text characters.