Skip to main content

A fast python library for aligning similar audio snippets passed in as NumPy arrays.

Project description

fast-align-audio: high-speed NumPy audio alignment

fast-align-audio is designed to swiftly align two similar NumPy arrays — a common need in various fields including audio signal processing. If you have two arrays where one "lags behind" the other due to factors such as different capture sensors (microphones), propagation delays, or post-processing like reverberation or MP3 compression, fast-align-audio is here to help.

The package employs a "brute force" alignment approach, leveraging a C-based algorithm for maximum speed while providing a user-friendly Python API for easy integration.

While this library was initially developed with audio ndarrays in mind, it could also be used to align other kinds of time-series data that are represented as NumPy arrays.

Installation

$ pip install fast-align-audio

Usage

Here is a basic usage example:

import fast_align_audio
import numpy as np

# Create a random NumPy array
arr = np.random.uniform(size=10_000).astype("float32")

# Find the best offset for aligning two arrays
print(fast_align_audio.best_offset(arr, np.pad(arr, (121, 0)), 1_000, 5_000))
# Output: -121

print(fast_align_audio.best_offset(arr, arr[121:], 1_000, 5_000))
# Output: 121

# Align two arrays and confirm they're equal post alignment
arr1, arr2 = fast_align_audio.align(arr, np.pad(arr, (121, 0)), 1_000, 5_000, align_mode="crop")
np.array_equal(arr, arr1) and np.array_equal(arr, arr2)
# Output: True

In this example, we first create a random numpy array. We then call the best_offset method to find the best offset to align two arrays, and we use the align method to align the arrays. The np.array_equal method checks if two arrays are equal, demonstrating the successful alignment of the two original arrays.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

fast_align_audio-0.1.2-pp39-pypy39_pp73-win_amd64.whl (10.7 kB view hashes)

Uploaded PyPy Windows x86-64

fast_align_audio-0.1.2-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

fast_align_audio-0.1.2-pp38-pypy38_pp73-win_amd64.whl (10.7 kB view hashes)

Uploaded PyPy Windows x86-64

fast_align_audio-0.1.2-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

fast_align_audio-0.1.2-pp37-pypy37_pp73-win_amd64.whl (10.7 kB view hashes)

Uploaded PyPy Windows x86-64

fast_align_audio-0.1.2-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

fast_align_audio-0.1.2-cp311-cp311-musllinux_1_1_x86_64.whl (20.3 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

fast_align_audio-0.1.2-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

fast_align_audio-0.1.2-cp310-cp310-musllinux_1_1_x86_64.whl (20.3 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

fast_align_audio-0.1.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

fast_align_audio-0.1.2-cp39-cp39-win_amd64.whl (11.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

fast_align_audio-0.1.2-cp39-cp39-musllinux_1_1_x86_64.whl (20.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

fast_align_audio-0.1.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

fast_align_audio-0.1.2-cp38-cp38-win_amd64.whl (11.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

fast_align_audio-0.1.2-cp38-cp38-musllinux_1_1_x86_64.whl (20.7 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

fast_align_audio-0.1.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

Supported by

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