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))
Audio loaded!
# Extract stems
output_files = ds.extract_stems(
    audio_path=audio_file_path,  # Pass the file path, not the loaded audio
    output_dir="stems/",
)
Starting Demucs separation for: test_track_1.wav...
Demucs raw separation finished in 3.72 minutes.
Separation complete. Outputs saved in: stems/test_track_1
print(f"Isolated drum stem saved to: {output_files}")
Isolated drum stem saved to: stems/test_track_1/test_track_1_drums.wav
# 3. Create the in-browser playable widget for the drumless track
print("\nExtracted Drum Stem:")
# display(Audio(output_files['drums']))
display(Audio(output_files))
Extracted Drum Stem: