Skip to content

Fully configure frame processors when they are used directly on an audio stream#679

Open
1egoman wants to merge 20 commits into
mainfrom
frame-processor-on-audio-stream
Open

Fully configure frame processors when they are used directly on an audio stream#679
1egoman wants to merge 20 commits into
mainfrom
frame-processor-on-audio-stream

Conversation

@1egoman
Copy link
Copy Markdown
Contributor

@1egoman 1egoman commented May 20, 2026

Updates the python sdk so that FrameProcessor-based noise cancellation providers can be used directly on AudioStream, without having to go through the agent's RoomIO to be able to initialize itself with credentials.

For example, with this change, something like the below becomes possible:

stream = rtc.AudioStream.from_track(                                                                                                                   
    track=track,
    sample_rate=SAMPLE_RATE,                                             
    num_channels=CHANNELS,
    noise_cancellation=ai_coustics.audio_enhancement(model=ai_coustics.EnhancerModel.QUAIL_VF_L)  ,
) 

The way this works - Tracks now keep track of which room they are part of (holding a weakref value). When the room a track is in changes, it computes new frame processor options and sends these to any AudioStreams which are associated with the track.

The noise_cancellation_leave_open parameter allows the agents sdk to call this from_track method with a frame processor which remains open across the whole session, and won't be auto-closed when the track is closed.

This goes along with livekit/agents#5867, which removes the relevant event handling logic in the agents sdk. I will follow up with a node version of this once the python one is in a good state.

Todo

  • Add some tests for this newly added behavior

@1egoman 1egoman force-pushed the frame-processor-on-audio-stream branch from 3e5a9ab to f62c247 Compare May 26, 2026 15:15
Comment thread livekit-rtc/livekit/rtc/track.py Outdated
@1egoman 1egoman marked this pull request as ready for review May 26, 2026 21:25
devin-ai-integration[bot]

This comment was marked as resolved.

1egoman added 2 commits May 27, 2026 11:28
@1egoman 1egoman force-pushed the frame-processor-on-audio-stream branch from 564b2c7 to 8d3f4fe Compare May 27, 2026 17:02
1egoman added 2 commits May 27, 2026 13:26
These tests exercise all the frame processor track reparenting under
room / etc paths.
num_channels: int = 1,
frame_size_ms: int | None = None,
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
noise_cancellation_leave_open: bool = False,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
noise_cancellation_leave_open: bool = False,

Can we move that inside NoiseCancellationOptions?

Copy link
Copy Markdown
Contributor Author

@1egoman 1egoman May 28, 2026

Choose a reason for hiding this comment

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

Unfortunately, no - this also important to the FrameProcessor[AudioFrame] side of that noise_cancellation union. Open to putting it somewhere else but it needs to be settable in the FrameProcessor path.

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