Extract Drums from a Song#

Sometimes a mix is so dense you can’t quite hear what the drummer is doing.

DrumScript uses Demucs, a deep-learning source separation model, to isolate the drum stem from a full polyphonic audio track. Demucs splits audio into four stems: drums, bass, vocals, and other. DrumScript then returns the path to the isolated drum track.

This is useful for:

  • Feeding a clean drum stem into ds.transcribe() for more accurate transcription.

  • Listening to the drum part in isolation for practice or analysis.

(Note: We are using a copyright-free synthetic track for this demonstration.)


from IPython.display import Audio, display

import drumscript as ds

# Load audio
audio_file_path = "audio/test_track_1.wav"
audio_file = ds.load_audio(audio_file_path)
print("Audio loaded!")
display(Audio(audio_file_path))
# Extract stems
output_files = ds.extract_stems(
    audio_path=audio_file_path,  # Pass the file path, not the loaded audio
    output_dir="stems/",
)
print(f"Isolated drum stem saved to: {output_files}")
# 3. Create the in-browser playable widget for the extracted drum stem
print("\nExtracted Drum Stem:")
# display(Audio(output_files['drums']))   # NOTE: won't work — extract_stems returns a path string, not a dict
display(Audio(output_files))