Skip to content

Conversation

@toubatbrian
Copy link
Contributor

@toubatbrian toubatbrian commented Oct 27, 2025

Add utility to play a local audio file.

This is a dependency of BackgroundAudio player

@changeset-bot
Copy link

changeset-bot bot commented Oct 27, 2025

🦋 Changeset detected

Latest commit: d2d6774

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

This PR includes changesets to release 14 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugins-test Patch

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

@toubatbrian toubatbrian changed the title brianyin/ajs-310-background-audio brian-/bg-audio Oct 27, 2025
@toubatbrian toubatbrian changed the title brian-/bg-audio brianyin/ajs-310-play-local-audio-file-utility Oct 27, 2025
Comment on lines 51 to 59
'-probesize',
'32',
'-analyzeduration',
'0',
'-fflags',
'+nobuffer+flush_packets',
'-flags',
'low_delay',
])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same set of flags as in python

Comment on lines +130 to +141
it('should gracefully handle close while read is pending', async () => {
const channel = createStreamChannel<string>();
const reader = channel.stream().getReader();

const readPromise = reader.read();

await channel.close();

const result = await readPromise;
expect(result.done).toBe(true);
expect(result.value).toBeUndefined();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add tests to make sure buffered read after close still reads correct values

Comment on lines 45 to 57
for await (const frame of codecs.loopAudioFramesFromFile(audioFile, {
sampleRate: 48000,
numChannels: 1,
abortSignal: abortController.signal,
})) {
await audioSource.captureFrame(frame);
frameCount++;

if (frameCount % 100 === 0) {
logger.info(`Played ${frameCount} frames (${(frameCount * 0.1).toFixed(1)}s)`);
}
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

example of directly playing an audio file on server side and send to livekit.

Comment on lines +120 to +129
.inputOptions([
'-probesize',
'32',
'-analyzeduration',
'0',
'-fflags',
'+nobuffer+flush_packets',
'-flags',
'low_delay',
])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

same flags as in python

Copy link
Member

Choose a reason for hiding this comment

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

when the generator closes, where do we close the ffmpeg process?

@toubatbrian toubatbrian merged commit ac1db65 into main Oct 29, 2025
8 checks passed
@toubatbrian toubatbrian deleted the brian-/bg-audio branch October 29, 2025 06:49
@github-actions github-actions bot mentioned this pull request Oct 29, 2025
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