Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/resampler-flush-empty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@livekit/rtc-node': patch
---

Return no frames from `AudioResampler.flush()` when nothing is buffered, instead of one empty frame.
18 changes: 18 additions & 0 deletions packages/livekit-rtc/src/audio_resampler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2026 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0
import { describe, expect, it } from 'vitest';
import { AudioFrame } from './audio_frame.js';
import { AudioResampler } from './audio_resampler.js';

describe('AudioResampler', () => {
it('flush returns no frames when nothing is buffered', () => {
const resampler = new AudioResampler(48000, 16000);
expect(resampler.flush()).toEqual([]);

resampler.push(new AudioFrame(new Int16Array(4800), 48000, 1, 4800));
const tail = resampler.flush();
expect(tail.reduce((n, f) => n + f.samplesPerChannel, 0)).toBeGreaterThan(0);
expect(resampler.flush()).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion packages/livekit-rtc/src/audio_resampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class AudioResampler {
throw new Error(res.error);
}

if (!res.outputPtr) {
if (!res.outputPtr || !res.size) {
return [];
}

Expand Down
Loading