Skip to content

ensure failing audio filter init doesn't degrade audio quality#1270

Merged
lukasIO merged 2 commits into
mainfrom
lukas/rate-fallback
Jul 22, 2026
Merged

ensure failing audio filter init doesn't degrade audio quality#1270
lukasIO merged 2 commits into
mainfrom
lukas/rate-fallback

Conversation

@lukasIO

@lukasIO lukasIO commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Problem

When a noise-cancellation filter is requested and the plugin supports
separate rates (v2), the WebRTC sink is created at the codec's native rate
on the assumption that the filter will resample to the requested output
rate. If the filter session fails to initialize, the code fell back to a
plain native stream reusing that codec-rate sink — so codec-rate audio
was forwarded downstream mislabeled as the output rate.

Whenever the codec rate differs from the requested output rate (e.g. a SIP
telephony call, or any track where STT asks for a lower rate than the codec),
this dilates the audio in time: on a failed init we observed STT
transcription_delay jump from ~0.3–0.5s to ~5.5s, with the agent responding
seconds late. Removing the NC option restored baseline latency, because
without the option the sink is already created at the output rate.

Fix

Decide the sink's rate based on whether a filter session actually exists:
run at the codec rate only when a live filter is there to resample it,
otherwise run directly at the requested output rate. A failed (or absent)
filter now degrades to clean, correctly-rated native audio — identical to the
no-option path.

Applied to both FfiAudioStream::from_track and from_participant.

Notes

  • Pure host-side fix; no protocol or plugin change. Orthogonal to why a
    given filter session fails to initialize.
  • Verified: livekit-ffi builds clean (no new warnings). Runtime check
    pending — a SIP call with the option set should return transcription_delay
    to baseline with no pitch/speed shift.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Changeset ✓

This PR includes a changeset covering all affected packages:

Package Bump
livekit-ffi patch

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

Ensure that initializing a failing audio filter does not degrade audio quality as reported in issue #1270.
@lukasIO
lukasIO requested a review from ladvoc as a code owner July 21, 2026 12:34
@lukasIO
lukasIO merged commit e742aaf into main Jul 22, 2026
24 checks passed
@lukasIO
lukasIO deleted the lukas/rate-fallback branch July 22, 2026 08:02
@knope-bot knope-bot Bot mentioned this pull request Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants