-
Notifications
You must be signed in to change notification settings - Fork 113
Description
👋 Hey there!
I've been prototyping with the Python SDK to build an audio gateway between another realtime system and LiveKit. I am basically creating a new AudioSource and feeding frames to it, similar to what the publish_wave example does, but rather than having a generated sine wave, I am feeding it audio frames.
The problem I'm running into is that the function takes too long to run. I added some logs with precise differences, and I'm measuring it takes somewhere between 6 and 30ms to run. This is a problem because audio will end up very delayed very quickly, as the delay compounds.
Initially I thought I might have been copying buffers not too efficiently, but the publish_wave example shows the same symptoms.
Here is how I measured:
t0 = perf_counter_ns()
await source.capture_frame(audio_frame)
t1 = perf_counter_ns()
print(f'XX capture frame' {(t1-t0)/1e6:.3f}')And here is some output (this was on macOS, FWIW):
XX capture frame 13.939
XX capture frame 15.069
XX capture frame 19.562
XX capture frame 11.712
XX capture frame 8.328
XX capture frame 10.812
XX capture frame 11.314
XX capture frame 7.734
XX capture frame 12.327
XX capture frame 10.045
XX capture frame 5.673
XX capture frame 12.810
XX capture frame 24.589
I also tried using 20ms audio chunks, but that doesn't seem to change things much, so I'm out of ideas. Is there a way to make this faster? Would using Go work better for this scenario?
Thanks in advance! 🙏