Skip to main content

An opinionated segmentation library for (machine learning) audio

Project description

The libsegmenter audio segmentation library

A small library intended to provide helper functions for block-based processing in Python.

Find out more by exploring the code or reading the docs.

About

The main idea is to help the user choose a combination of window function and hop size, which satisfy the constant-overlap-add (COLA) condition, i.e., if the processing does not modify the blocks, the act of segmenting and un-segmenting the input audio data should be perfectly reconstructing (with some potential latency introduced by the system).

The library currently supports three different modes of operation

  • Overlap-Add (ola), where a rectangular window is applied to the input frames, and the specified window is applied to the output frames prior to reconstruction. This mode is intended for block-based processing in the time-domain, where the purposed of the overlapping windows is to interpolate the discontinuities between adjacent frames prior to reconstruction.

  • Weighted Overlap-Add (wola), where a square-root (COLA)-window is applied to both the input frame and output frame. This mode is intended for processing in the frequency domain along the lines of Short-time Fourier Transform (STFT) processing.

  • Analysis (analysis), where a window is applied to the input frames and disables computing output frames. Useful to obtain spectrograms.

The primary use-case for the library is to support machine learning tasks, which has led to a number of options which are designed to ease training tasks. The segmenter is implemented in both TensorFlow and PyTorch to support multiple machine learning tasks.

Recently, we have upgraded the library to version 1.0. This deprecated the C++ backend for now to simplify development. That being said, the general design has been simplified so implementing your own backend (and verifying it with our unit tests) should not be infeasible.

A word of caution

Note that segmentation is a destructive operation in the sense that we do not provide any pre and post windows. This means that the first and last couple of samples of your audio post subsequently segment-ing and unsegment-ing are going to be windowed, thus different than what you started out with. This is something to take into account when training.

Installation

Simply install from PyPi:

pip install libsegmenter

Example

To make a segmenter with a specific window:

import libsegmenter as seg
segmenter = seg.Segmenter(backend="torch", seg.WindowSelector("hann75"))

Use various supported transforms:

import libsegmenter as seg
segmenter = seg.Segmenter(backend="torch", seg.WindowSelector("hann75"))
transform = seg.TransformSelector(backend="torch", transform="spectrogram")
X = transform.forward(segmenter.segment(x))
x = transform.inverse(x)

Development

Installing python

Install uv (pip replacement):

# install for linux / mac
curl -LsSf https://astral.sh/uv/install.sh | sh

# install for windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Install the development packages:

uv venv
source .venv/bin/activate
uv sync --dev

Linting

We require everything to be fully typed. We enforce that by having 100% clearance on pyright:

uv run pyright
uv run ruff check
uv run ruff format

Licenses

The project is licensed under MIT. Add licenses using the addlicense tool found here:

addlicense -c "Niels de Koeijer, Martin Bo Møller" -l mit -y 2025 -ignore *.m

Documentation

Docs are mainly automatically generated and described with docstrings. To host the docs locally run:

mkdocs serve

They are automatically rebuilt on push to main.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libsegmenter-1.0.4.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libsegmenter-1.0.4-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file libsegmenter-1.0.4.tar.gz.

File metadata

  • Download URL: libsegmenter-1.0.4.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for libsegmenter-1.0.4.tar.gz
Algorithm Hash digest
SHA256 f032dc38fae0b0afb87b5580a08659b6c3953a24483e6a2d5368d4d3f99f8a8a
MD5 b55a7d21106522c20bfbed0dd153d055
BLAKE2b-256 a79f8dd79ffe4837134c76552309f284e92c5758b2d63c00bd336545c22d6f29

See more details on using hashes here.

File details

Details for the file libsegmenter-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: libsegmenter-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for libsegmenter-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 579a7ab4508eb90d665ce8d3bdda9c6a14e83c295b95a5f3c603bd06cb445928
MD5 09c708a31a8e7ee72eca1b71e88124d3
BLAKE2b-256 e203fea799098e465cdc428767e3e20d35d8fedbd34fb8cbf9cf91984474880e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page