drumscript.extract_stems¶
- extract_stems(audio_path, output_dir=None, output_format='wav', drumless=False, mute=None, all_stems=False, verbose=False, full=None)[source]¶
Extracts drum stems and optionally separates the full track into constituent parts.
This function serves as a high-level wrapper around the Demucs source separation model. It allows for quick isolation of drum tracks for transcription, or the creation of “drumless” backing tracks for practice.
- Parameters:
audio_path (str) – Path to the input audio file.
output_dir (str, optional) – Directory to save the output files. Defaults to current working directory.
output_format (str, optional) – Export format, ‘wav’ or ‘mp3’. Defaults to ‘wav’.
drumless (bool, optional) – If True, extracts a track with NO drums (plus the isolated drum track).
mute (list, optional) – List of specific stems to mute (e.g., [‘bass’, ‘vocals’]).
all_stems (bool, optional) – If True, exports all separated stems individually.
verbose – If True, returns a detailed dictionary of all output paths instead
of just the drum stem path. :type verbose: bool, optional :param full: Deprecated since v0.1.6, will be removed in v1.0.0. Use
verboseinstead. Passingfull=Truestill works but emits aDeprecationWarning. :type full: bool, optional- Returns:
Path to the extracted file, or a dictionary of results if
verbose=True.- Return type:
str or dict
Note
Source separation is computationally heavy. On a standard CPU, extracting stems from a 3-minute song may take a few minutes.
Examples:
Extract just the drum stem to the current directory:
import drumscript as ds drum_path = ds.extract_stems("my_song.mp3")
Create a drumless backing track in MP3 format:
results = ds.extract_stems( "my_song.mp3", drumless=True, output_format="mp3", # full=True, # LEGACY CODE FROM V0.1.5 (--full flag replaced with deprecation shim, in place of --verbose) verbose=True ) print(f"Backing track saved to: {results['mix']}")