From 421fdcce96559a9492a94ae460e434d33a6ec963 Mon Sep 17 00:00:00 2001 From: CarolinePascal Date: Fri, 9 May 2025 12:54:20 +0200 Subject: [PATCH] [skip ci] fix(audio latency): setting microphone recording latency to low as default --- src/lerobot/microphones/portaudio/microphone_portaudio.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lerobot/microphones/portaudio/microphone_portaudio.py b/src/lerobot/microphones/portaudio/microphone_portaudio.py index ca1c709ff..fa4edb1fd 100644 --- a/src/lerobot/microphones/portaudio/microphone_portaudio.py +++ b/src/lerobot/microphones/portaudio/microphone_portaudio.py @@ -170,14 +170,15 @@ class PortAudioMicrophone(Microphone): samplerate=self.sample_rate, channels=max(self.channels), dtype="float32", + blocksize=0, # Varying input buffer length, but no additional latency + latency="low", # Low latency mode (not enabled by default !) + # never_drop_input=True, # Disabled as it generates an error for some devices callback=self._audio_callback, ) - # Remark : the blocksize parameter could be passed to the stream to ensure that audio_callback always receive same length buffers. - # However, this may lead to additional latency. We thus stick to blocksize=0 which means that audio_callback will receive varying length buffers, but with no additional latency. self._is_connected = True - def _audio_callback(self, indata, frames, time, status) -> None: + def _audio_callback(self, indata, frames, timestamp, status) -> None: """ Low-level sounddevice callback. """