Speaker gate
A caller on speakerphone, a TV in the next room, a colleague talking across the desk: the speech recognizer hears all of it, and your agent answers whoever spoke last. The speaker gate compares each utterance with the voice it learned at the start of the call, so your agent only acts on the caller.
What it does
The first utterance of a call enrolls the caller. Every later utterance is scored against that voice, and the result decides what your agent receives and whether the speech may interrupt the agent while it is talking. The gate is off by default and costs nothing while it is off. It is a project setting, and an agent can also change it during a call.
Modes
Set speakerGate.mode in the dashboard (Project Settings → Voice (STT / TTS) → Advanced voice pipeline → Speaker gate) or with the CLI:
voicethere projects voice-advanced set speakerGate.mode auto
| Mode | What your agent receives |
|---|---|
disabled (default) | Every final transcript, exactly as without the gate. No speaker fields. |
auto | Only the enrolled caller's finals, as the usual user_speech_final event. Anyone else becomes a user_speech_ignored event with no text. |
manual | Every final, each labelled with a speaker. Your agent decides what to do with it. |
In auto, a voice that is not the caller produces:
{ "type": "user_speech_ignored", "reason": "speaker_mismatch", "utteranceId": "utt_42" }The ignored event carries no transcript, so nothing the bystander said is stored in the conversation history. In manual the final looks like this:
{
"type": "user_speech_final",
"text": "what about the other plan",
"speaker": "other"
}speaker is caller, other or unknown. When the gate could not decide, the event also carries speakerUnknownReason, and it may carry speakerCheckWindows and speakerRechecked to show how many times it looked.
Barge-in
speakerGate.bargeIn applies in auto and manual.
caller_only(default): a voice that is not the caller cannot interrupt the agent.anyone: barge-in ignores the verdict. The gate still scores and labels, but it never holds an interruption back.
With caller_only, an interruption waits until the gate has heard enough speech to decide, so it can start a moment later than without the gate. When there is no verdict yet, this is what happens:
speakerUnknownReason | Barge-in |
|---|---|
not_enrolled | Goes through. There is no caller voice to compare with yet. |
short | Held until the phrase ends plus the STT gate hold, then decided on what was heard. Turn on speakerGate.suppressShortBargeIn to drop these instead. |
timeout, error, no_embedding | Goes through. A failed check never silences the caller. |
loading | Goes through. While the speaker model loads after the first switch-on in a session, the verdict is unknown with this reason. |
Enrollment
The gate enrolls from the first speech of the call, so the caller should be the first person to talk. Enrollment survives a change of mode within the call. If the wrong person enrolled, for example because someone else spoke first, start over from your agent:
import { defineAgent, resetSpeakerEnrollment } from "@voicethere/agent";
export default defineAgent({
async onUserSpeechFinal({ sessionId }) {
const result = await resetSpeakerEnrollment(sessionId);
// { ok: true } or { ok: false, reason: "not_available" | "timeout" }
},
});The next utterance enrolls again.
Switching during a call
An agent can change the mode and the barge-in policy while the call is running. The change applies from the next utterance and enrollment is kept.
import {
defineAgent,
getSpeakerGate,
setSpeakerGate,
} from "@voicethere/agent";
export default defineAgent({
onSessionStart(ctx) {
// speakerGate is set only when the runner can switch the gate:
// { available: true, mode, bargeIn }. Otherwise it is absent;
// getSpeakerGate(sessionId) then returns { available: false }.
console.log(ctx.speakerGate?.mode);
},
async onUserSpeechFinal({ sessionId }) {
// Only the caller reaches the agent, and nobody else can interrupt.
await setSpeakerGate(sessionId, { mode: "auto", bargeIn: "caller_only" });
// Everyone reaches the agent with a speaker label, and anyone can interrupt.
await setSpeakerGate(sessionId, { mode: "manual", bargeIn: "anyone" });
// Back to no gating.
const result = await setSpeakerGate(sessionId, { mode: "disabled" });
// { ok: true, mode, bargeIn }
// or { ok: false, reason: "not_available" | "invalid" | "timeout" }
},
onUserSpeechIgnored({ sessionId, utteranceId, reason }) {
// auto mode: a voice that is not the caller. No transcript.
},
});These calls need @voicethere/agent 0.29.0 or newer. Outside a runner session, or on a runner without the gate, both setSpeakerGate and resetSpeakerEnrollment resolve with { ok: false, reason: "not_available" }.
If the gate is switched off while a held interruption is waiting for a verdict and the reply is still playing, the interruption is released at once. An utterance that is already in progress when you switch keeps whatever verdict it had, or unknown if it had none.
A project can start with the gate disabledand still be switched on mid-call, so a voice agent can offer a spoken command such as "only listen to me".
Starter template
The speaker-gate template shows all three modes. Pick Speaker gate under Voice when you create a project. It answers the caller, says one short line when it hears someone else in manual mode, and switches mode from a chat command (speaker-gate:auto, manual, disabled, reset) or a spoken phrase. Its source is in the agent repository.
Tuning
Seven further settings change how the gate scores and splits speech. Their defaults are the benchmark-tuned values, and Speaker gate tuning lists each one with its range, what raising or lowering it does, and the order to set the settings that depend on each other. Start with speakerGate.threshold if bystanders get through or the caller is rejected, and with speakerGate.enrollSpeechMs if the first seconds of a call are misjudged.
Split on speaker change
Without it, a caller and a bystander who talk with no pause in between end up in one utterance, and the final transcript carries both voices. Turn on speakerGate.splitOnSpeakerChange and the gate ends the utterance at the point the voice changes, in both directions. The first part is decoded again on its own, and the rest starts a new utterance.
- Caller, then someone else.The caller's utterance ends where the caller stops. The other voice starts a new utterance, which never interrupts your agent.
- Someone else, then the caller.The first utterance (the other voice) ends just before the caller starts, and the caller's words start a new utterance that can interrupt your agent. Before this was supported, the whole utterance was labelled as the caller's, with the other voice's words inside the caller's final. The gate splits only when an earlier check scored clearly as someone else (under 0.20, where the match threshold is 0.459). If none did, it may have been the caller on a bad window, and the utterance is labelled as the caller's as before.
Each new part is watched on its own, so other, caller, other, caller gives one split per confirmed change. The gate needs a confirming window of caller speech before it cuts, so the cut is a best guess. When nobody pauses, a few words of the other voice right before the caller can stay at the start of the caller's part, and the gate prefers that to clipping the caller. A different voice that sounds like the caller can still pass as the caller, and the split follows the gate's verdict.
The gate keeps the caller's words first and accepts some words from other voices. When the other voice is never clearly different from the caller (no check scores it clearly as someone else, under 0.20), the gate does not split. The whole utterance, the other person's sentence included, is then labelled as the caller's. This is deliberate, because cutting there would risk the caller's own words. It happens more with similar voices, and in our tests on real speech it was roughly one in ten handovers with no pause. When the speakers leave a pause between them, the two are separate utterances and this does not apply.
speakerGate.splitOnSpeakerChange also keeps a barge-in on hold while the first voice is not the caller, even if speakerGate.recheckOnOther is off. It needs the recheck window cap above 1. Projects that already have it on get the two-way split with no change on their side.
Your agent gets an onUserUtteranceSplit event with sessionId, fromUtteranceId, toUtteranceId, splitAtMs, and from / to (caller or other, in either order) (@voicethere/agent 0.31.0 or later). The final of the first part carries reason: "speaker_split", or speaker_split_redecode_timeout if the second decode did not finish in time. In auto mode a part that belongs to another voice is dropped as user_speech_ignored. In manual mode it is delivered as its own utterance with the speaker other. Nothing is sent while the gate is disabled. The conversation history links the two utterances.
A split can add up to one second of billed usage, because each part is rounded up to a whole second. The second decode of the first part is not charged.
Adapt the reference during the call
speakerGate.adaptReference is off by default and has no effect while the split is off. When on, the in-memory reference voice is refined from later confident caller speech, so a caller whose line changes during a long call (EQ, codec, level) is rejected less often. Only an utterance that ended with no split and with every check on the caller counts, each update is small, and it is dropped if it would move the reference too far from the voice that was enrolled.
It trades one error for another. In our bench of 40 real speakers, rejected callers after a channel change fell from 13.6% to 2.2%. Bystander accepts rose in every set we tried: from 0.014% to 0.085% on clean speech, from 0.057% to 0.184% with background noise, and from 1.5% to 4.2% with the three bystanders who sound closest to each caller. Turn it on for long calls where the caller's channel changes and a few more bystander accepts cost less than a rejected caller. The reference stays in memory and is never stored.
STT vendors
The gate works with every speech-to-text vendor. It listens to the call audio itself and does not depend on which vendor transcribes it. Three things are worth knowing before you rely on it.
- The voice model was benchmarked on English speech only. We have not measured other languages.
- A split decodes the first part again on one extra speech-to-text stream. On a cloud vendor that is billed to us by the vendor, not to you, and you are not charged for it. It still adds a little load, which is why the setting is off by default.
- The re-decode is tested in the deferred finalize mode that Deepgram, ElevenLabs, Mistral, Fish Audio and the cluster speech service use, with a simulated recognizer rather than each live vendor.
Limits
- We tested bystanders at least 15 dB quieter than the caller. A voice as loud as the caller's can pass as the caller, so the gate is a filter and not an identity check.
- The speaker model is trained on English speech.
- Short utterances such as "yes" may not contain enough speech to score. See the table above for what happens then.
- It is meant for one caller per call. Two people sharing a phone should use
disabledormanual.
Use it with the adaptive VAD. A detector that follows the noise floor passes cleaner speech to the gate, and the gate then has less background to mistake for another person.
Privacy and consent
The gate builds a voice embedding of the caller from the live call. That can count as biometric data under GDPR, the Illinois Biometric Information Privacy Act and similar laws. You are the controller: tell callers that their voice is compared with the start of the call and get their consent where the law requires it before you turn the gate on. The embedding stays in memory for the session. With speakerGate.adaptReference on, that in-memory reference is refined from later confident caller speech, and the refined version is also kept in memory only. It is never stored, logged or sent anywhere, and it is dropped when the call ends or your agent resets the enrollment. The details are in the Privacy Policy and your obligations are in the Terms of Service.
Latency
A barge-in under caller_onlywaits for the gate to hear up to about 1.5 seconds of speech (the library's checkSpeechMs) before it decides. If your agent needs instant interruption and trusts the room, set speakerGate.bargeIn to anyone.