diff --git a/src/lerobot/datasets/lerobot_dataset.py b/src/lerobot/datasets/lerobot_dataset.py index b5e91a85e..53919b574 100644 --- a/src/lerobot/datasets/lerobot_dataset.py +++ b/src/lerobot/datasets/lerobot_dataset.py @@ -1435,7 +1435,7 @@ class LeRobotDataset(torch.utils.data.Dataset): for video_key in self.meta.video_keys: ep_metadata.update(self._save_episode_video(video_key, episode_index)) - #TODO(Caroline): add parallel encoding for audio as well + # TODO(Caroline): add parallel encoding for audio as well for audio_key in self.meta.audio_keys: ep_metadata.update(self._save_episode_audio(audio_key, episode_index)) diff --git a/src/lerobot/microphones/portaudio/microphone_portaudio.py b/src/lerobot/microphones/portaudio/microphone_portaudio.py index a3707115b..b9dbcaed4 100644 --- a/src/lerobot/microphones/portaudio/microphone_portaudio.py +++ b/src/lerobot/microphones/portaudio/microphone_portaudio.py @@ -497,6 +497,12 @@ class PortAudioMicrophone(Microphone): self.record_start_event.clear() # Ensures the audio stream is not started again ! self.record_stop_event.set() + # Wait for the stream to be stopped (might lead to race condition if the stream is not properly stopped on array reset and queue clearing) + timeout = 1.0 + while self.is_recording and timeout > 0: + time.sleep(0.01) + timeout -= 0.01 + self.read_shared_array.reset() self._clear_queue(self.write_queue, join_queue=True) @@ -504,11 +510,6 @@ class PortAudioMicrophone(Microphone): self.write_stop_event.set() self.write_thread.join() - timeout = 1.0 - while self.is_recording and timeout > 0: - time.sleep(0.01) - timeout -= 0.01 - if self.is_recording: raise RuntimeError(f"Error stopping recording for microphone {self.microphone_index}.") if self.is_writing: