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
$ 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, 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.
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 Distributions
Built Distributions
Hashes for fast_align_audio-0.3.0-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08304d6bdeba77ebeae2c464819aa2e87091c9c1a12b4d3031f68c7e52e1369a |
|
MD5 | 4bd9be3af928f8fe07101444b684951a |
|
BLAKE2b-256 | c84bc6ba5b81462bbc2587ef8926a3cbe718b545b7c12da25af32c345db4c7ae |
Hashes for fast_align_audio-0.3.0-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f77d20745a2c7882959e396d8474318056c610fc58362e92c45227809319402b |
|
MD5 | 4fdb232396ddc639e2bec34a225d45dd |
|
BLAKE2b-256 | 539513d039102a32758f842efe196781e59f5e7b3a121d29da1db6775bf089bb |
Hashes for fast_align_audio-0.3.0-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9f5335b17dbc9b403a7cbd463b65bd0b95370b24043291fd736f9d948757765 |
|
MD5 | d4df058d227a2ea3a511a535f3d4465d |
|
BLAKE2b-256 | 346330e798e7e1b5eef5a6725a2c783f80ada5a8079e990746620899652ca032 |
Hashes for fast_align_audio-0.3.0-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3cb1e190dbe0ab91ac9df3ee3d7da74f5190d70369ad447da92486c34601669 |
|
MD5 | f9ad358a642f996ddd6847edf847d086 |
|
BLAKE2b-256 | e5380e72ae0113e478767c8a3afec996081f01169ec4d850fceec12fe64e9cee |
Hashes for fast_align_audio-0.3.0-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5ad915d8eaedfc7026b08671ffd8bca023b4cc8087beeeea368a486a7f1a3c9 |
|
MD5 | 00331e6679a779a5b759791c5b4713f8 |
|
BLAKE2b-256 | 0876035c9e6d0076f48089809e47973ccd97d88d258ec27778084cdafe03423f |
Hashes for fast_align_audio-0.3.0-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 162fd585565232c269cde0d9ab7964ac1334d0df7b1a7dfe75adac305b528832 |
|
MD5 | aae51800516f7da9d9d897fd6cd6c85f |
|
BLAKE2b-256 | 27cf553bba81b492445fcc492a420adfcf8c123af7341227ee0be59709def4a9 |
Hashes for fast_align_audio-0.3.0-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2c8a3ebe9a5dfd8bc6ad6b937045705edbc22609f1f840a1c4e7492cf774f9b |
|
MD5 | 4aec931fb5a0d2ecf621249516306dab |
|
BLAKE2b-256 | da567bdadefd459bf123d11d8c0627be86b1ee8c5298c5ee0c07c44683549bac |
Hashes for fast_align_audio-0.3.0-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25a772e35f4185672748139f0d3f61f5d1aca9648aa058fb6531faf11e4a0f2e |
|
MD5 | 6d5d14ffbf3ed64937405a65a7cc639e |
|
BLAKE2b-256 | e82f0f932ec4023cb508c2816299ca5f6921924fc51f0e055a44dab952108cea |
Hashes for fast_align_audio-0.3.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90fc40103c1bcc039a57af61d422eeba67a7b1681cd7d558c2f5d4b9915bf379 |
|
MD5 | aca897a927a8b85ae9875ee1a5fad6a2 |
|
BLAKE2b-256 | e4e7e14b38ff35b95493d81e94af8a33c2ce54079a0d3a4ce6a6875a51a8cc1b |
Hashes for fast_align_audio-0.3.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b80bcf5a77d56edb604abca3379d56ad53f65b686b03f0c944c94606e97cdb4 |
|
MD5 | 52b1705c8f66b9be6e61beada5980234 |
|
BLAKE2b-256 | fb636809a5c1246b3652424c08c8af8d0274e4f87d120b94a6058b6f70a5eb6a |
Hashes for fast_align_audio-0.3.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c5ffc1feb75206183d6e8b7de7b83db906954de1d3158ee47999fc0d380056b |
|
MD5 | 54b476b4c58957e2380b71b9e2280e05 |
|
BLAKE2b-256 | 3df473aa65dee9f91a0ac65f72f1a961aef881bae269ba2d78f70cbe624226dc |
Hashes for fast_align_audio-0.3.0-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40e98f33f8258909d188de0729f7bd3c89f84629cfe6e0ebf710baf86e8f518a |
|
MD5 | 3a15074c655f9a0a30662ab160dae9b7 |
|
BLAKE2b-256 | 5ec806f811518d7b7b9ae6517bb964b6539e1a54edb84ecaf74f93cf4b6dfaf4 |
Hashes for fast_align_audio-0.3.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 387749a3540675e01628618e6d2012a620baf03200448fb72df5613f88226bff |
|
MD5 | 5e4f7e69c9c0d05d652e83970895473b |
|
BLAKE2b-256 | b49f0bd892656ce60ec2a60269ac972fc32b58f96eb1af20ab54d6cf5f9e4aa8 |
Hashes for fast_align_audio-0.3.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f37bb9c18bbbaa420315e119d9be9c1b0922a1d493c630670645a8eaf09082a |
|
MD5 | 2978ecf66ac8f6f79a55439cf43516d0 |
|
BLAKE2b-256 | 9bbadb857609356abb46db474b6411b5d922fb702ed10f2b12ebe424569782c6 |
Hashes for fast_align_audio-0.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2370d1ba8cb2b4ff509e30771c87213c3cd2be776496a1aed24dfc4b8016e54f |
|
MD5 | 2a1359fe11f02f38a53896bd6e9182db |
|
BLAKE2b-256 | 1e3eb4ec3006dbe2cb06d72858746c21eba2d6af1622c564f9f01edb08a78a3d |
Hashes for fast_align_audio-0.3.0-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e87e1e4f0bb3aa00d03904b834666f8b4235fab054b3c1418bbf785ecab3858 |
|
MD5 | 7b3494e33a578bbe6eadf0d02fc43287 |
|
BLAKE2b-256 | cc9c5e849538f55d6e22a09cb94b9aebfc4cd0be0b068fb6188a5bd0060e406b |
Hashes for fast_align_audio-0.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 387551df0efe44f9796f7a9523057c9f9f94730fd7a48fc3bebd2a73fa5c4197 |
|
MD5 | 4c0a123c0f38a09c4b70ce78c145152d |
|
BLAKE2b-256 | 9609de1880a6ee8103359527b10e8f3a85cf09733ede8858bbf7c724cb829f06 |
Hashes for fast_align_audio-0.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 388a738cf998fb45c5bc6b101ca3c82dc37a21e986e65a333d0f514f3ef8b588 |
|
MD5 | 6018acc0ed0b9bec88db8b50e872f5f9 |
|
BLAKE2b-256 | ef8cd0ebf09fc8708263d355bdfdf96f310ba42fa1b69aa34e624e07336b8d01 |
Hashes for fast_align_audio-0.3.0-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 581186cfb798573d2538eec2c02640e621b49df8007bd768d44bdffa3ab17202 |
|
MD5 | 09d88be105e0151dc79f2e05ae47732e |
|
BLAKE2b-256 | 43e53f763541f78c739b3cfa6ca3b5d26d7d24201bc4d39dead421785f9d65d1 |
Hashes for fast_align_audio-0.3.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c71f72f5854e5b9d474644bccb36158e6b7952b2896d319db221715d663eb2a |
|
MD5 | 86040e3beaf115edb493ca232ea71a36 |
|
BLAKE2b-256 | bcd9bb378350f8f0efbd21c447609d711d99e50b58374dcc054f0ef55b6e9553 |