AudioTools

repository·master·Indexed 43 days ago

https://github.com/descriptinc/audiotools

An object-oriented library for handling audio signals, providing fast augmentation routines, batching, padding, and signal processing. It features the AudioSignal class for manipulating audio data, including differentiable LUFS loudness normalization, convolution with impulse responses, pitch shifting, time stretching, and codec transformations. The library includes modules for DSP, FFMPEG routines, audio dataset management, and machine learning layers such as spectral gating.

Tokens
7.6K
Snippets
27
Records
48
Agent score
56%

What's inside AudioTools

  1. Calculate spectral distance metrics

    master
    The audiotools.metrics.spectral module provides metrics specifically designed to measure distances in the spectral domain. These are useful for comparing the frequency content and spectral envelopes of two audio signals. Refer to the audiotools.metrics.spectral API for specific spectral distance implementations.
  2. Combine transforms using the Compose transform

    master

    The Compose transform allows you to apply a sequence of transforms to an audio signal. It takes a list of transforms as its first positional argument.

    Key behaviors:

    • Sequential Application: Transforms are applied in the order they appear in the list.
    • Naming/Indexing: If transforms are not explicitly named, Compose assigns them a numeric prefix corresponding to their position (e.g., 0.LowPass, 1.LowPass).
    • Nesting: Compose transforms can be nested within other Compose transforms to create complex hierarchies.
    • Probabilistic Application: You can pass a prob argument to Compose to determine the likelihood of the entire sequence being applied, or pass prob to individual transforms within the list to control their application independently.
    import audiotools.transforms as tfm
    
    transform = tfm.Compose(
        [
            tfm.MuLawQuantization(prob=0.5),
            tfm.LowPass(prob=0.5),
        ],
        prob=0.5
    )
  3. How transforms work: instantiate and transform

    master

    Every transform in AudioTools follows a two-step API pattern:

    1. instantiate(state, signal): This method calculates the specific parameters (like cutoff frequencies or noise levels) required for the transform. It uses a state (seed) to ensure reproducibility. It returns a dictionary of parameters.
    2. transform(signal, **kwargs): This method performs the actual audio processing using the parameters provided in kwargs.

    You can check which arguments a transform expects by inspecting its .keys attribute.

    from audiotools import transforms as tfm
    
    transform = tfm.LowPass()
    
    # Get parameters for a specific seed
    kwargs = transform.instantiate(seed=0)
    
    # See what keys are required
    print(transform.keys) # e.g., ['cutoff', 'mask']
    
    # Apply
    output = transform(signal.clone(), **kwargs)
  4. Understanding transform masks and probability

    master

    Transforms have a prob attribute (defaulting to 1.0) which represents the probability that the transform will actually be applied to the signal.

    When you call instantiate(), the transform generates a mask (a boolean value).

    • If mask is True, the transform is applied.
    • If mask is False, the signal remains unchanged.

    This is particularly useful during batch training to ensure some samples in a batch are augmented while others remain original.