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 1-dimensional 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 1D NumPy arrays.

Installation

PyPI version python 3.9, 3.10, 3.11, 3.12, 3.13 os: Linux, Windows

$ 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
reference = np.random.uniform(size=10_000).astype("float32")
delayed = np.pad(reference, (121, 0))[0:10_000]

# Find the best offset for aligning two arrays
offset, mse = fast_align_audio.find_best_alignment_offset(
    reference_signal=reference,
    delayed_signal=delayed,
    max_offset_samples=1000,
    lookahead_samples=5000,
)
print(offset)  # 121

negative_offset, mse2 = fast_align_audio.find_best_alignment_offset(
    reference_signal=reference,
    delayed_signal=reference[121:],
    max_offset_samples=1000,
    lookahead_samples=5000,
)
print(negative_offset)  # -121

# Align two arrays and confirm they're equal post alignment
aligned_audio, gaps = fast_align_audio.align_delayed_signal_with_reference(
    reference.shape[-1], delayed, offset=offset
)
print(np.array_equal(reference[500:600], aligned_audio[500:600]))  # True

In this example, we first create a random numpy array. We then call the find_best_alignment_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.

Tips

  • For more reliable alignments, filter out unwanted/unrelated sounds before passing the audio snippets to fast-align-audio. E.g. if you are aligning two speech recordings, you could band-pass filter and/or denoise them first.
  • This library assumes that the delay is fixed throughout the audio snippet. If you need something that aligns audio tracks in a dynamic way (e.g. due to distance between microphones changing over time), look elsewhere.
  • The "mse" method is sensitive to loudness differences. If you use this method, make sure the two input audio snippets have roughly the same loudness
  • This lib only works well for small offsets, like up to 500 ms, and suitable audio file durations, like for example between 3 and 45 seconds. If you have large audio files with large offsets between them, a different algorithm may be required to solve the problem well.

Changelog

[0.6.0] - 2025-06-28

Added

  • Add support for Python 3.13

For the complete changelog, go to CHANGELOG.md

Development

  • Install dev/build/test dependencies as denoted in setup.py
  • python setup.py develop
  • pytest

Acknowledgements

Original C implementation by jonashaag. Now maintained/backed by Nomono.

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

fast_align_audio-0.6.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distributions

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

fast_align_audio-0.6.0-cp313-cp313-win_amd64.whl (14.3 kB view details)

Uploaded CPython 3.13Windows x86-64

fast_align_audio-0.6.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.1 kB view details)

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

fast_align_audio-0.6.0-cp312-cp312-win_amd64.whl (14.3 kB view details)

Uploaded CPython 3.12Windows x86-64

fast_align_audio-0.6.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (21.2 kB view details)

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

fast_align_audio-0.6.0-cp311-cp311-win_amd64.whl (14.3 kB view details)

Uploaded CPython 3.11Windows x86-64

fast_align_audio-0.6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20.9 kB view details)

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

fast_align_audio-0.6.0-cp310-cp310-win_amd64.whl (14.3 kB view details)

Uploaded CPython 3.10Windows x86-64

fast_align_audio-0.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20.9 kB view details)

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

fast_align_audio-0.6.0-cp39-cp39-win_amd64.whl (14.3 kB view details)

Uploaded CPython 3.9Windows x86-64

fast_align_audio-0.6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (20.9 kB view details)

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

File details

Details for the file fast_align_audio-0.6.0.tar.gz.

File metadata

  • Download URL: fast_align_audio-0.6.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for fast_align_audio-0.6.0.tar.gz
Algorithm Hash digest
SHA256 ca48021e4b65de132ccaeac5fb13bbef0e0ce4ee285ae5c060c86ac502c1559b
MD5 210decae9c4e26946758fbecad78180c
BLAKE2b-256 8cf49deebd56258311c7bd6e3f62fbe9575ad6828fd42aadca02dc530a1d114f

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2a3ac7acb8919cadd0fde45f88218192f990b84819f9db3b1eacfb1709e9ef6a
MD5 be3d6be041b5acbad9550e5a1cebf811
BLAKE2b-256 3d711ce6583c1a26c611f58bf03986a23951b1efcc42c49270bcad7de7402eed

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0a948a0a937d1d8645c8dde638bc917c32189cb62636b1fb5b72f428733762ef
MD5 2f737b30e26b8ef7ff07fa0b18075356
BLAKE2b-256 1b24002fd337915f49b94bb627a7f3c2549a0f4ed778ba947c471d9a875995e5

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 799377ba756edbcdf4da8a478ad6102090a83d191e6713ab8b869d1afa2f6633
MD5 069e3ec326a7397a4db40d5115f4917d
BLAKE2b-256 f00f5347a0e0319edb414ab663721841c919e4719803babe24b8dc89d7d20716

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7a54a0bc251b8265f8346272ca5104b141ce96445b28d4b4d6647d2783e2299c
MD5 2c27cd263c7546f26f9bcb72b4b7e561
BLAKE2b-256 e5f2ff8cc8936523d46ee585c6f489142dbda14c4c35c5eb34ab583dcc6c14a5

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 89413548e6a1d22b3a21a822aabf9b39f46116ee31adfd7e9b62c22a64c06f22
MD5 5daf4272c86536c4380310ddaddc6a2f
BLAKE2b-256 4d07a1d33cf6e026a53412f42ab54d57c1e2c3242b65f5ea724cff9f263c69b0

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b3ca8db8f23b2a4912702c4792fab0d2b4092e848e574ed21deadc2f2b8e8d6
MD5 dfa0a7d7fc4349edab50a5698dfb64a8
BLAKE2b-256 ccca23b4a7753444577d33ec3e3a01fe3ca451586ce80c1946ea8b139d528aaa

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5801b6de4450a666e8bbb2e7e6d659490810946b13101d369c2a88f96ddaa41d
MD5 7e8ec4d15f9c46860876657281d179ce
BLAKE2b-256 dc5cc95ca080d7d3bc1742dcebed6df07622a58dc4f94a66a4367e32f9f5a58e

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29c4ab063801db9676fb1a464aa0316ee732fb40546ee700a8c2591f5c19891c
MD5 a9d510dc164899cf6e4b1dffdced88a8
BLAKE2b-256 36cc576a608b6a1d8cb2b4fa75ca5750fb56dc73097e2ea2bc0673a690498c5d

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f9cf21113e0bdda69459494452e6359301a45c0c9aab68588bce76aeb2de54e6
MD5 6a49eb8537987151b996ffb244cd94f8
BLAKE2b-256 b99ec01a329b19d721665e28e4a4651fbc995c09a433731eb3ea2886e75933c1

See more details on using hashes here.

File details

Details for the file fast_align_audio-0.6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fast_align_audio-0.6.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 deb87404b162248111984aa53916d0d5016987424886d0bcda3b44090c5a09ec
MD5 e5377998cbb4b639c13137d3ec2a3976
BLAKE2b-256 7bc700c40c06a76b4f6e0ed0be102c7fc22c7e44f2523b7f65275d8cf92146f5

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