Skip to content

End of turn

A voice agent must answer when the caller has finished, not at every pause: “my number is… zero six…” has pauses, and is not finished. End-of-turn detection listens to how the speaker talks at each pause and sends an end_of_turn message when their turn is over.

Live APIend_of_turn
Pre-recorded (batch)Live only
Live modelssolaria-3 (every live model)
LanguagesEvery language of the model (supported languages)

Turn it on in the init body:

{ "end_of_turn": true }

Then answer when an end_of_turn message arrives. Each program prints the caller’s sentences and each end of turn:

end_of_turn.mjs
// npm install @gladiaio/sdk
import { readFileSync } from "node:fs";
import { GladiaClient } from "@gladiaio/sdk";
const { sampleRate, channels, pcm } = readWav(process.argv[2]); // a 16-bit PCM WAV file
const config = {
encoding: "wav/pcm",
sample_rate: sampleRate,
bit_depth: 16,
channels,
model: "solaria-3",
language_config: {
languages: [
"en"
]
},
endpointing: 0.3,
end_of_turn: {
eot_threshold: 0.8,
stop_s: 1.2
},
messages_config: {
receive_partial_transcripts: true
}
};
const client = new GladiaClient({
apiKey: process.env.GLADIA_API_KEY,
apiUrl: process.env.GLADIA_API_URL ?? "https://eu1.api.gladia.io",
});
// `end_of_turn` is a Gladia Connect option not in the SDK's types yet: the SDK sends it as is.
const session = client.liveV2().startSession(config);
session.on("message", (message) => {
if (message.type === "transcript" && message.data.is_final) console.log("caller:", message.data.utterance.text);
if (message.type === "end_of_turn") console.log(`end of turn (${message.data.reason}): answer now`);
});
session.on("error", (error) => {
console.error(error);
process.exitCode = 1;
});
session.once("ended", () => process.exit());
const step = (sampleRate * channels * 2) / 10; // 100 ms of audio per chunk
for (let start = 0; start < pcm.length; start += step) {
session.sendAudio(pcm.subarray(start, start + step)); // live audio: send each chunk as it is captured
}
session.stopRecording();
function readWav(path) {
const file = readFileSync(path);
let fmt, pcm;
for (let pos = 12; pos < file.length; ) {
const id = file.toString("ascii", pos, pos + 4);
const size = file.readUInt32LE(pos + 4);
if (id === "fmt ") fmt = { channels: file.readUInt16LE(pos + 10), sampleRate: file.readUInt32LE(pos + 12) };
if (id === "data") pcm = file.subarray(pos + 8, pos + 8 + size);
pos += 8 + size + (size % 2);
}
return { ...fmt, pcm };
}

The message:

{
"type": "end_of_turn",
"session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b",
"data": { "channel": 0, "probability": 0.97, "reason": "model", "end": 18.42, "speech_duration": 3.1 }
}

reason is model when the probability that the speaker finished crossed eot_threshold, or timeout when the silence reached stop_s whatever the probability.

"end_of_turn": true uses the defaults, and so does an empty object ("end_of_turn": {}); an object turns it on and changes some of them. Omitted or false: off. An unknown option or a value out of its range is a 400 that names it.

{ "end_of_turn": { "eot_threshold": 0.8, "stop_s": 1.2 } }
option range what it does
eot_threshold 0 to 1 (excluded) Probability above which the turn ends. Lower: faster answers, more interruptions.
silence_ms 1 to 10000 Silence, in ms, before a pause is evaluated: every pause of the turn, also the ones after the speaker went on.
stop_s up to 60 Silence, in seconds, that ends the turn anyway.
emit_scores Also send end_of_turn_score for each evaluation, to calibrate eot_threshold.
min_end_of_turn_silence_when_confident 0 to 5000 Silence, in ms, that must follow a turn judged complete before the end of turn is sent; speech meanwhile cancels it. 0: as soon as the model is sure.
speculation true, or { threshold } Compare each final to the text of the end_of_turn and send a speculation verdict (below). Off when omitted.
window_s up to 8 Audio, in seconds, an evaluation reads.
reeval_ms 0 to 10000 Interval between two evaluations of the same pause.
eager_eot_threshold 0 to 1 (excluded), at most eot_threshold Send an eager_end_of_turn from this probability, before the turn is confirmed (below). Off when omitted.

threshold and confirm_ms, the first names of eot_threshold and min_end_of_turn_silence_when_confident, still work but are deprecated: send the new names. They are refused from January 31, 2027.

GET /v2/live/defaults returns the defaults in force.

A voice agent that waits for end_of_turn before calling its LLM adds the LLM’s whole latency after the caller stopped. With eager_eot_threshold, the engine also tells you when the turn is probably over, so the LLM can start early:

{ "end_of_turn": { "eot_threshold": 0.9, "eager_eot_threshold": 0.6 } }

At a pause whose probability reaches eager_eot_threshold, an eager_end_of_turn arrives:

{
"type": "eager_end_of_turn",
"session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b",
"data": { "channel": 0, "probability": 0.72, "end": 4.18, "speech_duration": 3.2 }
}

Then exactly one of:

  • end_of_turn: the turn is confirmed. Send the answer you prepared.
  • turn_resumed: the caller spoke again. Drop the answer you prepared, and keep listening:
{
"type": "turn_resumed",
"session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b",
"data": { "channel": 0, "end": 4.62 }
}

end is where the caller started speaking again. A resumed turn can bring a new eager_end_of_turn at its next pause.

  • It costs LLM calls. Each turn_resumed throws away an answer you paid for. The lower eager_eot_threshold, the earlier the eager, and the more resumes. Values from 0.3 to 0.9 work; turn on emit_scores on real calls and pick one under the probabilities of your callers’ mid-sentence pauses.
  • Send eot_threshold with it. eager_eot_threshold above eot_threshold is a 400 on the init. Without eot_threshold, the server’s default applies (GET /v2/live/defaults), and an eager threshold above it is a 400 too.
  • No final at eager time. Build the LLM’s prompt from the partial transcripts; the final comes after end_of_turn, as without the eager.
  • No eager during a hold. While the caller dictates a phone number, an address or an amount, no eager is sent.
  • An eager can end without a confirmation. If the session ends (end_session) while an eager is open, neither end_of_turn nor turn_resumed is sent: drop the answer you prepared.
  • An end_of_turn with reason: model always follows an eager, sent just before it when none came at the pause. A reason: timeout end of turn can come without one.

Starting the LLM on eager_end_of_turn or end_of_turn answers earlier, but the call starts on the text the engine had at the pause. The final that closes the turn comes later, and it can differ: a last word that arrives late, a number written another way, or a caller who went on talking. With speculation, you are told whether the call you started on that text is still good, so you recompute only when needed.

{ "end_of_turn": { "speculation": true } }

For each turn, three messages arrive, in this order:

  1. end_of_turn, with text: the text to start the LLM call on.

With an eager threshold, eager_end_of_turn carries a text too. The final is compared to the text of the first message of the pause, so start the call on that one. The end_of_turn that confirms it may show a newer text; the call you started stays valid if the verdict says keep.

{
"type": "end_of_turn",
"session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b",
"data": { "channel": 0, "probability": 0.97, "reason": "model", "end": 4.18, "speech_duration": 3.2, "text": "book a table for two" }
}
  1. The final of the turn. Its utterance.speculation holds the verdict, the same as the message below.
  2. speculation, after the final (and after the other add-on messages of that final, if you enabled any), on a keep too:
{
"type": "speculation",
"session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b",
"created_at": "2026-10-17T10:00:00.000Z",
"error": null,
"data": {
"utterance_id": "00_00000003",
"utterance": { "text": "Book a table for two.", "start": 1.0, "end": 4.0, "language": "en", "confidence": 0.9, "channel": 0, "words": [] },
"results": [
{
"eager_text": "book a table for two",
"eager_end": 4.18,
"similarity": 1.0,
"lexical_similarity": 1.0,
"recommendation": "keep",
"reason": "same_text"
}
]
}
}

recommendation is keep when similarity reaches the threshold, discard otherwise. reason is same_text, similar, text_changed or caller_went_on. The program below starts a fake LLM call (a timer standing in for your model) on end_of_turn, keeps it on keep, and restarts it on the final on a discard:

speculative_turn.mjs
// npm install @gladiaio/sdk
import { readFileSync } from "node:fs";
import { GladiaClient } from "@gladiaio/sdk";
const { sampleRate, channels, pcm } = readWav(process.argv[2]); // a 16-bit PCM WAV file
const config = {
encoding: "wav/pcm",
sample_rate: sampleRate,
bit_depth: 16,
channels,
model: "solaria-3",
language_config: { languages: ["en"] },
endpointing: 0.3,
end_of_turn: { speculation: true, stop_s: 1.2 },
messages_config: { receive_realtime_processing_events: true },
};
// Stands in for your LLM call: it answers after 300 ms unless it is cancelled.
function startLlm(prompt) {
const call = { prompt };
call.reply = new Promise((resolve) => {
const timer = setTimeout(() => resolve(`(answer to: ${prompt})`), 300);
call.cancel = () => {
clearTimeout(timer);
resolve(null);
};
});
call.reply.then((reply) => reply && console.log("agent:", reply));
return call;
}
const client = new GladiaClient({
apiKey: process.env.GLADIA_API_KEY,
apiUrl: process.env.GLADIA_API_URL ?? "https://eu1.api.gladia.io",
});
// `end_of_turn` is a Gladia Connect option not in the SDK's types yet: the SDK sends it as is.
const session = client.liveV2().startSession(config);
let call = null; // the LLM call started on the last end of turn
let judged = false; // the verdict of the last end of turn came
let settle; // resolves `verdict`
let verdict = new Promise((resolve) => (settle = resolve)); // pending until a verdict comes
let final = ""; // the last final of the caller
session.on("message", (message) => {
if (message.type === "end_of_turn") {
call?.cancel(); // a new end of turn replaces the call of the previous one
const text = message.data.text ?? "";
call = text ? startLlm(text) : null; // no text, no call, and no verdict will follow
if (text && judged) {
judged = false; // a verdict is coming for this turn
verdict = new Promise((resolve) => (settle = resolve));
}
console.log(`end of turn: LLM started on "${text}"`);
}
if (message.type === "turn_resumed") {
call?.cancel(); // the caller went on: drop the call, no verdict follows
call = null;
judged = true;
settle();
}
if (message.type === "transcript" && message.data.is_final) {
final = message.data.utterance.text;
console.log("caller:", final);
}
if (message.type === "speculation") {
judged = true;
settle();
const result = message.data.results[0];
if (result.recommendation === "keep") {
console.log(`KEEP ${result.similarity}`);
} else {
console.log(`DISCARD ${result.reason}`);
call?.cancel();
// `caller_went_on`: the turn was not over, wait for the next end_of_turn
call = result.reason === "caller_went_on" ? null : startLlm(final);
}
}
});
session.on("error", (error) => {
console.error(error);
process.exitCode = 1;
});
session.once("ended", async () => {
await call?.reply; // let the last answer print
process.exit();
});
const step = (sampleRate * channels * 2) / 10; // 100 ms of audio per chunk
for (let start = 0; start < pcm.length; start += step) {
session.sendAudio(pcm.subarray(start, start + step)); // live audio: send each chunk as it is captured
await new Promise((resolve) => setTimeout(resolve, 100)); // at the speed of speech, as a microphone would
}
// A live agent keeps the line open. This file is over: wait for the verdict before stopping, or the
// stop closes the turn before the engine has judged the pause (10 s at most, the file needs
// trailing silence for the engine to end the turn).
await Promise.race([verdict, new Promise((resolve) => setTimeout(resolve, 10_000))]);
session.stopRecording();
function readWav(path) {
const file = readFileSync(path);
let fmt, pcm;
for (let pos = 12; pos < file.length; ) {
const id = file.toString("ascii", pos, pos + 4);
const size = file.readUInt32LE(pos + 4);
if (id === "fmt ") fmt = { channels: file.readUInt16LE(pos + 10), sampleRate: file.readUInt32LE(pos + 12) };
if (id === "data") pcm = file.subarray(pos + 8, pos + 8 + size);
pos += 8 + size + (size % 2);
}
return { ...fmt, pcm };
}
  • A discard with caller_went_on means the turn was not over. The caller spoke again after the end_of_turn: cancel the call and wait for the next end_of_turn, do not restart on this final.
  • The message comes on a keep too. similarity is useful on its own to see how often the pause text and the final agree on your calls.
  • A turn can end without a verdict. No speculation message comes when the end_of_turn has an empty text (the engine had nothing to start on: do not start a call), or when a turn_resumed follows (the caller went on: cancel the call). A new end_of_turn also replaces the call of the previous one: cancel it first, as the program does.
  • The block can grow. The engine may add fields to the block and values to reason. Read recommendation to decide, and treat reason and any other field as information, not as a closed list.
  • threshold is a trade-off. { "speculation": { "threshold": 0.9 } }: higher recomputes more often and answers the wrong thing less often; lower keeps more calls and risks answering on a stale text. Watch similarity on real calls before you change it.
  • Callbacks get speculation, not end_of_turn. The speculation message follows the other receive_realtime_processing_events messages on the callback; end_of_turn stays on the WebSocket.
  1. Use a low-latency model and profile: solaria-3-fast.
  2. Turn on partial transcripts to prepare the answer while the caller speaks.
  3. Answer on end_of_turn, with the finals received so far.
  4. If the caller speaks again before you answer, cancel and wait for the next end_of_turn.
  • Off unless you ask. A session without end_of_turn gets no end-of-turn message.
  • WebSocket only. end_of_turn messages are never sent to callbacks: the agent that answers must hold the WebSocket.
  • Per channel. Each channel has its own turns: with the caller and the agent on two channels, read channel.
  • eot_threshold is a trade-off. Lower answers sooner and interrupts more; higher waits for clearer endings. Turn on emit_scores on real calls to see the probabilities, then set it.
  • stop_s is your ceiling. Whatever the probability, a silence that long ends the turn (reason: timeout): keep it under what your callers will tolerate.
  • Endpointing still applies. Finals still come on each pause: buffer them, answer on end_of_turn. The finals option picks whether the end of the turn, the end of a sentence or the pause alone closes a final.
  • Python SDK: see above, use a raw WebSocket or the JavaScript SDK.
  • Eager end of turn is opt-in. Without eager_eot_threshold, no eager_end_of_turn or turn_resumed is sent.