End of turn
For voice bots: end each segment as soon as the caller sounds finished, and know what ended it, to answer sooner.
A voice bot answers when the caller has finished. With a pause alone (vad), it must wait out the whole pause after every sentence, or cut people off when they stop to think. With commit=turn, the service also listens to how the speech ends, its intonation and rhythm, and ends the segment as soon as the speaker sounds finished.
Romanian real-time models
End of turn works with Romanian real-time models, such as vatis_ro_v9_realtime. Its model is tuned on Romanian phone calls. It costs nothing extra: a session is billed by its audio seconds, as any other.
When to use it
| commit | A segment ends | Suits |
|---|---|---|
vad (default) | after a pause of vad_silence_s (1.5 s). The final comes about 1.5 s after the last word. | captions, meetings, a bot that can wait |
turn | as soon as the speaker sounds finished, else after a pause of vad_silence_s. When the speaker sounds finished, the final comes about 0.5 s after the last word at the median. | voice bots that answer callers |
manual | when your bot sends {"type": "commit"}. The final comes a fraction of a second after it. | bots that detect the end of a turn themselves, push-to-talk |
A commit works with turn too: send it to end a segment at once, for example when the caller presses a key.
How it works
- At every pause, the service checks whether the speaker sounds finished: after 0.4 s of silence after the last word, then at 0.6 s and 1.0 s.
- When they sound finished, the segment ends, and its final has
"end_reason": "turn". - When they do not, the segment ends after
vad_silence_sof silence, as withvad. Here it is the longest pause: 1.5 s by default, 0.2 to 3.0. Its final has"end_reason": "pause". - The text, words and times of a final are made as with
vad: only where a segment ends differs. - With two channels (
multichannel=true), each channel has its own turns.
Ask for end of turn
Add commit=turn to the request parameters of the session, and turn_sensitivity if you want another than 0.5 (Turn sensitivity). The rest of the program is the one of The whole program.
// Request parameters: end of turn, and its sensitivity (0 to 1)
const params = {
model_id: "vatis_ro_v9_realtime",
commit: "turn",
turn_sensitivity: "0.5",
};Expected result: session.started says so in its config:
{"type": "session.started", "session_id": "sess_8d41c2a7e09b4f6a9c03d5e1b2a7f480",
"model_id": "vatis_ro_v9_realtime",
"config": {"commit": "turn", "turn_sensitivity": 0.5, "vad_silence_s": 1.5, ...}}Answer when the turn ends
Keep the text of each final, and answer when a final ends the turn. Here answer stands for your bot: it gets what the caller said since its last answer, and replies.
let heard = []; // what the caller said since the bot last answered
// in ws.onmessage
if (message.type === "final") {
if (message.text) heard.push(message.text);
// turn: they sounded finished; pause: the longest pause passed
const reason = message.end_reason;
if (heard.length && (reason === "turn" || reason === "pause")) {
answer(heard.join(" ")); // your bot's reply
heard = [];
}
}If the caller goes on while your bot replies (a partial with text comes), stop the reply and listen: their next final carries on what they said.
What ended the segment
Every final of a commit=turn session has end_reason. Other sessions never have it.
| end_reason | What happened | What a bot can do |
|---|---|---|
turn | The speaker sounded finished. | Answer now. |
pause | vad_silence_s of silence passed, and the speaker did not sound finished. They may go on: their next words open a new segment. | The caller has been silent for the longest pause: answer, or keep the text and give them a moment more. |
commit | The answer to your commit. | Go on as your bot decided when it sent the commit. |
end | The session's last finals: after your end, or before a restart of the server ends the session. | Keep the text: nothing more comes in this session. After a restart, connect again (Reconnect after a restart). |
A finished question, then a pause in the middle of a sentence:
{"type": "partial", "segment_id": 4, "text": "aș vrea să mut programarea",
"start": 20.12, "end": 21.76, "speaker": null}
{"type": "final", "segment_id": 4, "text": "Aș vrea să mut programarea de joi.",
"start": 20.12, "end": 22.30, "speaker": null, "end_reason": "turn"}
{"type": "final", "segment_id": 5, "text": "Da, și",
"start": 25.02, "end": 25.61, "speaker": null, "end_reason": "pause"}A final with an empty text (a commit with nothing said since the last final) has a reason too. Skip it.
Turn sensitivity
turn_sensitivity sets how finished the speaker must sound: 0.0 to 1.0, 0.5 by default, only with commit=turn.
- Higher answers sooner, and cuts more pauses inside a sentence: a caller who stops to think may get an answer before they finish.
- Lower waits until the speaker sounds more clearly finished: fewer cuts, and more finals wait for the longest pause.
vad_silence_sis the most a final waits when the speaker does not sound finished. A shorter one answers those sooner, and cuts more of them.
Start with the default. If your bot cuts callers off, lower it; if it answers too late, raise it.
A bot that labels speakers
With diarize=true, a final waits until speaker separation has passed its last word, about a second behind the audio, which takes back the time end of turn saves. Send speaker_updates=true too: the final comes as soon as its text is done, and its speakers follow in a final.speakers message (The text first, its speakers after). A bot on a two-channel call needs neither: each channel is its speaker.
Refusals
A session that asks for end of turn the wrong way is refused before session.started, with invalid_parameter and close code 1008:
turn_sensitivitywithoutcommit=turn, or outside 0 to 1:paramturn_sensitivity.commit=turnwith a model that is not Romanian:paramcommit.
{"type": "error", "code": "invalid_parameter",
"message": "turn_sensitivity: needs commit=turn", "param": "turn_sensitivity"}Every code: Errors in a session.