Repository navigation
Description
Problem
Deepgram (DG) bills per second of audio sent, including silence. BigQuery analysis (Jan 2026, 162,429 streaming hours, 219K sessions) shows average WPM of 27.3 vs normal speech at ~130 WPM — implying ~79% of streaming time is non-speech being billed.
| Speech Density | % of Hours | Est. Silence | Description |
|---|---|---|---|
| 0-5 WPM | 19.2% (31,166h) | ~98% | Dead air — wearable on, nobody talking |
| 5-15 WPM | 11.8% (19,110h) | ~92% | Very sparse speech |
| 15-30 WPM | 11.0% (17,799h) | ~83% | Light/intermittent |
| 30-60 WPM | 13.4% (21,831h) | ~65% | Moderate conversation |
| 60-100 WPM | 9.7% (15,760h) | ~38% | Active conversation |
| 100-130 WPM | 4.1% (6,721h) | ~12% | Dense conversation |
| 130+ WPM | 30.8% (50,042h) | ~0% | Very dense speech |
41.9% of all hours are below 30 WPM — mostly silence being billed per-second.
Infrastructure: Which Services Use Cloud vs Self-Hosted DG
From Helm charts (backend/charts/):
| Service | Prod DG Mode | Config | Billing |
|---|---|---|---|
| backend-listen | Cloud (Hosted) | DEEPGRAM_SELF_HOSTED_ENABLED: "false" |
Per-second (billed for silence) |
| pusher | Self-Hosted | DEEPGRAM_SELF_HOSTED_ENABLED: "true" at dg.omi.me |
Fixed license (~fixed monthly) |
| pre-recorded | Cloud only | No self-hosted variant | Per-second |
All real-time streaming from devices goes through backend-listen → Cloud DG → billed per-second. VAD gate savings apply to 100% of real-time streaming traffic.
Self-hosted DG (pusher only): Nova-3 release-251210, engine min 1 / max 10 replicas, 60 streaming requests/pod, GPU nodes. Recently scaled down (PR #4811, merged Feb 15 — min replicas 3→1).
Config files:
backend/charts/backend-listen/prod_omi_backend_listen_values.yaml:223-226backend/charts/pusher/prod_omi_pusher_values.yaml:232-235backend/charts/deepgram-self-hosted/nova-3/prod_omi_values.yaml
Proposed Fix
Insert server-side Silero VAD check before sending audio to DG WebSocket. Skip or replace silence chunks so DG bills less.
Current path (backend-listen):
App → WebSocket → backend decodes audio → stt_audio_buffer.extend(data) → dg_socket.send(chunk)
With VAD gate:
App → WebSocket → backend decodes audio → VAD check → send only if speech → dg_socket.send(chunk)
Insertion point — transcribe.py:1873-1875 (before stt_audio_buffer.extend(data)). The flush_stt_buffer() at :1754-1783 routes audio to DG via dg_socket.send(chunk) at :1770.
Existing VAD code — utils/stt/vad.py:14-15: Silero VAD model already loaded globally at module import. However, is_speech_present() (:23-49) resets state every call — not suitable for streaming. Needs new stateful per-session VAD class.
Savings Estimate
Since backend-listen is 100% cloud-hosted, VAD gate applies to all real-time streaming hours:
- Conservative (50% VAD effectiveness): ~10% of total DG spend
- Moderate (70% effectiveness): ~15-19% of total DG spend
- Aggressive (80% effectiveness): ~20%+ of total DG spend
Note: Self-hosted (pusher) has fixed license cost — VAD gate there would save GPU capacity but not billing. Focus is on backend-listen.
Risk Matrix
| Risk | Severity | Detail |
|---|---|---|
| Timestamp drift | CRITICAL | DG timestamps assume continuous audio. Skipping silence compresses the timeline. Code at :1515 and :1524-1529 applies linear offset. Speaker ID ring buffer extraction at :1352-1384 uses abs_start/abs_end from :1612-1615 — would extract wrong audio if timestamps are compressed. |
| DG connection timeout | HIGH | keepalive: "true" (streaming.py:286) is TCP-level only. DG hosted connections timeout after ~30s without audio data. Extended silence → connection drop. |
| Endpointing breakage | HIGH | endpointing=300 (streaming.py:445) triggers utterance end on 300ms silence. VAD gaps inject artificial boundaries, splitting utterances. Segment merging (:120, gap < 3s) may recover some but not all. |
| CPU overhead | LOW | Silero ~5-10ms per 30ms chunk. At ~175 concurrent streams, needs asyncio.to_thread() wrapping or will block event loop. |
Note: "Self-hosted routing" is NOT a risk — backend-listen and pusher are separate deployments with separate env vars. No per-session routing needed.
Implementation Plan
Phase 1: Shadow Mode (zero risk)
- Add VAD check at insertion point but do NOT skip any audio — log only
- Log:
{session_id, chunk_timestamp, vad_result, chunk_bytes} - Measure actual silence ratio, VAD latency, boundary accuracy, CPU impact
- Deliverables: per-session
VADGateStateclass, shadow logging,VAD_SHADOW_MODE=truefeature flag
Phase 2: VAD Gate (after shadow data confirms)
- Pre-roll buffer: 300-500ms before speech detection fires (prevent clipping word starts)
- Hangover timer: 600-1000ms after speech ends (prevent trailing phoneme loss)
- Timestamp remapping: Cumulative silence gap tracker per session, remap DG timestamps at
:1524 - DG keepalive during silence: Periodic minimal audio frames to prevent connection timeout
- Gradual rollout: Feature flag 5% → 25% → 100%, monitor transcription quality
Phase 3: Optimization
- Threshold tuning from shadow data
- Diarization quality evaluation with context gaps
- Evaluate whether pusher could also benefit (GPU capacity savings on self-hosted)
Key Decision: Skip Silence vs Send Comfort Noise
| Approach | Savings | Complexity | Risk |
|---|---|---|---|
| Skip chunks entirely | Maximum | High — requires timestamp remapping at :1515, :1524-1529, :1612-1615, ring buffer |
Timestamp drift, endpointing breakage |
| Send comfort noise | ~50-70% of skip | Low — timestamps stay aligned, no remapping needed | Minimal — DG processes low-amplitude frames correctly |
Recommendation: Start with comfort noise for Phase 2. Graduate to full skip only if shadow data shows remaining cost justifies timestamp remapping work.
Data Sources
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsIn review
Activity
beastoin commentedon Feb 6, 2026
📝 The proposed solution here is based on data analysis and has not been verified by the CTO. If you have a better approach to address this, feel free to propose it.
beastoin commentedon Feb 20, 2026
Deep Dive: Server-Side VAD Gate Implementation
Updated Data (Jan 2026, BigQuery hourly_usage_raw)
162,429 streaming hours across 219K sessions. Average WPM: 27.3 (normal speech ≈ 130 WPM), implying ~79% of streaming time is non-speech.
41.9% of all hours are below 30 WPM — mostly silence being billed per-second.
Hosted vs self-hosted split (from 15K request sample): 55.9% of streaming hours = hosted (billed per-second). VAD savings only apply to the hosted portion. Estimated savings: 13-21% of total DG spend depending on VAD effectiveness.
Code Deep Dive
Insertion point —
transcribe.py:1873-1875:VAD check goes BEFORE
stt_audio_buffer.extend(data). Theflush_stt_buffer()function at:1754-1783routes audio to DG viadg_socket.send(chunk)at:1770.Existing VAD code —
utils/stt/vad.py:14-15: Silero VAD model is already loaded globally at module import. However:is_speech_present()(:23-49) callsvad_iterator.reset_states()on every invocation — not suitable for streaming (needs stateful operation across chunks within a session)HOSTED_VAD_API_URL) at:72, not the local modeltorch.set_num_threads(1)at:12— single-threaded, would serialize if called synchronously across concurrent streamsRisk Matrix
:1515(first_audio_byte_timestamp + segments[0]["start"]) and:1524-1529(linear offset) assumes continuous audio. Speaker ID ring buffer extraction at:1352-1384usesabs_start/abs_endcomputed at:1612-1615— would extract wrong audio if timestamps are compressed.keepalive: "true"atstreaming.py:286is TCP-level keepalive only. DG hosted connections timeout after ~30s without audio data. Extended silence → connection drop → session restart.endpointing=300atstreaming.py:445triggers utterance end on 300ms silence. VAD gaps inject artificial silence boundaries, splitting single utterances into multiple segments. Segment merging (:120,b.start - a.end < 3) may recover some but not all.is_dg_self_hostedatstreaming.py:285is a global env var, not per-session. Can't selectively enable VAD for hosted-only sessions without code changes.asyncio.to_thread()wrapping or will block.Implementation Plan
Phase 1: Shadow Mode (zero risk, 1-2 weeks)
Add VAD check at the insertion point but do NOT skip any audio — log results only.
What we measure:
Deliverables:
VADGateStateclass with stateful Silero iterator (noreset_states()per call)VAD_SHADOW_MODE=trueenv varPhase 2: VAD Gate (after shadow data confirms estimates)
time_offsetcalculation at:1524Phase 3: Optimization
Key Decision: Skip Silence vs Send Silence
Two approaches to VAD gating:
Skip chunks entirely — Maximum cost savings, but requires timestamp remapping everywhere (
:1515,:1524-1529,:1612-1615, ring buffer extraction). High implementation complexity.Send comfort noise / minimal audio — Send low-amplitude frames during silence. DG still processes them (some cost) but timestamps stay aligned. Lower savings (~50-70% of approach 1) but dramatically simpler and safer.
Recommendation: Start with approach 2 for Phase 2 (send minimal audio during detected silence). Graduate to approach 1 only if shadow data shows the remaining cost is significant enough to justify the timestamp remapping work.
Analysis: @mon (BQ data, DG billing research) + @Chen (code deep dive, risk assessment)
Data sources: DG Usage API, DG Requests API, BigQuery hourly_usage_raw, backend code (main @ ce4f225)
[-]Auto-pause Deepgram streaming on silent connections to reduce transcription waste[/-][+]Server-side VAD gate: skip silence before Deepgram send to reduce streaming cost[/+]beastoin commentedon Feb 22, 2026
Deep Analysis: Verified Implementation Plan
Traced the full audio path, ran empirical DG WebSocket tests with real speech audio, and verified billing via the DG Usage API. Key findings below.
Verified Audio Path
Insertion point: Between ring buffer write (
transcribe.py:1871) and STT buffer extend (transcribe.py:1874). Ring buffer always gets all audio (speaker ID needs it). VAD gate only controls what reaches DG.Key Discovery: DG KeepAlive Protocol
DG has an official KeepAlive feature designed for this use case:
{"type": "KeepAlive"}(text WebSocket frame)keepalive: "true"atstreaming.py:286), auto-sends every 5s{"type": "Finalize"}flushes DG transcript buffer on demandEmpirical Test Results (4 tests, real speech audio via gTTS)
Test: Timestamp Compression — CONFIRMED
real_time = dg_time + cumulative_skipped_silenceTest: Endpointing During KeepAlive — DOES NOT FIRE
endpointing=300relies on audio silence detection; KeepAlive messages are invisible to it{"type": "Finalize"}is required on speech→silence transition to flush pending transcriptTest: Finalize — WORKS (0.2s flush)
Test: Billing Comparison — VERIFIED via DG Usage API
The ~10s of KeepAlive was completely invisible to billing. DG billed exactly the audio data received.
Issue Corrections
keepalive: "true"enabled)conversations.pyArchitecture: Dual-Timeline (Codex-verified)
Risk Matrix
Implementation Plan
Phase 1 — Shadow Mode (~1 week, zero risk):
Add
VADStreamingGateclass. Log VAD decisions at insertion point but send ALL audio as before. Measure actual silence ratio, VAD latency, false negative rate. Feature flag:VAD_GATE_MODE=shadow.Phase 2 — Active Gate (~2 weeks):
Gate audio: skip silence → SDK KeepAlive keeps connection → send Finalize on speech→silence → timestamp remapping via checkpoint list. Gradual rollout: 5% → 25% → 100%.
Phase 3 — Tuning (~1 week):
Optimize pre-roll (300-500ms) and hangover (250-400ms) from production data. Evaluate diarization quality with gaps.
Estimated Savings
With ~79% of streaming time being silence (27.3 avg WPM vs 130 WPM normal speech):
Applied to backend-listen hosted streaming only. Self-hosted (pusher) has fixed license cost.
by AI for @beastoin
beastoin commentedon Feb 22, 2026
Verification Scripts
Reproducible scripts used for the empirical testing above. Requires
pip install websockets httpxandDEEPGRAM_API_KEYenv var.Audio setup — generate two short speech WAV files (16kHz mono PCM16):
Script 1:
vad-gate-verify-v2.py— Behavior verification (4 tests)Tests: timestamp compression, endpointing during KeepAlive, Finalize behavior, silence-vs-KeepAlive comparison.
vad-gate-verify-v2.py (click to expand)
Script 2:
vad-billing-verify.py— Billing verification via Usage APIRuns two DG sessions (silence audio vs KeepAlive), then queries DG Usage API to compare billed duration.
# Requires a DG key with usage:read scope DEEPGRAM_API_KEY=your_key python3 vad-billing-verify.pyvad-billing-verify.py (click to expand)
by AI for @beastoin
feat: add server-side VAD gate to reduce DG streaming cost (#4644)
beastoin commentedon Feb 22, 2026
Implementation Limitations Found (PR #4931)
Post-implementation analysis found 8 limitations that affect quality and cost savings. Addressing before active-mode rollout.
CRITICAL
keep_alive()is never called. When silence is skipped, nothing is sent to DG. DG's 30-second idle timeout will drop the connection mid-conversation if user is genuinely silent for 30s+. Transcripts are lost, conversation must reconnect.HIGH
Speech threshold hardcoded to 0.5 — Silero VAD returns 0.0–1.0 probability; anything below 0.5 is classified as silence. Soft speakers, whispers, and accented speech at 0.45–0.49 get clipped. No
VAD_GATE_SPEECH_THRESHOLDenv var to tune per-deployment.Pre-roll depth varies with chunk size — Code assumes 30ms chunks for pre-roll buffer sizing. If actual chunks differ (20ms or 40ms), pre-roll depth is unpredictable (220ms–440ms instead of target 300ms).
Speech profile disables gate for 80% of users — Gate is disabled entirely when
preseconds > 0(speech profile active). ~80% of users have speech profiles, so the gate never activates for most sessions. Cost savings drastically lower than projected. Need to activate gate AFTER profile phase completes.MEDIUM
Checkpoint compaction loses early timestamps — Capped at 500 checkpoints. Long sessions (4+ hours) drop old checkpoints; late DG transcripts referencing early segments get inaccurate timestamp remapping. No auxiliary time-based checkpoints.
Finalize exceptions swallowed silently —
except Exception: passon finalize means failed flushes lose transcript chunks with zero visibility. No metric, no log.VAD buffer truncation — If incoming audio doesn't align to 512-sample VAD windows, buffer truncates to last 512 samples. Up to 32ms of audio context lost, degrading VAD accuracy on speech onset.
No cost/quality production metrics — Gate tracks local silence ratio but nothing correlates with actual DG billing. No
dg_audio_bytes_skippedcounter, no WER tracking. PR claims ~43% reduction but no prod telemetry to confirm.Working on fixes for all items. Priority: #4 (preseconds bypass), #1 (keepalive), #2 (threshold tunability).
by AI for @beastoin
feat: add server-side VAD gate to reduce DG streaming cost (#4644)