Skip to content

Cwilson/audio processor#124

Merged
yepher merged 5 commits intomainfrom
cwilson/audio_processor
Mar 5, 2026
Merged

Cwilson/audio processor#124
yepher merged 5 commits intomainfrom
cwilson/audio_processor

Conversation

@yepher
Copy link
Copy Markdown
Contributor

@yepher yepher commented Mar 4, 2026

Build an example audio processor and accompanying documentation to support the example.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 4, 2026

🦋 Changeset detected

Latest commit: e4df303

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@livekit/track-processors Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an example Web Audio–based GainAudioProcessor (plus docs and sample app UI) to demonstrate how to build and use audio TrackProcessors alongside the existing video background processors.

Changes:

  • Export new GainAudioProcessor + options from the package entrypoint.
  • Add GainAudioProcessor implementation using a GainNode Web Audio graph.
  • Add new audio/video processor documentation and update the sample app + README to reference them.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/index.ts Re-exports the new GainAudioProcessor from the package entrypoint.
src/audio/GainAudioProcessor.ts Introduces a Web Audio gain-based audio TrackProcessor.
processor-docs/video-processors.md Adds standalone documentation for video processors.
processor-docs/audio-processors.md Adds standalone documentation for audio processors and how to build them.
example/sample.ts Adds sample app controls to insert/remove the audio processor and adjust gain.
example/index.html Adds UI for the audio processor toggle + gain slider.
README.md Refactors README to link out to the new processor docs and mention audio processors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment thread processor-docs/audio-processors.md Outdated
Comment thread src/audio/GainAudioProcessor.ts Outdated
Comment thread src/audio/GainAudioProcessor.ts
Comment thread src/audio/GainAudioProcessor.ts
Comment thread example/sample.ts Outdated
Comment thread README.md
Copy link
Copy Markdown
Contributor

@1egoman 1egoman left a comment

Choose a reason for hiding this comment

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

Just left a bunch of minor mostly documentation nitpicks, great work! I gave it a shot locally for me and it worked.

One other minor thing: before merging, if you could add a changesets entry per the comment on the pull request that would be appreciated!

Comment thread README.md Outdated
@@ -1,91 +1,51 @@
# LiveKit track processors

Prebuilt audio and video track processors for [LiveKit](https://livekit.io), implementing the [`TrackProcessor`](https://docs.livekit.io/home/client/tracks/manipulate/#track-processors) interface from `livekit-client`.
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, I thought I tried all the links. oops. Will update to this one.
https://docs.livekit.io/reference/client-sdk-js/interfaces/TrackProcessor.html

Comment thread README.md Outdated
- `BackgroundProcessor({ mode: 'disabled' })`

### Usage example
Background blur and virtual background for video tracks:
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.

thought: It might be worthwhile adding a small section here on video track processors here conceptually rather than immediately going right to the "prebuilt" reference processors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I will throw together some mermaid diagrams too

Comment thread README.md Outdated
## Audio processors

A track processor is instantiated with a Transformer.
Gain control for audio tracks, and a reference implementation for building custom audio processors:
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.

thought: Same thing as the video track section - It might be worthwhile adding a small section here on audio track processors here conceptually rather than immediately going right to the "prebuilt" reference example processors.

Comment on lines +37 to +73
```ts
import { BackgroundProcessor } from '@livekit/track-processors';

const videoTrack = await createLocalVideoTrack();
const processor = BackgroundProcessor({ mode: 'background-blur' });
await videoTrack.setProcessor(processor);
room.localParticipant.publishTrack(videoTrack);

async function disableBackgroundBlur() {
await videoTrack.stopProcessor();
}

async function updateBlurRadius(radius) {
return processor.switchTo({ mode: 'background-blur', blurRadius: radius });
}
```

### Avoiding visual artifacts when switching

In a real application, you'll likely want to toggle background effects on and off. You could call `videoTrack.setProcessor()` / `videoTrack.stopProcessor()` on demand, but these functions can sometimes produce visual artifacts during the switching process, resulting in a poor user experience.

A better approach is to initialize the `BackgroundProcessor` in `disabled` mode and then switch to the desired mode later. This avoids artifacts entirely:

```ts
const videoTrack = await createLocalVideoTrack();
const processor = BackgroundProcessor({ mode: 'disabled' });
await videoTrack.setProcessor(processor);
room.localParticipant.publishTrack(videoTrack);

async function enableBlur(radius) {
await processor.switchTo({ mode: 'background-blur', blurRadius: radius });
}

async function disableBlur() {
await processor.switchTo({ mode: 'disabled' });
}
```
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.

nitpick: This example is basically wholesale repeated twice.

Comment on lines +77 to +78
Video processors in this package are built on two layers:

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.

nitpick: It might also be worth adding a note here that you don't necessarily have to follow this Transformer pattern, but if you do and pass it to ProcessorWrapper, then ProcessorWrapper abstracts away the actual MediaStreamTrack => VideoFrame => run through transformer => VideoFrame => MediaStreamTrack conversion which is probably not something the majority of track processor use cases would care about.

Comment on lines +130 to +137
// Optional lifecycle hooks — included for completeness as a reference implementation
async onPublish(room: Room): Promise<void> {
// No-op: override in subclasses if you need room context
}

async onUnpublish(): Promise<void> {
// No-op: override in subclasses for room lifecycle cleanup
}
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.

nitpick: IMO, either add a debug log in these so that they do something and you can actually see when they fire in the example app, or get rid of them outright given that they are probably fairly easily discoverable by reading the TrackProcessor type definitions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like that they are there a super simple obvious example so will add a log

@yepher yepher merged commit 9ef5191 into main Mar 5, 2026
4 checks passed
@yepher yepher deleted the cwilson/audio_processor branch March 5, 2026 13:52
@github-actions github-actions Bot mentioned this pull request Mar 5, 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