nutritious-australia-78231
09/17/2025, 10:48 AMtall-airline-16756
09/17/2025, 10:48 AMtall-airline-16756
09/17/2025, 10:49 AMnutritious-australia-78231
09/17/2025, 10:51 AMgetTrackPublications() and streaming it to BE.
• any sample rate between 16k to 48k is fine, provided it remains constant through out the session.
• no addl processing is done in the client sidetall-airline-16756
09/17/2025, 10:52 AMgetTrackPublications(). Let me walk you through the steps to make this as smooth as possible:
1. Start by using getTrackPublications() to find and access your audio tracks. You'll want to filter these to get the microphone (audio) tracks specifically.
2. Next, create an AudioStream from the track, then use the resampleStream() utility to ensure a consistent output sample rate. Here's a simple example to guide you:
import { resampleStream } from '@livekit/agents';
const audioStream = new AudioStream(track);
const resampledStream = resampleStream({
stream: audioStream,
outputRate: 16000 // Set your desired constant sample rate
});
for await (const event of resampledStream) {
const frame = event.frame;
console.log(`Frame sample rate: ${frame.sampleRate}`); // Will always be 16000
}
1. Don't forget to handle track lifecycle events like track_subscribed, so you can dynamically apply resampling whenever new tracks are published.
By following these steps, you'll help ensure your audio stream keeps a steady sample rate—like 16kHz—throughout your session, no matter what input device is used. If you have any questions or need further assistance, feel free to ask—I'm here to help!
Sources: Receiving and publishing tracks | LiveKit Docs | Speech & Audio Processing | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/room_io/_output.py | Runtime/Scripts/Room/Participant/Participant.cs | packages/core/src/components/mediaTrack.tsnutritious-australia-78231
09/17/2025, 10:57 AMtall-airline-16756
09/17/2025, 10:57 AMAudioResampler. Choosing higher quality settings like HIGH or VERY_HIGH can give you better audio fidelity, though they do require a bit more processing power.
Right now, the resampleStream function in the LiveKit SDK doesn’t offer a quality parameter, so it defaults to MEDIUM quality. Here are a couple of ways you might approach this:
1. You could modify the resampleStream function to accept a quality parameter and then pass that along to the AudioResampler constructor.
2. Alternatively, you might consider doing the resampling outside of LiveKit using tools like soxr or pydub, which give you explicit control over the resampling quality.
If you’d like, I’m more than happy to guide you through implementing a custom resampleStream function with configurable quality—just let me know, and I can provide more details!
Sources: packages/livekit-rtc/src/audio_resampler.ts | agents/src/utils.test.ts | livekit-rtc/tests/test_resampler.py | livekit-ffi/protocol/audio_frame.protonutritious-australia-78231
09/17/2025, 10:58 AMtall-airline-16756
09/17/2025, 10:58 AM