diff --git a/benchmarks/audio/run_microphone_benchmark.py b/benchmarks/audio/run_microphone_benchmark.py index 0ba40a551..89fade45f 100644 --- a/benchmarks/audio/run_microphone_benchmark.py +++ b/benchmarks/audio/run_microphone_benchmark.py @@ -29,7 +29,7 @@ from lerobot.microphones.utils import ( make_microphones_from_configs, ) from lerobot.utils.robot_utils import ( - busy_wait, + precise_sleep, ) @@ -70,7 +70,7 @@ def main( # Record audio chunks for j in range(audio_chunks_number): - busy_wait(audio_chunks_duration) + precise_sleep(audio_chunks_duration) for microphone_key, microphone in microphones.items(): audio_chunk = microphone.read() diff --git a/benchmarks/audio/run_tactile_benchmark.py b/benchmarks/audio/run_tactile_benchmark.py index a98e7d970..debfe1017 100644 --- a/benchmarks/audio/run_tactile_benchmark.py +++ b/benchmarks/audio/run_tactile_benchmark.py @@ -28,7 +28,7 @@ from lerobot.microphones.utils import ( make_microphones_from_configs, ) from lerobot.utils.robot_utils import ( - busy_wait, + precise_sleep, ) @@ -59,7 +59,7 @@ def main( ) # Record audio chunks - busy_wait(10.0) + precise_sleep(10.0) for sensor_key, sensor in sensors.items(): data_chunk = sensor.read() diff --git a/src/lerobot/microphones/portaudio/interface_sounddevice_sdk.py b/src/lerobot/microphones/portaudio/interface_sounddevice_sdk.py index f4ec4c832..9e51283df 100644 --- a/src/lerobot/microphones/portaudio/interface_sounddevice_sdk.py +++ b/src/lerobot/microphones/portaudio/interface_sounddevice_sdk.py @@ -21,7 +21,7 @@ from typing import Any import numpy as np from sounddevice import PortAudioError -from lerobot.utils.robot_utils import busy_wait +from lerobot.utils.robot_utils import precise_sleep # --- Interface definitions for InputStream --- @@ -335,7 +335,7 @@ class FakeSounddeviceSDKAdapter(ISounddeviceSDK): def _streaming_loop(self): if self.callback is not None: while not self._streaming_thread_stop_event.is_set(): - busy_wait(self.latency) + precise_sleep(self.latency) tmp_data = self._simulated_audio_data() self.callback( tmp_data, diff --git a/src/lerobot/microphones/portaudio/microphone_portaudio.py b/src/lerobot/microphones/portaudio/microphone_portaudio.py index eb6a9827d..a3707115b 100644 --- a/src/lerobot/microphones/portaudio/microphone_portaudio.py +++ b/src/lerobot/microphones/portaudio/microphone_portaudio.py @@ -268,7 +268,7 @@ class PortAudioMicrophone(Microphone): self.audio_callback_start_event.clear() # Create and start an audio input stream with a recording callback - # Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the busy_wait function. + # Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the precise_sleep function. process_init_event = process_Event() self.record_process = Process( target=self._record_process, diff --git a/src/lerobot/microphones/touchlab/sensor_touchlab.py b/src/lerobot/microphones/touchlab/sensor_touchlab.py index 7370d2bef..d82a7111d 100644 --- a/src/lerobot/microphones/touchlab/sensor_touchlab.py +++ b/src/lerobot/microphones/touchlab/sensor_touchlab.py @@ -171,7 +171,7 @@ class TouchLabSensor(Microphone): self.audio_callback_start_event.clear() # Create and start an audio input stream with a recording callback - # Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the busy_wait function. + # Remark: this is done in a separate process so that audio recording is not impacted by the main thread CPU usage, especially the precise_sleep function. process_init_event = process_Event() self.record_process = Process( target=self._record_process, diff --git a/src/lerobot/scripts/lerobot_record.py b/src/lerobot/scripts/lerobot_record.py index 1921ca1eb..e01a30957 100644 --- a/src/lerobot/scripts/lerobot_record.py +++ b/src/lerobot/scripts/lerobot_record.py @@ -363,7 +363,7 @@ def record_loop( # This initial wait might be longer than the audio chunk duration to # (1) ensure that the audio buffers are filled with enough data # (2) add additional initial samples to the dataset in case of variable audio chunk duration during training - busy_wait(DEFAULT_INITIAL_AUDIO_BUFFER_DURATION) + precise_sleep(DEFAULT_INITIAL_AUDIO_BUFFER_DURATION) for microphone_name, microphone in robot.microphones.items(): audio_chunk = microphone.read() audio_buffer[microphone_name] = rolling_vstack(audio_buffer[microphone_name], audio_chunk) diff --git a/tests/microphones/test_portaudio.py b/tests/microphones/test_portaudio.py index b8c8a65b4..d17b2b981 100644 --- a/tests/microphones/test_portaudio.py +++ b/tests/microphones/test_portaudio.py @@ -33,7 +33,7 @@ from lerobot.utils.errors import ( DeviceNotConnectedError, DeviceNotRecordingError, ) -from lerobot.utils.robot_utils import busy_wait +from lerobot.utils.robot_utils import precise_sleep MODULE_PATH = "lerobot.microphones.portaudio.microphone_portaudio" RECORDING_DURATION = 1.0 @@ -302,7 +302,7 @@ def test_stop_recording_success(default_config, test_sdk, multiprocessing): microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk) microphone.connect() microphone.start_recording(multiprocessing=multiprocessing) - busy_wait(RECORDING_DURATION) + precise_sleep(RECORDING_DURATION) microphone.stop_recording() assert not microphone.is_recording @@ -316,7 +316,7 @@ def test_stop_writing_success(tmp_path, default_config, test_sdk, multiprocessin microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk) microphone.connect() microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing) - busy_wait(RECORDING_DURATION) + precise_sleep(RECORDING_DURATION) microphone.stop_recording() assert not microphone.is_recording @@ -348,7 +348,7 @@ def test_disconnect_while_recording(default_config, test_sdk, multiprocessing): microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk) microphone.connect() microphone.start_recording(multiprocessing=multiprocessing) - busy_wait(RECORDING_DURATION) + precise_sleep(RECORDING_DURATION) microphone.disconnect() assert not microphone.is_connected @@ -362,7 +362,7 @@ def test_disconnect_while_writing(tmp_path, default_config, test_sdk, multiproce microphone = PortAudioMicrophone(default_config, sounddevice_sdk=test_sdk) microphone.connect() microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing) - busy_wait(RECORDING_DURATION) + precise_sleep(RECORDING_DURATION) microphone.disconnect() assert not microphone.is_connected @@ -378,7 +378,7 @@ def test_read_success(default_config, test_sdk, multiprocessing): microphone.connect() microphone.start_recording(multiprocessing=multiprocessing) - busy_wait(RECORDING_DURATION) + precise_sleep(RECORDING_DURATION) data = microphone.read() @@ -398,7 +398,7 @@ def test_writing_success(tmp_path, default_config, test_sdk, multiprocessing): microphone.connect() microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing) - busy_wait(RECORDING_DURATION) + precise_sleep(RECORDING_DURATION) microphone.stop_recording() @@ -420,7 +420,7 @@ def test_read_while_writing(tmp_path, default_config, test_sdk, multiprocessing) microphone.connect() microphone.start_recording(output_file=tmp_path / "test.wav", multiprocessing=multiprocessing) - busy_wait(RECORDING_DURATION) + precise_sleep(RECORDING_DURATION) read_data = microphone.read() microphone.stop_recording()