Voice Activity Detection in Telephony

Voice activity detection (VAD) determines when a speaker starts and stops talking inside a live audio stream. This guide covers how VAD works in telephony pipelines, the difference between server_vad...
Voice activity detection on a phone call: speech segments highlighted and separated by a silence gap in the waveform.
In this article

AI Summary: This article covers voice activity detection (VAD) in telephony pipelines and is written for backend engineers integrating real-time AI into live phone calls. The OpenAI Realtime API documents two VAD modes, server_vad and semantic_vad, and transmits audio as base64-encoded PCM16 over WebSocket. Engineers must handle the format mismatch between that stream and the 8 kHz narrowband audio that PSTN carriers deliver, and must decide whether to manage turn boundaries manually or delegate them to the API. Teler’s WebSocket transport bridges carrier audio to AI models at a configurable sample rate of 8 kHz or 16 kHz, removing the need to build the telephony layer from scratch.

Scope: This walkthrough covers voice activity detection as implemented in the OpenAI Realtime API, verified against the API documentation current as of September 2026. It addresses the audio path from a PSTN call through Teler’s WebSocket transport to an AI model. It does not cover SIP-side configuration or WebRTC browser clients.

Quick Answer: Voice activity detection in telephony is the mechanism that identifies speech boundaries inside a continuous audio stream so a system knows when to start and stop processing a speaker’s turn. In 2026, the OpenAI Realtime API exposes this as server_vad or semantic_vad, configured via session.update, with audio delivered as base64 PCM16 over WebSocket.

Voice activity detection is the signal-processing layer that tells a telephony pipeline when a caller is speaking and when they have stopped, so the system can commit an audio turn, trigger a response, or handle a barge-in without waiting for a manual boundary signal.

What is voice activity detection?

Voice activity detection (VAD) is a signal classification process that labels each frame of an audio stream as either speech or non-speech, so downstream systems can act on turn boundaries without manual intervention. It operates at the media layer, below the speech-to-text (STT) engine and below the large language model (LLM), and it does not transcribe or interpret the content of what is said. VAD does not handle call routing, session initiation protocol (SIP) signaling, or public switched telephone network (PSTN) connectivity. A developer building a telephony AI agent must supply the carrier transport, the audio resampling path, and the call control logic; VAD handles only the speech-versus-silence classification within the audio that reaches it.

Why is voice activity detection hard to get right in telephony?

The core difficulty is that telephony audio and AI model audio operate at different sample rates, and VAD tuning that works in a clean studio environment fails on a live carrier line. PSTN audio follows ITU-T G.711, which encodes voice at 8 kHz with 8-bit companding. Most AI models, including the OpenAI Realtime API, expect 16 kHz or 24 kHz PCM. That mismatch means every audio frame must be resampled before it reaches the VAD engine, and any resampling artifact can trigger a false speech-start event.

Beyond sample rate, the turn-taking problem is genuinely hard. A caller who pauses mid-sentence to think should not trigger a response. A caller who finishes a question and waits for an answer should. The silence duration threshold that separates these two cases is not universal. It varies by speaker, language, and call context. Setting it too short causes the agent to interrupt; setting it too long adds latency that makes the conversation feel broken.

The prefix_padding_ms and silence_duration_ms parameters in the OpenAI Realtime API exist precisely because these failure modes are common. Front-word truncation happens when the VAD window does not include enough audio before the detected speech onset. Early cutoffs happen when the silence threshold fires before the speaker has finished. Both are tunable, but the right values depend on the specific call environment.

How does audio travel from a phone call to a VAD engine?

Understanding the full audio path is the prerequisite for tuning VAD correctly. Each hop in the chain introduces a format constraint or a latency cost, and a mismatch at any hop produces artifacts that the VAD engine will misclassify.

HopFormatSample rateTransportOwner
PSTN carrier to TelerG.711 PCM (mu-law or a-law)8 kHzSIP / RTPCarrier + Teler
Teler to your serverRaw PCM16, base64-encoded8 kHz or 16 kHz (configurable)WebSocketTeler
Your server to OpenAI RealtimeBase64 PCM16 at 24 kHz, or G.711 μ-law (audio/pcmu) at 8 kHzSet in session audio.input.formatWebSocketYour code
OpenAI VAD engineInternalInternalIn-sessionOpenAI

Teler streams call audio at a configurable sample rate of 8 kHz or 16 kHz, defaulting to 8 kHz. If you send audio to the OpenAI Realtime API as audio/pcm, it expects 24 kHz, so your server must resample before appending frames with input_audio_buffer.append. Alternatively, set the input format to audio/pcmu and convert Teler’s 8 kHz PCM to μ-law, which skips resampling entirely Skipping that step does not produce an error; it produces audio that the VAD engine will misread, because the timing relationships between frames are wrong at the wrong sample rate. This is the resampling hop that most teams discover too late.

Prerequisites

  • A Teler account with an active API key and at least one provisioned phone number. See the Teler documentation for number provisioning steps.
  • A WebSocket server capable of handling binary or text frames, written in Node.js 20+ or Python 3.11+.
  • An OpenAI API key with Realtime API access enabled.
  • A streaming resampling library, such as python-soxr (ResampleStream) in Python or a streaming resampler library in Node, unless you use audio/pcmu input.
  • Network reachability between your WebSocket server and both Teler’s edge and OpenAI’s Realtime endpoint. Both connections must remain open for the duration of a call.
  • Familiarity with the RFC 6455 WebSocket protocol, specifically connection lifecycle and close codes, because both Teler and OpenAI will close the socket on idle timeout.

How do you configure voice activity detection in the OpenAI Realtime API?

The OpenAI Realtime API exposes VAD through the turn_detection field of session.update. Two modes are documented: server_vad and semantic_vad. A third option is to set turn_detection to null, which disables automatic detection entirely and requires the client to manage turn boundaries manually.

Step 1: Open the Realtime WebSocket and configure the session

Send a session.update event immediately after the connection opens. The type field inside turn_detection controls which VAD mode the server uses. The threshold field accepts a float from 0.0 to 1.0, defaulting to 0.5; lower values make the detector more sensitive to quiet speech.

{
  "type": "session.update",
  "session": {
    "type": "realtime",
    "audio": {
      "input": {
        "format": { "type": "audio/pcm", "rate": 24000 },
        "turn_detection": {
          "type": "server_vad",
          "threshold": 0.5,
          "prefix_padding_ms": 300,
          "silence_duration_ms": 500
        }
      }
    }
  }
}

Watch prefix_padding_ms carefully: the VAD needs some speech before it fires, and prefix_padding_ms sets how much audio from before that point is kept in the turn. Values below 200 ms often clip the first word.

Step 2: Stream audio from Teler into the Realtime buffer

Teler delivers audio in chunks whose size you configure in multiples of 20 ms, defaulting to 400 ms. A smaller chunk size gets audio to the VAD sooner. Before forwarding each chunk to OpenAI, resample from 8 kHz (or 16 kHz if you configured that) to 24 kHz, then base64-encode the PCM16 bytes and send them with input_audio_buffer.append.

import base64
import json

async def forward_audio_chunk(teler_ws, openai_ws, resampler):
    raw_msg = await teler_ws.recv()
    payload = json.loads(raw_msg)
       if payload["type"] != "audio":
        return
    pcm_8k = base64.b64decode(payload["data"]["audio_b64"])
    pcm_24k = resampler.resample(pcm_8k, from_rate=8000, to_rate=24000)
    encoded = base64.b64encode(pcm_24k).decode("utf-8")
    await openai_ws.send(json.dumps({
        "type": "input_audio_buffer.append",
        "audio": encoded
    }))

The resampler call is blocking in this example; in production, run it in a thread pool executor so it does not stall the event loop while frames accumulate.

Step 3: Handle VAD events and barge-in

When server_vad is active, the OpenAI server emits input_audio_buffer.speech_started when it detects voice onset and input_audio_buffer.speech_stopped when it detects the end of a turn. On speech_started, if the assistant is currently speaking, flush Teler’s playback queue immediately to implement barge-in.

async def handle_openai_event(event, teler_ws):
    if event["type"] == "input_audio_buffer.speech_started":
        await teler_ws.send(json.dumps({"type": "clear"}))
    elif event["type"] == "input_audio_buffer.speech_stopped":
        pass  # server_vad commits automatically; no manual commit needed
       elif event["type"] == "response.done" and event["response"]["status"] == "cancelled":
        pass  # log and update conversation state

Sending {"type": "clear"} to Teler flushes all queued audio from the playback buffer, which is the correct barge-in implementation. After the clear, stop forwarding audio deltas from the interrupted response, which can still arrive from OpenAI, and send conversation.item.truncate with how much audio the caller actually heard.

Step 4: Manual turn control when VAD is disabled

When turn_detection is null, the server does not commit the audio buffer automatically. Your code must send input_audio_buffer.commit when the caller finishes speaking, then send response.create to trigger a response. If you need to discard buffered audio without committing it, send input_audio_buffer.clear. This mode gives you full control over turn boundaries but requires you to implement your own speech-end detection, typically with a client-side VAD library such as Silero VAD, py-webrtcvad, or Picovoice Cobra.

Voice activity detection modes compared: server_vad ends turns on silence, semantic_vad waits for the end of a thought.

Step 5: Choose between server_vad and semantic_vad

semantic_vad uses a turn-detection model in addition to energy-based detection, so it can distinguish a mid-sentence pause from a completed thought. It is documented as a newer mode and is not supported on all model versions. If you select semantic_vad with gpt-4o-realtime-preview-2024-10-01, the session returns an error; you must use a model version that supports it, such as gpt-4o-realtime-preview-2024-12-17 or the current gpt-realtime-2.1 family. For gpt-realtime-whisper, the documentation states that turn_detection must be omitted or set to null.

Most teams discover their latency problem is not the model, it is the resampling hop they added between the carrier and the STT engine. When you stream 8 kHz audio from a PSTN call and forget to upsample before it reaches the VAD, the silence thresholds fire at the wrong intervals and you spend weeks tuning parameters that were never the real issue.

– Subhash Kalluri, Founder & CEO, FreJun

What breaks in production with voice activity detection?

The failure modes below come from documented reports in the OpenAI community forums and the openai-realtime-api-beta GitHub repository. Each was reported once; frequency is noted honestly.

SymptomCauseFix
Assistant cannot be interrupted in VAD mode; it pauses briefly then continuesUnresolved in the source thread (GitHub issue #54, October 2024)No fix reported
appendInputAudio slows to a halt during long sessionsClient-side buffer never reset in server_vad mode; each append copies a growing buffer (GitHub issue #87, December 2024)Stop merging into the local buffer when turn_detection.type === server_vad
Semantic VAD fires on mic noise or background soundMicrophone gain too high; no pre-filtering before uploadLower mic gain; apply programmatic noise suppression before sending audio
Semantic VAD returns an error on session setupModel version does not support semantic_vad; reported with gpt-4o-realtime-preview-2024-10-01Switch to gpt-4o-realtime-preview-2024-12-17 or a current gpt-realtime-2.1 model
Multiple speech_started events with only the last matched by speech_endedSemantic VAD event pairing breaks under rapid segment boundaries (reported October 2025)No fix reported
Assistant audio cleared mid-sentence on false barge-inServer treats cough or assistant audio leaking into mic as user speech, even with interrupt_response: falseNo fix reported
Interruptions too sensitive; transcript not trimmed after interruptionOver-aggressive interruption handling plus incomplete post-interruption truncation logicReduce VAD sensitivity; handle truncation explicitly in the client

Common VAD failures in production

The false barge-in failure is the one that catches most teams in production. When the assistant’s audio leaks back into the microphone input, the VAD detects it as user speech and clears the output buffer. On a telephony call, acoustic echo cancellation (AEC) is the standard mitigation, but AEC must run before the audio reaches the VAD engine. If you are forwarding raw carrier audio to OpenAI without an AEC pass, you will see this failure on any call where the caller is not using a headset. Teler’s transport layer does not apply AEC automatically; that processing belongs in your bridge server.

One honest limitation of using Teler in this pipeline: the transport layer targets sub-100 milliseconds for packet delivery, but it does not guarantee that the resampling step your bridge server performs will stay within that budget. If your resampler is synchronous and your server is under load, the added latency can push total turn-detection delay past the threshold where conversations feel natural. Profiling the resampling path under realistic call volume is a required step before production launch.

Which voice activity detection approach fits your architecture?

There are four practical approaches to VAD in a telephony AI pipeline. The right choice depends on where you want the media to terminate and how much control you need over turn boundaries.

ApproachMedia terminates atLatency costOperational burdenLock-in
OpenAI Realtime server_vad or semantic_vad via Teler bridgeOpenAI WebSocket sessionResampling hop in your bridgeMedium: manage two WebSocket connections and resamplingOpenAI model and event model
Twilio Media Streams to custom backend with client-side VADYour own bridge serverExtra hop; buffering and resampling requiredHigh: own the full VAD and turn logicLow: model-agnostic
Telnyx Realtime Conversations with built-in speech eventsTelnyxLower: media stays at the providerLow: speech lifecycle events providedTelnyx protocol and event model
Google Cloud Speech-to-Text V2 with SPEECH_ACTIVITY_BEGIN and SPEECH_ACTIVITY_END over gRPCGoogle STT streamCustom turn-control layer requiredHigh: convert transcript and activity events into turn controlGoogle STT and gRPC transport

If you are already using OpenAI models and want the fastest path to a working telephony AI agent, the Teler bridge with server_vad is the right starting point. The resampling hop is a known cost you can profile and optimize. If you need model-agnostic infrastructure or you already own a SIP stack, a custom bridge with client-side VAD gives you more control at the cost of building and maintaining the turn-detection logic yourself. For teams evaluating telephony API providers in the US, the media termination point is the single most important axis: it determines where your audio processing budget is spent and which failure modes you own.

Frequently asked questions

What audio format does the OpenAI Realtime API require for voice activity detection?

The API requires base64-encoded PCM16 audio sent via input_audio_buffer.append over WebSocket. The format is set in the session’s audio.input.format: audio/pcm runs at 24 kHz, while audio/pcmu and audio/pcma (G.711) run at a fixed 8 kHz. Telephony audio sent as audio/pcm must be resampled to 24 kHz; sent as audio/pcmu, it only needs converting to μ-law. Sending unresampled 8 kHz audio does not produce an explicit error; it produces incorrect VAD behavior.

What is the difference between server_vad and semantic_vad?

server_vad uses energy-based detection to identify when audio volume crosses a threshold, then fires speech_started and speech_stopped events based on that signal and the configured silence_duration_ms. semantic_vad adds a turn-detection model that evaluates whether the speaker has semantically completed a thought, so it can hold the turn open through a mid-sentence pause. semantic_vad is not supported on all model versions; check the model compatibility before configuring it.

When should I disable VAD and manage turn boundaries manually?

Disable VAD when you need deterministic control over when a turn commits, for example in an IVR flow where the caller presses a key (DTMF) to signal completion, or when you are running your own client-side VAD library and want to avoid double-detection. With VAD disabled, you send input_audio_buffer.commit and response.create yourself. The tradeoff is that you own the full turn-detection logic and must handle edge cases like rapid speech and trailing silence.

How does Teler handle barge-in when a caller interrupts the assistant?

When the OpenAI Realtime API emits input_audio_buffer.speech_started while the assistant is speaking, your bridge server should immediately send {"type": "clear"} to Teler. That message flushes all queued audio from the playback buffer, stopping the assistant’s voice mid-stream. Teler’s transport layer processes the clear command and stops injecting audio into the live call. You must implement this logic in your bridge; neither Teler nor OpenAI coordinates the barge-in automatically across the two connections.

What happens to voice activity detection under high call volume?

Each call runs its own independent WebSocket session to both Teler and the OpenAI Realtime API, so VAD state does not bleed between calls. The scaling constraint is your bridge server: it must maintain two open WebSocket connections per concurrent call and run a resampling operation on every audio chunk. Under load, a synchronous resampler will become the bottleneck before either the telephony layer or the model layer does. Profile the resampling path at your expected peak concurrency before launch. The OpenAI documentation does not publish concurrency limits for the Realtime API in the retrieved sources.

Does Teler expose VAD events directly, or does that come from the AI model?

VAD events such as input_audio_buffer.speech_started and input_audio_buffer.speech_stopped come from the OpenAI Realtime API, not from Teler. Teler’s role is to deliver raw carrier audio to your bridge server over WebSocket and to accept audio back for playback into the live call. The speech classification happens inside the OpenAI session. If you use a different AI provider, that provider’s VAD event names and semantics will differ.

What must I build myself that neither Teler nor the OpenAI Realtime API provides?

You must build the bridge server that holds both WebSocket connections open, the resampling pipeline that converts between sample rates, acoustic echo cancellation if callers are not using headsets, and the state machine that maps VAD events to call control actions such as barge-in, hold, and transfer. You must also handle WebSocket reconnection on unexpected drops, because neither connection guarantees indefinite uptime. See the Teler API documentation for the full list of call control events your bridge can send and receive.

Is SIP or WebSocket the right transport for a telephony VAD pipeline?

SIP handles call setup and teardown per RFC 3261, while audio travels over RTP per RFC 3550. WebSocket is the transport that connects your bridge server to both Teler and the AI model. These are not competing choices: SIP and RTP operate at the carrier layer, and WebSocket operates at the application layer. Teler abstracts the SIP and RTP complexity so your bridge server only needs to handle WebSocket frames. If you are building on top of a raw SIP trunk without Teler, you must implement the RTP-to-WebSocket bridge yourself, which adds significant engineering scope. Teams evaluating this decision can review the top SIP trunking providers in the US for context on what the raw SIP layer involves.

What voice activity detection means for your telephony AI build in 2026

Voice activity detection is not a configuration detail you tune once and forget. It is the mechanism that determines whether your telephony AI agent feels like a conversation or a broken IVR. In 2026, the OpenAI Realtime API gives you two documented modes, server_vad and semantic_vad, and a manual path for teams that need full control. The decision that matters most is where your audio terminates: if it terminates at the model provider, you inherit their VAD behavior and their event model; if it terminates in your own bridge, you own the full detection logic. For teams building on Teler’s programmable voice API, the transport layer handles carrier connectivity and audio delivery, but the resampling path and the barge-in state machine remain your responsibility. If your call environment includes significant background noise or acoustic echo, invest in pre-processing before the audio reaches the VAD engine; no amount of threshold tuning compensates for audio that was never clean to begin with. For teams evaluating voice API providers for AI agents in the US, the VAD implementation is one of the first capabilities worth testing under realistic call conditions.

About the Author: Subhash Kalluri is the Founder & CEO of FreJun, which he has been building since 2019. With over 8 years in voice communication and SaaS, he works on the problem of getting real-time AI onto live phone calls: raw media streaming, interruption handling, and carrier connectivity. That work became FreJun Teler, FreJun’s programmable voice API for developers building AI phone agents. Connect with him on LinkedIn.

Get started with FreJun today

In this article

Make every voice interaction count

FreJun is a real-time voice platform for automating calls and connecting AI bots.

Popular Articles
Add Voice Bot Conversational AI to Your Web Stack 1 7

Businesses today face increasing pressure to engage customers in real time while optimizing operational efficiency. Voice, as the most immediate...

AssemblyAI applications for coaching: a rep scorecard with talk ratio, questions asked and objections handled

AI Summary: This article describes five ways businesses use AssemblyAI’s Audio Intelligence to turn voice data into insights: sales intelligence...

CPaaS providers Australia: the Australian flag with +61 beside voice, messaging, code and integration API icons.
This guide compares the top 11 CPaaS providers Australia teams can use in 2026, evaluating each on real-time latency, WebSocket...