From 2962330bb111e50a9e9d16d7c8498df96d86c81c Mon Sep 17 00:00:00 2001 From: CarolinePascal Date: Tue, 22 Apr 2025 18:31:08 +0200 Subject: [PATCH] style(imports): simplify soundfile imports --- benchmarks/audio/run_microphone_benchmark.py | 6 +++--- src/lerobot/microphones/portaudio/microphone_portaudio.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmarks/audio/run_microphone_benchmark.py b/benchmarks/audio/run_microphone_benchmark.py index f4cf16303..a3179d846 100644 --- a/benchmarks/audio/run_microphone_benchmark.py +++ b/benchmarks/audio/run_microphone_benchmark.py @@ -20,7 +20,7 @@ from pathlib import Path import matplotlib.pyplot as plt import numpy as np -import soundfile as sf +from soundfile import read from lerobot.microphones.configs import MicrophoneConfig from lerobot.microphones.portaudio import PortAudioMicrophone, PortAudioMicrophoneConfig @@ -97,8 +97,8 @@ def main( recorded_audio_chunks = all_audio_chunks[i][microphone_key] # Load recorded file - recorded_data, _ = sf.read(recording_dir / f"{microphone_key}_recording_{i}.wav") - if len(recorded_data.shape) == 1: + recorded_data, _ = read(recording_dir / f"{microphone_key}_recording_{i}.wav") + if recorded_data.ndim == 1: recorded_data = np.expand_dims(recorded_data, axis=1) record_length[i, j] = recorded_data.shape[0] diff --git a/src/lerobot/microphones/portaudio/microphone_portaudio.py b/src/lerobot/microphones/portaudio/microphone_portaudio.py index d2f320fc6..ca1c709ff 100644 --- a/src/lerobot/microphones/portaudio/microphone_portaudio.py +++ b/src/lerobot/microphones/portaudio/microphone_portaudio.py @@ -26,7 +26,7 @@ from typing import Any import numpy as np import sounddevice as sd -import soundfile as sf +from soundfile import SoundFile from lerobot.utils.errors import ( DeviceAlreadyConnectedError, @@ -196,7 +196,7 @@ class PortAudioMicrophone(Microphone): Thread/Process-safe loop to write audio data into a file. """ # Can only be run on a single process/thread for file writing safety - with sf.SoundFile( + with SoundFile( output_file, mode="w", samplerate=sample_rate,