Audio Separator

0.44.1 · active · verified Wed Apr 15

Audio Separator is a Python package designed for easy audio stem separation, capable of splitting audio files into various stems (e.g., instrumental, vocals, drums, bass, etc.). It leverages a variety of pre-trained deep learning models, primarily from UVR (Ultimate Vocal Remover) and includes MDX-Net, VR Arch, Demucs, and MDXC models. The library offers both a Command Line Interface (CLI) for batch processing and a Python API for integration into other projects. It supports common audio formats like WAV, MP3, FLAC, and M4A.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Separator` class with an audio file path, a desired model name, and an output directory, then execute the separation process. The separated stems will be saved in the specified output directory. Models are automatically downloaded on first use. Replace `input_audio.wav` and `output_directory` with your actual paths.

import os
from audio_separator import Separator

# Ensure a dummy audio file exists for demonstration, or provide a real path
# For a runnable example, replace with an actual audio file path
audio_file_path = os.environ.get('AUDIO_FILE_PATH', 'input_audio.wav')
output_directory = os.environ.get('OUTPUT_DIR', 'separated_stems')
model_name = os.environ.get('MODEL_NAME', 'UVR_MDXNET_KARA_2')

# Create dummy input file if it doesn't exist for demonstration purposes
if not os.path.exists(audio_file_path):
    # This part is for demonstration only and won't create a valid audio file
    # In a real scenario, `input_audio.wav` would be a proper audio file.
    print(f"Warning: '{audio_file_path}' not found. Please provide a real audio file.")
    # Example: Create a tiny placeholder file (not actual audio)
    with open(audio_file_path, 'wb') as f:
        f.write(b'RIFF\x00\x00\x00\x00WAVEfmt \x10\x00\x00\x00\x01\x00\x01\x00\x44\xAC\x00\x00\x88\x58\x01\x00\x02\x00\x10\x00data\x00\x00\x00\x00')

# Initialize the Separator
separator = Separator(
    audio_file=audio_file_path,
    model_name=model_name,
    output_dir=output_directory,
    output_format='wav' # Specify output format (e.g., 'wav', 'mp3')
)

# Perform the separation
print(f"Separating '{audio_file_path}' using model '{model_name}'...")
primary_stem_path, secondary_stem_path = separator.separate()

print(f"Primary stem saved at: {primary_stem_path}")
print(f"Secondary stem saved at: {secondary_stem_path}")

# Clean up dummy file and directory for demonstration
if os.path.exists(audio_file_path) and audio_file_path == 'input_audio.wav':
    os.remove(audio_file_path)
if os.path.exists(output_directory) and output_directory == 'separated_stems':
    # In a real scenario, you might want to keep the output.
    import shutil
    shutil.rmtree(output_directory)
    print(f"Cleaned up temporary output directory: {output_directory}")

view raw JSON →