mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-24 02:06:15 +00:00
[skip ci] feat(audio recording): handle folder creation in start_recording directly
This commit is contained in:
@@ -1317,17 +1317,8 @@ class LeRobotDataset(torch.utils.data.Dataset):
|
|||||||
Starts recording audio data provided by the microphone and directly writes it in a .wav file.
|
Starts recording audio data provided by the microphone and directly writes it in a .wav file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
audio_dir = self._get_raw_audio_file_path(
|
audio_file = self._get_raw_audio_file_path(self.num_episodes, "observation.audio." + microphone_key)
|
||||||
self.num_episodes, "observation.audio." + microphone_key
|
microphone.start_recording(output_file=audio_file)
|
||||||
).parent
|
|
||||||
if not audio_dir.is_dir():
|
|
||||||
audio_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
microphone.start_recording(
|
|
||||||
output_file=self._get_raw_audio_file_path(
|
|
||||||
self.num_episodes, "observation.audio." + microphone_key
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def save_episode(
|
def save_episode(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -283,7 +283,12 @@ class Microphone:
|
|||||||
|
|
||||||
return audio_readings
|
return audio_readings
|
||||||
|
|
||||||
def start_recording(self, output_file: str | None = None, multiprocessing: bool | None = False) -> None:
|
def start_recording(
|
||||||
|
self,
|
||||||
|
output_file: str | None = None,
|
||||||
|
multiprocessing: bool | None = False,
|
||||||
|
overwrite: bool | None = True,
|
||||||
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Starts the recording of the microphone. If output_file is provided, the audio will be written to this file.
|
Starts the recording of the microphone. If output_file is provided, the audio will be written to this file.
|
||||||
"""
|
"""
|
||||||
@@ -302,8 +307,15 @@ class Microphone:
|
|||||||
# Write recordings into a file if output_file is provided
|
# Write recordings into a file if output_file is provided
|
||||||
if output_file is not None:
|
if output_file is not None:
|
||||||
output_file = Path(output_file)
|
output_file = Path(output_file)
|
||||||
|
output_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
if output_file.exists():
|
if output_file.exists():
|
||||||
output_file.unlink()
|
if overwrite:
|
||||||
|
output_file.unlink()
|
||||||
|
else:
|
||||||
|
raise FileExistsError(
|
||||||
|
f"Output file {output_file} already exists. Set overwrite to True to overwrite it."
|
||||||
|
)
|
||||||
|
|
||||||
if multiprocessing:
|
if multiprocessing:
|
||||||
self.record_stop_event = process_Event()
|
self.record_stop_event = process_Event()
|
||||||
|
|||||||
Reference in New Issue
Block a user