drumscript.extract_stems

extract_stems(audio_path, output_dir=None, output_format='wav', drumless=False, mute=None, all_stems=False, full=False)[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.

  • full (bool, optional) – If True, returns a detailed dictionary of all output paths.

Returns:

Path to the extracted file, or a dictionary of results if full=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
)
print(f"Backing track saved to: {results['mix']}")