Spleeter Source Separation Library

repository·master·Indexed 12 days ago

https://github.com/deezer/spleeter

A high-performance audio source separation library by Deezer using pretrained TensorFlow models to split audio into stems. It supports 2-stem (vocals/accompaniment), 4-stem (vocals/drums/bass/other), and 5-stem (vocals/drums/bass/piano/other) separation. Spleeter utilizes a U-net architecture and provides a CLI for separation, training, and evaluation, as well as a Python API for custom model development.

Tokens
5.4K
Snippets
17
Records
27
Agent score
98%

What's inside Spleeter

  1. What is Spleeter and its available models?

    master

    Spleeter is a source separation library written in Python using TensorFlow. It provides pretrained models for various separation tasks:

    • 2 stems: Vocals (singing voice) / accompaniment separation.
    • 4 stems: Vocals / drums / bass / other separation.
    • 5 stems: Vocals / drums / bass / piano / other separation.

    It can be used via the command line, as a Python library, or via Docker.

  2. Overview of Spleeter's separation capabilities

    master

    Spleeter is a fast music source separation tool based on TensorFlow that allows users to split audio files into different stems using pre-trained models.

    Supported separation modes:

    • 2 stems: Vocals and Accompaniment.
    • 4 stems: Vocals, Drums, Bass, and Other.
    • 5 stems: Vocals, Drums, Bass, Piano, and Other.

    Beyond inference, Spleeter allows users to train new source separation models or fine-tune existing pre-trained ones using TensorFlow, provided a dataset of isolated sources is available.

  3. Spleeter model architecture and implementation

    master

    Spleeter uses a U-net architecture, which is an encoder/decoder Convolutional Neural Network (CNN) with skip connections.

    Key technical details:

    • Architecture: 12-layer U-nets (6 layers for the encoder and 6 for the decoder).
    • Mechanism: The U-net estimates a soft mask for each source (stem).
    • Training Loss: $L_1$-norm between masked input mix spectrograms and source-target spectrograms.
    • Separation Methods: Separation is performed from estimated source spectrograms using either soft masking or multi-channel Wiener filtering.
    • Runtime: Implemented in TensorFlow, supporting both CPU and GPU execution.
  4. Spleeter performance and speed

    master

    Spleeter is designed for high-speed processing of large datasets. On a single GPU (e.g., GeForce RTX 2080), it can separate a 4-stem mix approximately 100 times faster than real-time.

    Example benchmark: Processing the entire musdb18 test dataset (~3.5 hours of audio) into 4 stems in less than 2 minutes using a single GPU and a dual Intel Xeon Gold CPU (where the CPU handles mix loading and stem export).

  5. Ways to install and distribute Spleeter

    master

    Spleeter can be consumed in several ways depending on your environment:

    • Python Package: Available as a standalone package via pip.
    • Conda: Provided via a conda recipe.
    • Docker: Available as self-contained Docker images for easy deployment across various platforms.
  6. Set up Spleeter for development

    master

    Spleeter is managed using Poetry. To set up a development environment and run the test suite, follow these steps:

    1. Clone the repository.
    2. Install Poetry.
    3. Install dependencies using poetry install.
    4. Run tests using poetry run pytest.
    # Clone spleeter repository
    git clone https://github.com/Deezer/spleeter && cd spleeter
    
    # Install poetry
    pip install poetry
    
    # Install spleeter dependencies
    poetry install
    
    # Run unit test suite
    poetry run pytest tests/
  7. Quick start with Spleeter

    master

    To quickly test Spleeter, you can install the necessary dependencies, install the package via pip, download an example file, and run a separation task.

    Note: Spleeter requires ffmpeg and libsndfile to be installed on your system. While Conda can be used to install these, it is no longer the recommended method for installing Spleeter itself.

    Warning for Apple M1 users: There are known TensorFlow compatibility issues with Apple M1 chips. Check the official issue tracker for workarounds.

    # install dependencies using conda
    conda install -c conda-forge ffmpeg libsndfile
    
    # install spleeter with pip
    pip install spleeter
    
    # download an example audio file
    wget https://github.com/deezer/spleeter/raw/master/audio_example.mp3
    
    # separate the example audio into two components
    spleeter separate -p spleeter:2stems -o output audio_example.mp3
  8. How the DatasetBuilder works

    master

    The DatasetBuilder is the core engine for constructing the preprocessing pipeline. It transforms raw audio paths from a CSV into a batched TensorFlow dataset of spectrograms.

    The Pipeline Lifecycle:

    1. Segmentation: Splits songs into n_chunks_per_song segments based on chunk_duration.
    2. Loading & Spectrograms: Loads waveforms via the AudioAdapter and computes spectrograms for the mix and all target instruments.
    3. Caching: Converts spectrograms to uint format to minimize disk usage and saves them to the cache_directory. If wait_for_cache is True, it will block until the cache index is found.
    4. Augmentation (Training only): Applies random_time_stretch and random_pitch_shift if random_data_augmentation is enabled.
    5. Formatting: Reshapes tensors to the target (T, F, n_channels) and maps the data into the final (input_, output) format where:
      • input_ is a dict containing the mix spectrogram: {'mix_spectrogram': ...}
      • output is a dict containing ground truth instrument spectrograms: {'vocals_spectrogram': ..., 'accompaniment_spectrogram': ...}
  9. Separate audio using the Spleeter CLI

    master

    You can perform audio separation from the command line using the spleeter separate command.

    To separate an audio file into its constituent parts (e.g., vocals and accompaniment), use the following syntax:

    spleeter separate -o <output_directory> <input_audio_file>

    By default, this will create a directory within the specified output path named after the input file, containing the separated .wav files.

    !spleeter separate -o output/ audio_example.mp3
  10. Use the Spleeter CLI

    master

    Spleeter can be invoked as a Python module. The CLI provides three primary commands: train for training models, evaluate for testing models on the MUSDB dataset, and separate for performing audio source separation.

    Usage Pattern:

    python -m spleeter {train,evaluate,separate} [options]
    python -m spleeter separate ...
  11. Configure separate_to_file output formatting

    master

    When using separate_to_file, you can control how the output files are named and organized using the filename_format parameter. This is a Python-style format string that supports the following placeholders:

    • {instrument}: The name of the separated source (e.g., 'vocals', 'drums').
    • {filename}: The base filename of the input audio.
    • {foldername}: The name of the directory containing the input audio.
    • {codec}: The output codec used (e.g., 'wav', 'mp3').

    Default format: "{filename}/{instrument}.{codec}"