← Back to Pull requests

Cancel speaker echo in the packaged audio client #671

Closed
unknown closed this pull request without merging on Oct 30, 2026 13:38 UTC
View on GitHub
unknown unknown commented on Oct 07, 2026 21:12 UTC
Author

Summary

The packaged mic/speaker client can hear its own replies on laptop speakers, interrupt playback and start another turn. This enables echo cancellation by default in talk and local, so users can speak during assistant playback without headphones. Related: #151 and #668.

Physical Windows laptop, using the Python client with its built-in microphone and speakers:

  • Echo cancellation off

  • Echo cancellation on
  • Implementation

  • Include pywebrtc-audio in the default installation. WebRTC AEC3 removes echo; noise suppression and gain control stay off. Its high-pass filter remains on.

  • Give audio hardware and cancellation their own spawned process, so model or tool code cannot hold their Python execution lock. Networking and tools stay in the parent; queues carry microphone PCM and playback commands.

  • Match speaker references to microphone samples using playback/capture timestamps on a shared clock. Preserve continuous sample spacing through small timestamp fluctuations and retain the acoustic model across capture gaps.

  • Use WASAPI with sample-rate conversion on Windows when cancellation is enabled.

  • Process complete 10 ms frames together in one native call; carry partial frames across callbacks. Playback clear/resume, worker startup failures and shutdown are handled.

  • Require matching 16 kHz rates in the packaged client. Use --no-echo-cancellation to opt out; microphone blocking also disables cancellation. Native processing failures log once and fall back to raw microphone audio.
  • Try it

    uv sync --python 3.11
    uv run speech-to-speech talk --url ws://<server-ip>:18766/v1/realtime --api-key none
    # Cancellation is also on by default for local.
    # Add --no-echo-cancellation when using headphones.
    

    Python scripts that call the client directly must guard their entry point with if __name__ == "__main__": because audio uses a spawned process.

    Behavior and cost

    On a physical MacBook Air M2 at the default 16 kHz / 1024 settings, controlled Python load in the same process made the previous adapter leave nearly all echo intact in three trials, without audio warnings. The normal speech detector accepted speaker playback as speech. Batching the native calls alone restored cancellation in two matched trials.

    Ten physical checks of the isolated worker under parent-process load cover default, large and automatic buffers, playback clear/resume, microphone transport and separate recorded speech during playback. Echo-only cleaned audio produced no speech detections; the separate voice still passed the normal detector. These are short physical audio checks with controlled load, not an end-to-end MLX model-pipeline test. Automatic-buffer suppression varied between runs.

    Three paired Linux workstation trials, including the client and audio worker, measured:

    | Mode | Idle, percent of one core | Fixed playback, percent of one core | Idle private memory |
    | --- | ---: | ---: | ---: |
    | Off | 1.61% | 1.92% | 79.9 MiB |
    | On | 2.67% | 3.14% | 139.5 MiB |

    Default 1024-sample blocks, twelve-second windows, Ryzen 9950X simulated room. Excludes model inference, fake-server and shared audio-service CPU; these are not Mac cost estimates.

    Cancellation can attenuate speech during overlap, and separate devices can drift. The reported M3 Pro/MLX setup still needs a retest before treating that exact failure as resolved. Requirements, limits and processing benchmark.

    Validation

  • Realtime, CLI, configuration and conversation-output tests: 1,099 passed, two skipped.

  • Earlier physical Windows validation: 97 audio-client tests passed, followed by the live conversations above. The merged/default-on revision has not been rerun on that laptop.

  • Ruff lint and format checks pass; mypy passes for 153 source files.

  • Existing speech tests cover default and large buffering, echo reduction above 30 dB, overlapping speech preservation, missing references and reported/unreported microphone gaps. Worker startup errors, abrupt worker death, shutdown and session cancellation are covered. Readiness waits for both audio streams to start.
  • Diff: 548 lines (+411 / -137) across 6 files Reviewer: jackboyla Review duration: 32665m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 548 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.377
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #671"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.1% (MEDIUM) · Higher = larger blast radius
    48.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.0% · Safe to merge
    19.0%