Skip to content

improve(talk): reduce voice conversion CPU work - #146469

Merged
steipete merged 1 commit into
mainfrom
codex/v8-audio-interior
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/v8-audio-interior

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #146468

What Problem This Solves

Voice calls spend unnecessary CPU converting between realtime and telephony audio formats.

User Impact

Voice conversion uses less CPU while preserving identical audio bytes: one-second telephony streams took about 39–46% less time in the measured adapter workload. This does not claim lower provider or network latency. Short conversions with many rate phases can remain neutral or slightly slower.

Why This Change Was Made

Calculate the existing phase's full coefficient sum once and use it for interior samples. Keep the original edge handling and arithmetic order, including the zero-weight fallback, so sample rounding and streaming continuity remain unchanged.

Evidence

  • Node 24.19.0 (V8 13.6.233.17-node.51) and Node 26.8.2 (V8 14.6.202.34-node.28), Windows AMD Ryzen AI MAX+ 395.
  • 2,302 full-output parity cases per runtime, including odd alignment/chunk lengths, sample boundaries, clipping extremes, silence, fractional/large-phase rates, complete streamed buffers, and the real OpenAI voice adapter and meeting TTS converter.
  • Nine alternating before/after pairs after five warmups for every timing cell. One-second OpenAI telephony decode/send/finish: 2.979 → 1.827 ms on Node 24 and 2.882 → 1.545 ms on Node 26. All one- and ten-second resampling adapter cells won 9/9 pairs.
  • 25 focused tests passed across the core resampler, telephony codec/TTS, OpenAI audio queue, and peer-adoption/RTP pipeline. Formatting, targeted lint and selected guards passed.
  • The local changed check and initial hosted run stopped at an unrelated core type error in src/gateway/server-startup-finish.ts:416 (TS2741, array missing required stop). Replacing only the audio owner with the unchanged base source reproduced the same error with the same frozen dependencies. The owning repair has now landed as fix(gateway): register TLS renewal with sidecar owner #146412; this branch was rebased onto fixed main with identical audio bytes. Later local changed-check stages were not reached. Fresh hosted CI remains required before landing.
Measurement method and complete timing controls

The source-copy harness uses the complete actual OpenAIQuicksilverAudioAdapter and meeting TTS conversion module, changing their codec imports to select original or candidate source. The codec retains its real normalization dependency. Synthetic PCM/μ-law fixtures avoid live services. The base is ea4b57a0adc495b54e7dbd783b07eb83f9c49382; candidate codec SHA-256 is 8c50ba592d66a3970059dcdddcd2c130bac4472a64100acd072b9f70b3f1f4a7.

Adapter timings include construction and finishing/resetting the audio adapter. Input uses 160-byte μ-law frames; output uses 960-byte PCM frames (20 ms). The duplex fixture feeds decoded PCM back through the output conversion to exercise both directions; separate directional cells measure independently generated source frames. The PCM control does not resample. Values are median milliseconds per complete operation; parentheses show winning pairs out of nine.

Adapter workload Node 24 before → after Node 26 before → after
adapter-telephony-20ms 0.0794 → 0.0551 (9/9) 0.0628 → 0.0452 (9/9)
adapter-telephony-1000ms 2.9786 → 1.8266 (9/9) 2.8815 → 1.5449 (9/9)
adapter-telephony-10000ms 30.0277 → 18.5166 (9/9) 37.1310 → 22.1582 (9/9)
adapter-pcm-control-1000ms 0.0154 → 0.0149 (3/9) 0.0138 → 0.0146 (3/9)
adapter-input-20ms 0.0611 → 0.0420 (8/9) 0.0633 → 0.0397 (9/9)
adapter-output-20ms 0.0357 → 0.0278 (9/9) 0.0344 → 0.0266 (9/9)
adapter-input-1000ms 2.4974 → 1.4068 (9/9) 2.4330 → 1.3414 (9/9)
adapter-output-1000ms 1.0075 → 0.5827 (9/9) 0.9786 → 0.5152 (9/9)
adapter-input-10000ms 23.5320 → 13.5999 (9/9) 25.1880 → 13.3342 (9/9)
adapter-output-10000ms 9.6530 → 6.4571 (9/9) 10.7422 → 6.2544 (9/9)

The meeting converter includes one-shot phase-table preparation. The 22.05 kHz short cases show why this is not a universal speedup: phase construction can dominate very short buffers. The 48,001 Hz cells retain the direct sampler because the phase count exceeds the existing cap; same-rate cells retain their original conversion behavior.

Source rate / duration / output Node 24 before → after Node 26 before → after
8000 Hz / 20 ms / pcm16-24khz 0.0472 → 0.0335 (9/9) 0.0515 → 0.0301 (9/9)
8000 Hz / 20 ms / g711-ulaw-8khz 0.0031 → 0.0028 (5/9) 0.0035 → 0.0029 (7/9)
8000 Hz / 1000 ms / pcm16-24khz 2.1381 → 1.1734 (9/9) 2.1209 → 0.9687 (9/9)
8000 Hz / 1000 ms / g711-ulaw-8khz 0.1002 → 0.1051 (4/9) 0.0699 → 0.0677 (7/9)
22050 Hz / 20 ms / pcm16-24khz 0.2346 → 0.2367 (5/9) 0.2492 → 0.2289 (6/9)
22050 Hz / 20 ms / g711-ulaw-8khz 0.2068 → 0.2146 (4/9) 0.1787 → 0.1506 (5/9)
22050 Hz / 1000 ms / pcm16-24khz 2.5184 → 1.4335 (9/9) 2.7562 → 1.2406 (9/9)
22050 Hz / 1000 ms / g711-ulaw-8khz 1.0266 → 0.6012 (9/9) 1.0653 → 0.6488 (9/9)
24000 Hz / 20 ms / pcm16-24khz 0.0001 → 0.0001 (1/9) 0.0001 → 0.0001 (2/9)
24000 Hz / 20 ms / g711-ulaw-8khz 0.0213 → 0.0136 (9/9) 0.0262 → 0.0148 (9/9)
24000 Hz / 1000 ms / pcm16-24khz 0.0002 → 0.0002 (6/9) 0.0001 → 0.0001 (4/9)
24000 Hz / 1000 ms / g711-ulaw-8khz 0.7914 → 0.4844 (9/9) 0.9937 → 0.4867 (9/9)
44100 Hz / 20 ms / pcm16-24khz 0.1421 → 0.1292 (9/9) 0.1501 → 0.1191 (8/9)
44100 Hz / 20 ms / g711-ulaw-8khz 0.1167 → 0.1124 (6/9) 0.1182 → 0.1007 (7/9)
44100 Hz / 1000 ms / pcm16-24khz 2.0993 → 1.2427 (9/9) 2.4895 → 1.2240 (9/9)
44100 Hz / 1000 ms / g711-ulaw-8khz 0.8489 → 0.5526 (9/9) 1.0654 → 0.5686 (9/9)
48000 Hz / 20 ms / pcm16-24khz 0.0461 → 0.0253 (9/9) 0.0548 → 0.0245 (9/9)
48000 Hz / 20 ms / g711-ulaw-8khz 0.0221 → 0.0141 (9/9) 0.0223 → 0.0142 (9/9)
48000 Hz / 1000 ms / pcm16-24khz 2.1373 → 1.0897 (9/9) 2.5609 → 1.0594 (9/9)
48000 Hz / 1000 ms / g711-ulaw-8khz 0.7890 → 0.4392 (9/9) 0.9773 → 0.4684 (9/9)
48001 Hz / 20 ms / pcm16-24khz 0.2731 → 0.2745 (4/9) 0.2670 → 0.2721 (5/9)
48001 Hz / 20 ms / g711-ulaw-8khz 0.0848 → 0.0890 (2/9) 0.1026 → 0.0982 (8/9)
48001 Hz / 1000 ms / pcm16-24khz 12.8443 → 12.3648 (7/9) 13.8859 → 14.0082 (5/9)
48001 Hz / 1000 ms / g711-ulaw-8khz 4.3611 → 4.3835 (5/9) 4.6077 → 4.4928 (5/9)

Three alternating fresh-process pairs per runtime measured the complete adapter workload. RSS is process high-water, including loader, imports and fixtures; small differences were mixed and do not support a memory improvement claim.

Runtime Median process wall time before → after Median peak RSS before → after
Node 24 1.029 → 0.808 s 96.26 → 96.54 MiB
Node 26 1.036 → 0.757 s 120.97 → 121.18 MiB

These measurements cover conversion CPU and full output parity, not live audio-device behavior, provider latency, or per-call heap allocation.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 12, 2026 21:00
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete force-pushed the codex/v8-audio-interior branch from a99ad53 to 9cad534 Compare September 12, 2026 21:15
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 5:31 PM ET / 21:31 UTC.

ClawSweeper review

What this changes

The PR reduces voice resampling CPU work by calculating each filter phase’s coefficient sum once while preserving audio bytes and stream-edge handling.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful, narrowly scoped optimization absent from inspected main and the latest release. No actionable correctness or security defects were found.

Priority: P2
Reviewed head: 9cad534964f34dd38cca51c03fc490ab71e9247a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct optimization with detailed parity and timing evidence and no actionable review findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied measurements exercise the actual audio adapter’s decode/send/finish path using synthetic audio on Windows and both supported Node lines, reporting faster conversion and complete byte parity for the hash-matched codec. This supports the conversion-only claim without requiring live provider or audio-device proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied measurements exercise the actual audio adapter’s decode/send/finish path using synthetic audio on Windows and both supported Node lines, reporting faster conversion and complete byte parity for the hash-matched codec. This supports the conversion-only claim without requiring live provider or audio-device proof.
Evidence reviewed 8 items Introduced optimization preserves arithmetic: The complete introduced diff caches the sum in the same tap order and uses it only when all 31 taps fit and the sum is nonzero. Partial-edge normalization, zero-weight fallback, rounding, clipping, and streaming state remain unchanged.
Optimization remains absent from main: The complete current-main codec still accumulates coefficient weights and checks boundaries inside every sample’s tap loop.
Latest release retains original loop: The v2026.9.4 codec also recomputes the coefficient sum per sample; this optimization is not present in the supplied latest release.
Findings None None.
Security None None.

How this fits together

OpenClaw’s shared audio codec converts PCM samples between rates for realtime voice and telephony adapters. Its output feeds audio playback and G.711 encoding for calls.

flowchart TD
  A[Incoming voice audio] --> B[PCM samples]
  B --> C[Shared audio resampler]
  C --> D{Full filter fits?}
  D -->|Yes| E[Reuse phase coefficient sum]
  D -->|No| F[Calculate partial edge weights]
  E --> G[Converted PCM]
  F --> G
  G --> H[Voice playback or telephony encoding]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20. Total +20 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 24 4 +20
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 24 4 +20

Review metrics

Metric Value Why it matters
Measured conversion CPU 39% and 46% lower one-second adapter time on Node 24 and 26 Reported alternating measurements support the optimization’s benefit without claiming provider or network latency improvements.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #146468
Summary: This PR is the implementation candidate for the explicitly paired audio-conversion performance issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep the optimization within the existing shared resampler, retaining identical output, edge normalization, and public APIs.

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

Not applicable as a functional bug: this is a performance optimization supported by current-source inspection and reported before/after adapter measurements; no code was executed during this review.

Is this the best way to solve the issue?

Yes: reusing the existing phase’s sum removes repeated work without a competing implementation, configuration change, or alteration to the public audio contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9b59fe4ef7da.

Labels

Label changes:

  • add P2: This is a measured, bounded voice-conversion performance improvement without evidence of an urgent user-facing outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied measurements exercise the actual audio adapter’s decode/send/finish path using synthetic audio on Windows and both supported Node lines, reporting faster conversion and complete byte parity for the hash-matched codec. This supports the conversion-only claim without requiring live provider or audio-device proof.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied measurements exercise the actual audio adapter’s decode/send/finish path using synthetic audio on Windows and both supported Node lines, reporting faster conversion and complete byte parity for the hash-matched codec. This supports the conversion-only claim without requiring live provider or audio-device proof.

Label justifications:

  • P2: This is a measured, bounded voice-conversion performance improvement without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied measurements exercise the actual audio adapter’s decode/send/finish path using synthetic audio on Windows and both supported Node lines, reporting faster conversion and complete byte parity for the hash-matched codec. This supports the conversion-only claim without requiring live provider or audio-device proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied measurements exercise the actual audio adapter’s decode/send/finish path using synthetic audio on Windows and both supported Node lines, reporting faster conversion and complete byte parity for the hash-matched codec. This supports the conversion-only claim without requiring live provider or audio-device proof.

Evidence

What I checked:

  • Introduced optimization preserves arithmetic: The complete introduced diff caches the sum in the same tap order and uses it only when all 31 taps fit and the sum is nonzero. Partial-edge normalization, zero-weight fallback, rounding, clipping, and streaming state remain unchanged. (src/talk/audio-codec.ts:102, 9cad534964f3)
  • Optimization remains absent from main: The complete current-main codec still accumulates coefficient weights and checks boundaries inside every sample’s tap loop. (src/talk/audio-codec.ts:112, 9b59fe4ef7da)
  • Latest release retains original loop: The v2026.9.4 codec also recomputes the coefficient sum per sample; this optimization is not present in the supplied latest release. (src/talk/audio-codec.ts:112, 3a9d69db306c)
  • Benchmark source identity and measured behavior: The complete supplied PR body at context sourceRevision fa62b467278516f4c558295fd6a8bed80d0c736722e8a63e63a358b6cfdccf78 reports 2,302 full-output parity cases per runtime and alternating before/after measurements using the complete production audio adapter and conversion modules on Windows with Node 24 and 26. One-second telephony conversion improved from 2.9786 to 1.8266 ms and 2.8815 to 1.5449 ms. The local codec SHA-256 matches the recorded candidate: 8c50ba592d66a3970059dcdddcd2c130bac4472a64100acd072b9f70b3f1f4a7. These are contributor-reported conversion measurements, not reviewer-executed live calls. (src/talk/audio-codec.ts, 9cad534964f3)
  • Production adapter exercises the changed owner: The adapter uses the shared streaming resampler for 8-to-24 kHz input and 24-to-8 kHz output, including flush and reset. This directly matches the benchmark’s decode/send/finish workload. The codec change does not depend on the Codex harness or its protocol. (extensions/openai/realtime-quicksilver-audio-buffer.ts:19, 9cad534964f3)
  • Existing continuity coverage: The existing tests exercise whole-buffer versus 20 ms chunk conversion and constrain discontinuities at chunk seams. They were inspected, not executed; the PR separately reports 25 focused passing tests. (src/talk/audio-codec.test.ts:27, 9cad534964f3)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 82bbea6 into main Sep 12, 2026
191 of 192 checks passed
@steipete
steipete deleted the codex/v8-audio-interior branch September 12, 2026 21:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

Reduce CPU used by realtime and telephony audio conversion

1 participant