drumscript.audio_processor.audio_loader.load_audio¶
- load_audio(audio_path: str, sr: int | None = None) tuple[ndarray, int][source]¶
Load an audio file and optionally resample it.
- Parameters:
audio_path (str) – Path to the audio file (.wav, .mp3, .flac, .ogg, etc.).
sr (int or None) – Target sample rate in Hz. -
None(default): load at the file’s native sample rate (no resampling). - An integer (e.g.44100): resample to that rate.
- Returns:
Tuple of (audio_data, sample_rate).
- Return type:
tuple[np.ndarray, int]
- Raises:
FileNotFoundError – If the file does not exist.
Examples:
Load at native sample rate (for exploration / notebooks):
import drumscript as ds audio, sr = ds.load_audio("my_drum_loop.wav") print(f"Native rate: {sr} Hz")
Load and resample to 44100 Hz (for the transcription pipeline):
from drumscript.notation_generator.constants import SAMPLE_RATE audio, sr = ds.load_audio("my_drum_loop.wav", sr=SAMPLE_RATE)