Skip to content

fix(voice): prevent choppy audio in realtime calls - #125620

Merged
steipete merged 11 commits into
mainfrom
steipete/voice-audio-pipeline
Aug 18, 2026
Merged

steipete merged 11 commits into
mainfrom
steipete/voice-audio-pipeline

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users on realtime voice calls would hear choppy, gapped, or corrupted audio even when upstream synthesis was continuous. This was observed on the production gateway on 2026-08-17/18. Review traced the symptom to five independent mechanisms in the outbound pacer, per-chunk resampling, telephony TTS format handling, Twilio playback completion, and bounded audio buffering.

Why This Change Was Made

The voice pipeline now keeps one continuous timing and DSP state across each stream: outbound telephony frames are paced from a monotonic stream clock with a 160 ms lead window and overdue catch-up; sample-rate conversion preserves sinc taps and fractional phase across chunks; telephony TTS honors raw mu-law versus PCM/container format contracts; Twilio playback waits for acknowledged completion marks and aborts cleanly on interruption or partial send failure; and input/reconnect queues remain bounded while retaining the freshest audio.

Codex OSS uses WebRTC for realtime calls (codex-rs/codex-api/src/endpoint/realtime_call.rs), where RTP transport owns media pacing. Twilio Media Streams expose audio over WebSocket instead, so OpenClaw must pace those frames in userspace.

User Impact

Realtime and streaming voice calls sound audibly smoother, without timer-lateness gaps or resampling seams. Azure raw 8 kHz mu-law and Gradium ulaw_8000 telephony TTS are passed through correctly instead of being double-companded into garbage audio. Barge-in and playback completion are deterministic, and prolonged backpressure no longer permits unbounded stale audio growth.

No configuration changes are required.

Evidence

  • Realtime outbound pacing: extensions/voice-call/src/webhook/realtime-audio-pacer.ts uses an absolute monotonic stream clock, a 160 ms lead window, and send-all-overdue catch-up instead of chaining relative 20 ms timers for each 160-byte frame. Fake-timer regressions cover timer lateness and catch-up in extensions/voice-call/src/webhook/realtime-audio-pacer.test.ts.
  • Stateful resampling: src/talk/audio-codec.ts adds createStreamingPcmResampler, preserving sinc filter history and fractional phase across chunks. It is wired into the 48 kHz/24 kHz werift peer path in extensions/openai/realtime-quicksilver-peer.runtime.ts and both 8 kHz/24 kHz telephony directions in extensions/openai/realtime-quicksilver-bridge.ts. src/talk/audio-codec.test.ts proves chunked output is equivalent to one-shot resampling without seam discontinuities.
  • Telephony TTS format contract: extensions/voice-call/src/telephony-tts.ts passes through Azure raw-8khz-8bit-mono-mulaw and Gradium ulaw_8000, converts PCM, and rejects container formats with a typed error. extensions/voice-call/src/telephony-tts.test.ts covers all three outcomes.
  • Twilio streaming playback: extensions/voice-call/src/media-stream.ts and extensions/voice-call/src/providers/twilio.ts wait for Twilio's echoed completion mark, fall back after audio duration plus 2 seconds, ignore stale marks after clear, race barge-in against in-flight synthesis, and abort/clear partial chunk-send failures. Coverage includes extensions/voice-call/src/media-stream.playback-marks.test.ts and extensions/voice-call/src/providers/twilio.test.ts.
  • Bounded input audio: extensions/openai/realtime-voice-bridge.ts drops input frames above a 1 MiB WebSocket bufferedAmount threshold with rate-limited warnings, while src/talk/realtime-session-lifecycle.ts applies drop-oldest overflow semantics so reconnect queues retain the freshest audio.

Local proof is green: 180+ focused tests across 12 files, including DSP-equivalence and fake-timer pacing regressions that fail on the pre-fix implementations by construction; pnpm build; pnpm plugin-sdk:surface:check; and pnpm check:changed. Codex autoreview completed clean on the full branch; the later three commits only clean up repository gates (baseline shrink/un-export, playback-mark suite split for the max-lines cap, and unused-helper removal).

Live-call listening proof is infeasible from this development checkout because the Twilio credentials and tailnet access live on the operator's production gateway. The deterministic fake-timer, DSP-equivalence, format-contract, playback-mark, abort, backpressure, and overflow regressions cover the changed mechanisms; they are not presented as live proof.

AI-assisted: yes. The branch was reviewed and validated as described above.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete steipete self-assigned this Aug 18, 2026
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 18, 2026
@steipete
steipete marked this pull request as ready for review August 18, 2026 05:12
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 2:52 AM ET / 06:52 UTC.

ClawSweeper review

What this changes

This PR revises realtime voice resampling, telephony pacing and playback acknowledgements, TTS format handling, and audio backpressure to reduce choppy or corrupted call audio.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for maintainer-owned merge review. The earlier containerized μ-law finding is fixed on the current head, but protocol-contract verification and a maintainer proof decision remain before merge.

Priority: P1
Reviewed head: e9cc2fe83e7d48adac93cdf4b5259c699835c954
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The source repair and focused regressions are substantial, but external protocol and production-call confirmation remain unresolved.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR documents why a production listening trace is unavailable; focused tests are supplemental, while the remaining proof decision is maintainer-owned.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR documents why a production listening trace is unavailable; focused tests are supplemental, while the remaining proof decision is maintainer-owned.
Evidence reviewed 4 items Current-main comparison: The core resampler, OpenAI bridges, pacer, Twilio playback handler, and TTS adapter all differ from current main; current main has no streaming resampler implementation.
Prior finding addressed: The exact head accepts only the two explicit raw μ-law formats and otherwise rejects the format; the accompanying test includes riff-8khz-8bit-mono-mulaw as a rejected container case.
Playback owner path: Twilio playback awaits a media-stream completion mark, while the handler rejects/ignores marks invalidated by clear; the focused WebSocket test covers both acknowledgement and post-clear behavior.
Findings None None.
Security None None.

How this fits together

Realtime audio passes through OpenAI voice bridges or telephony TTS, then through resampling, buffering, pacing, and Twilio media streams. These paths determine whether callers hear continuous audio and whether playback ends correctly on completion or interruption.

flowchart LR
  A[Provider audio] --> B[Resampling and buffering]
  B --> C[Realtime voice bridge]
  C --> D[Telephony pacer]
  D --> E[Twilio media stream]
  E --> F[Playback mark acknowledgement]
Loading

Decision needed

Question Recommendation
Should this maintainer-owned voice-pipeline change merge after direct Codex protocol verification and redacted production-call evidence, despite the local checkout lacking those credentials and the sibling Codex source? Verify before merge: Inspect the Codex completion-event behavior and attach a redacted production call trace showing smooth playback, mark acknowledgement, and interruption recovery.

Why: The changed tail-flush boundary depends on an external protocol implementation, and the repository policy requires direct source inspection before a merge verdict; only a maintainer can provide or waive that evidence.

Before merge

  • Resolve merge risk (P1) - The GPT-Live tail-flush behavior depends on the Frameless Bidi completion-event contract, which could not be checked against the required sibling Codex source in this environment.
  • Resolve merge risk (P1) - This bug-fix branch is net production growth of about 456 lines across transport, DSP, and plugin-SDK surfaces; exact-head integration and live-call evidence matter before merge.
Agent review details

Security

None.

PR surface

Source +457, Tests +591, Other 0. Total +1048 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 13 556 99 +457
Tests 10 639 48 +591
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 24 1196 148 +1048

Review metrics

Metric Value Why it matters
Production versus test delta production +555/-99 (net +456); tests/test support +640/-48 (net +592); baseline neutral This broad bug repair adds stateful behavior across several voice owners, so exact-head integration and live transport proof are more important than ordinary unit coverage alone.

Stored data model

Persistent data-model change detected: serialized state: extensions/voice-call/src/media-stream.playback-marks.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify transport behavior before merge (recommended)
    Confirm the Codex turn-completion contract and a production voice-call trace before merging the altered resampling and playback lifecycle.
  2. Accept evidence limits
    A maintainer may accept focused regression coverage and the Twilio documentation without the unavailable direct protocol and live-call checks.

Technical review

Best possible solution:

Verify the Codex completion-event contract and obtain a redacted production-gateway call trace confirming smooth audio, completion marks, and barge-in before landing the coherent owner-boundary repair.

Do we have a high-confidence way to reproduce the issue?

No live reproduction was available in this read-only checkout, but the changed source and focused regressions define concrete pacing, resampling, format, and completion paths.

Is this the best way to solve the issue?

Unclear: the owner-boundary repair is coherent in the inspected source and resolves the prior finding, but the required external protocol and real-call confirmation are still missing.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5dcc91df998f.

Labels

Label justifications:

  • P1: The PR addresses an observed realtime-call audio regression affecting active voice-call users.
  • merge-risk: 🚨 compatibility: It changes a Plugin SDK export and behavior for existing OpenAI realtime and telephony TTS setups.
  • merge-risk: 🚨 message-delivery: It changes outbound call audio pacing, completion acknowledgement, clear handling, and bounded audio delivery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR documents why a production listening trace is unavailable; focused tests are supplemental, while the remaining proof decision is maintainer-owned.

Evidence

What I checked:

  • Current-main comparison: The core resampler, OpenAI bridges, pacer, Twilio playback handler, and TTS adapter all differ from current main; current main has no streaming resampler implementation. (src/talk/audio-codec.ts:252, e9cc2fe83e7d)
  • Prior finding addressed: The exact head accepts only the two explicit raw μ-law formats and otherwise rejects the format; the accompanying test includes riff-8khz-8bit-mono-mulaw as a rejected container case. (extensions/voice-call/src/telephony-tts.ts:65, e9cc2fe83e7d)
  • Playback owner path: Twilio playback awaits a media-stream completion mark, while the handler rejects/ignores marks invalidated by clear; the focused WebSocket test covers both acknowledgement and post-clear behavior. (extensions/voice-call/src/media-stream.ts:707, e9cc2fe83e7d)
  • Protocol-contract gap: The changed GPT-Live bridge identifies the Frameless Bidi protocol as Codex realtime v3 behavior and flushes at its assistant turn-completion event. Repository policy requires direct sibling Codex inspection for that dependency, but ../codex is absent and network fetches fail in this read-only environment. (extensions/openai/realtime-quicksilver-bridge.ts:447, e9cc2fe83e7d)

Likely related people:

  • steipete: The current branch’s voice-pipeline commits and blamed changed lines are authored by this contributor. (role: recent area contributor; confidence: high; commits: 6dbd7f1bae56, 3a0979c8279b, dd9ccc28e930; files: extensions/voice-call/src/media-stream.ts, extensions/voice-call/src/webhook/realtime-audio-pacer.ts, extensions/openai/realtime-quicksilver-bridge.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify the Codex completion-event contract from the required source checkout.
  • Attach a redacted production voice-call trace covering smooth playback, completion marks, and barge-in.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-18T06:22:17.755Z sha 4283f6e :: found issues before merge. :: [P2] Reject containerized μ-law before telephony playback

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@steipete

steipete commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Handled all substantive ClawSweeper moves through head e9cc2fe83e7d48adac93cdf4b5259c699835c954:

  • Applied the resampler-tail fix in 4283f6e. Assistant turn.done now emits the held 24 kHz→8 kHz tail before response.done, replaces the sealed outbound resampler, and resets telephony DSP state on terminal teardown. The extended regression in extensions/openai/realtime-quicksilver-bridge.test.ts failed before the fix because two responses produced only two immediate audio callbacks; it now proves immediate+tail delivery for both responses and ordering before completion. Focused result: 15/15 tests passed.
  • Applied the container-format fix in e9cc2fe. Telephony TTS now allowlists only the two provider-owned raw formats, Azure raw-8khz-8bit-mono-mulaw and Gradium ulaw_8000, instead of substring-matching arbitrary 8 kHz μ-law names. The extended container test reproduced the bug first—riff-8khz-8bit-mono-mulaw resolved with raw container bytes—then passed after the owner fix. Focused result: 12/12 tests passed; production delta for this repair is net -1 line.
  • Directly verified the required Codex completion contract against OpenAI Codex commit 4861236f06d0: codex-rs/codex-api/src/endpoint/realtime_websocket/protocol_frameless_bidi.rs:15-26 dispatches output_audio.delta and turn.done; lines 38-45 map audio deltas to 24 kHz mono AudioOut; lines 58-69 map assistant turn.done to OutputTranscriptDone. That is the exact producer boundary OpenClaw flushes before projecting response.done.
  • Confirmed the upstream Twilio Media Streams contract in the official WebSocket messages documentation: Twilio echoes a mark with the same name when the preceding media playback completes; after clear, it empties the audio buffer and returns marks for buffered media that did not play. This matches the PR's acknowledged-playback and stale-post-clear handling.
  • Skipped an authenticated live-call listening trace because this development checkout does not have the production gateway's Twilio credentials or tailnet access. Peter's explicit landing work order accepts this evidence limit; the PR body records the gap, and deterministic mark, clear, abort, pacing, DSP-equivalence, response-tail, and format-contract regressions are not presented as live proof.

Final exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/32108370728. Final ClawSweeper review reports no actionable findings on e9cc2fe83e7d.

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@steipete
steipete merged commit 6cc4043 into main Aug 18, 2026
217 checks passed
@steipete
steipete deleted the steipete/voice-audio-pipeline branch August 18, 2026 07:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
* fix(voice-call): pace realtime audio from stream clock

* fix(voice): preserve resampler state across audio chunks

* fix(voice-call): honor telephony TTS audio formats

* fix(voice-call): await acknowledged stream playback

* fix(voice): bound realtime input audio backlog

* chore(voice-call): shrink assertion baseline and localize tts format error

* test(voice-call): split playback-mark coverage into its own suite

* test(voice-call): drop helper left unused by suite split

* test(openai): scope queued audio copy assertion

* fix(openai): flush realtime resampler at response end

* fix(voice-call): reject containerized mulaw TTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: voice-call Channel integration: voice-call extensions: openai maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant