Repository navigation
feat(audio): Compressed voice recordings with @braintrust/audio - #2658
Merged
Merged
Conversation
David Elner (delner)
requested review from
Abhijeet Prasad (AbhiPrasad),
Alex Z (CLowbrow),
Stephen Belanger (Qard) and
Luca Forstner (lforst)
October 23, 2026 21:10
David Elner (delner)
force-pushed
the
delner/audio-codecs
branch
4 times, most recently
from
October 27, 2026 16:16
008cbff to
dcbadff
Compare
David Elner (delner)
marked this pull request as ready for review
October 27, 2026 16:17
David Elner (delner)
force-pushed
the
delner/audio-codecs
branch
from
October 27, 2026 16:30
dcbadff to
37a3cb0
Compare
David Elner (delner)
changed the base branch from
main
to
delner/audio-recorder-pipeline
October 27, 2026 16:31
Luca Forstner (lforst)
approved these changes
Oct 27, 2026
Abhijeet Prasad (AbhiPrasad)
approved these changes
Oct 27, 2026
David Elner (delner)
added a commit
that referenced
this pull request
Oct 27, 2026
To facilitate transforms on recorded audio, for the purposes of compression, encoding, or filtering, this adds a configurable hook+middleware stack to the audio recording pipeline. ## What it does Moves recording out of the LiveKit plugin into a reusable **`AudioRecorder`** with an internal **middleware pipeline** that can transform each segment before upload. No outward changes to data or UX. [Opus compression and Ogg plugins leverage this pipeline in a separate, optional package.](#2658) ## Design Internal pipeline: <img width="492" height="642" alt="Screenshot 2026-10-20 at 3 20 41 PM" src="https://github.com/user-attachments/assets/77f6064c-fe74-48f5-a639-a5f2331a8bb7" /> - **`AudioRecorder`** places PCM frames from each source on a shared timeline and cuts bounded segments. It runs each segment through the middleware and hands the result to the integration. - **Middleware** works like Rack or Koa: `(segment, meta, next)`, transform on the way in, observe on the way out. Each recording builds its own stack, so state is never shared between calls. Middleware can change the format or channel layout and record facts in `meta.attributes`, published with the file. - **The integration** (LiveKit) owns capture, playback, spans and uploads. It publishes what each file contains: format, channels and sources. - **Bounded and safe.** One segment is in flight at a time, and buffered audio has a memory limit. A failing middleware omits its segment without affecting the call. ``` js/src/ pcm-buffer.ts PCM timeline, resampling, segment cuts (renamed from pcm-audio.ts) audio-recorder.ts buffering, segment rotation, finish audio-middleware.ts the middleware contract and runner ```
David Elner (delner)
force-pushed
the
delner/audio-codecs
branch
from
October 27, 2026 19:26
7eaa0fd to
0d6f894
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #2657
To provide more efficient, out-of-the-box encoding of audio, this adds
opusandoggplugins as middleware.What it does
By default, voice recordings upload as standard Ogg Opus files instead of raw PCM.
Install the package to activate:
Encoder settings are optional and declarative:
braintrustdoesn't depend on this package. Without it, recordings fall back to raw PCM, with a warning.codec: { name: "pcm" }to always record raw PCM.How it works
@audio/encode-opus) 20 ms at a time, pausing for the event loop every second of audio, so the agent stays responsive.codecandcontainerinto the internal middleware pipeline; users never write middleware.Performance
Measured on one 44-second recording segment: about 0.4 s of CPU in total, with the longest pause to the event loop around 10 ms, and 4 MB of PCM uploaded as 344 KB.