From 44af02a334f8b95d101e60d9cf803efb39c8ffa2 Mon Sep 17 00:00:00 2001 From: CarolinePascal Date: Fri, 4 Apr 2025 18:24:04 +0200 Subject: [PATCH] Remove variable audio recordings data types (will be converted to float32 anyway) --- lerobot/common/robot_devices/microphones/configs.py | 1 - lerobot/common/robot_devices/microphones/microphone.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lerobot/common/robot_devices/microphones/configs.py b/lerobot/common/robot_devices/microphones/configs.py index eb59be49..e90da519 100644 --- a/lerobot/common/robot_devices/microphones/configs.py +++ b/lerobot/common/robot_devices/microphones/configs.py @@ -33,5 +33,4 @@ class MicrophoneConfig(MicrophoneConfigBase): microphone_index: int sampling_rate: int | None = None channels: list[int] | None = None - data_type: str | None = None mock: bool = False \ No newline at end of file diff --git a/lerobot/common/robot_devices/microphones/microphone.py b/lerobot/common/robot_devices/microphones/microphone.py index b751f2b6..923d9b5e 100644 --- a/lerobot/common/robot_devices/microphones/microphone.py +++ b/lerobot/common/robot_devices/microphones/microphone.py @@ -116,7 +116,7 @@ class Microphone: ```python from lerobot.common.robot_devices.microphones.configs import MicrophoneConfig - config = MicrophoneConfig(microphone_index=0, sampling_rate=16000, channels=[1], data_type="int16") + config = MicrophoneConfig(microphone_index=0, sampling_rate=16000, channels=[1]) microphone = Microphone(config) microphone.connect() @@ -136,7 +136,6 @@ class Microphone: #Store the recording sampling rate and channels self.sampling_rate = config.sampling_rate self.channels = config.channels - self.data_type = config.data_type self.mock = config.mock @@ -203,7 +202,7 @@ class Microphone: device=self.microphone_index, samplerate=self.sampling_rate, channels=max(self.channels)+1, - dtype=self.data_type, + dtype="float32", callback=self._audio_callback, ) #Remark : the blocksize parameter could be passed to the stream to ensure that audio_callback always recieve same length buffers. @@ -220,6 +219,7 @@ class Microphone: self.read_queue.put(indata[:,self.channels]) def _record_loop(self, output_file: Path) -> None: + #Can only be run on a single process/thread for file writing safety with sf.SoundFile(output_file, mode='x', samplerate=self.sampling_rate, channels=max(self.channels)+1, subtype=sf.default_subtype(output_file.suffix[1:])) as file: while not self.record_stop_event.is_set():