rapid-shampoo-83551
12/09/2025, 12:17 AMaudioSource.waitForPlayout()? I have the following example code to demonstrate the issue I am facing:
// capture many frames ~100
await audioSource.waitForPlayout();
audioSource.clearQueue();
Since I am awaiting playout first, I would expect that audioSource.clearQueue(); does nothing - however the waitForPlayout promise resolve before audio has fully played out in the livekit playground (1-2 seconds early). audioSource.clearQueue(); stops playout on the client instantly resulting in the last few seconds of audio getting lost.
How can I wait for audio to finish playing in the playground.lively-winter-88668
12/09/2025, 10:45 AMwaitForPlayout() accounts for network latency, or audio buffering at the client end. You might need to add a couple of seconds buffer before calling clearQueue() or perhaps use https://docs.livekit.io/reference/python/v1/livekit/rtc/audio_source.html#livekit.rtc.audio_source.AudioSource.queued_duration to check if there is still queued audio.rapid-shampoo-83551
12/11/2025, 10:56 PMaudioSource.clearQueue(); before capturing the next set of audio frames (to make sure nothing else is being played out). It seems like this initial clearing of the queue, results in the waitForPlayout() not working properly.
audioSource.clearQueue(); <--- this lines is causing the issue
// capture around 100 frames
audioSource.captureFrame(frame)
await audioSource.waitForPlayout();
console.log("done")
The "done" log gets logged before audio finishes only if I clear the queue before hand.
Without the initial clearQueue, the "done" gets logged at the right time.
Even if I add a delay (1 second) after clearing the queue to ensure the clear queue request has propagated, the done log still comes too early.
How should I be clearing the queue to make it work?lively-winter-88668
12/12/2025, 9:39 AM