find-delay

A Python package to calculate the delay between two arrays or two audio files

https://github.com/romainpastureau/find_delay

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.6%) to scientific vocabulary

Keywords

audio-processing delay lag module package pip python
Last synced: 6 months ago · JSON representation

Repository

A Python package to calculate the delay between two arrays or two audio files

Basic Info
Statistics
  • Stars: 8
  • Watchers: 2
  • Forks: 1
  • Open Issues: 1
  • Releases: 0
Topics
audio-processing delay lag module package pip python
Created almost 2 years ago · Last pushed 6 months ago
Metadata Files
Readme Contributing Funding License Code of conduct Citation Security

README.md

find_delay 2.18

Documentation Status

PyPI page

Author: Romain Pastureau

What is find_delay?

find_delay is a Python package that tries to find the delay where a time series appears in another via cross-correlation. It can theoretically work with any time series (see the examples in the demos folder, but was created to try to align audio files. Read the documentation here!

How to

The best way to use this function is to install the find_delay module for Python by running py -m pip install find-delay.

You can then import the function by writing from find_delay import find_delay (or from find_delay import find_delays if you want to locate multiple excerpts in one big time series).

You can also run demos/demo.py to get four examples (in that case, you will need to download the .wav files present in the repository and place them in the same folder for examples 3 and 4).

Quick use for audio files

To find when an excerpt starts in an audio file, use the find_delay function and fill only the first two parameters, by indicating the path to the corresponding WAV files; leave the other parameters default (just set plot_figure = True if you want to visualize the output of the function).

Specifics

The function accepts two arrays containing time series - the time series can be of different frequency or amplitude.

The function can then calculate the envelope of the time series (recommended for audio files) and apply a band-pass filter to the result.

The function can also resample the arrays (necessary when the two time series do not have the same frequency).

Finally, the function performs the cross-correlation between the two arrays.

The results can be then plotted if the corresponding parameters are activated, and the function returns the delay at which to find the second array in the first by selecting the delay with the maximum correlation value (optionally, the function can also return this correlation value).

Dependencies

  • Python >= 3.8 (>= 2019-10-14)
  • Numpy >= 1.16 (>= 2019-01-14) for handling the numerical arrays
  • Scipy >= 1.5 (>= 2020-19-21) for loading the WAV files, performing the resampling, calculating the envelope, and applying a band-pass filter.
  • Matplotlib >= 3.2 (>= 2020-04-03) for the plots

The indicated minimum versions are for ensuring environment compatibility with other modules - using the most updated versions of Python and the required modules is recommended as older versions may not be supported or be subject to vulnerabilities.

Examples

Delay between two numerical time series

```
array1 = [24, 70, 28, 59, 13, 97, 63, 30, 89, 4, 8, 15, 16, 23, 42, 37, 70, 18, 59, 48, 41, 83, 99, 6, 24, 86] array2 = [4, 8, 15, 16, 23, 42]

finddelay(array1, array2, computeenvelope=False, plotfigure=True, pathfigure="figure_1.png") ```

Delay between two numerical time series

Delay between a sine function and a portion of it, different frequencies

``` timestamps1 = np.linspace(0, np.pi * 2, 200001) array1 = np.sin(timestamps1) timestamps2 = np.linspace(np.pi * 0.5, np.pi * 0.75, 6001) array2 = np.sin(timestamps2)

finddelay(array1, array2, 100000 / np.pi, 6000 / (np.pi / 4), computeenvelope=False, resamplingrate=1000, windowsizeres=20000, overlapratiores=0.5, resamplingmode="cubic", plotfigure=True, pathfigure="figure2.png", plotintermediate_steps=True) ```

Delay between a sine function and a portion of it, different frequencies

Delay between an audio file and an excerpt from it

find_delay("i_have_a_dream_full_speech.wav", "i_have_a_dream_excerpt.wav", return_delay_format="timedelta", mono_channel=0, plot_figure=True, path_figure="figure_3.png", plot_intermediate_steps=True)

Delay between an audio file and an excerpt from it

Find more examples here!

Latest version

2.18 (2025-06-29)

  • Corrected a bug where passing "average" for the parameter mono_channel would return an error if one of the files was mono.
  • Corrected a bug that did not display properly the cross-correlation peak when using min_delay or max_delay.
  • The parameter return_delay_format can now be set interchangeably between "index" or "sample".
  • Added a new parameter return_none_if_below_threshold.
  • The parameter return_correlation_value can now be set on "array". In that case, an 2-dimensional array of all the correlation values and their corresponding timestamps or indices is returned.
  • Added new tests.

See version history

If you detect any bug, please open an issue.

Thanks!

Buy Me A Coffee

Owner

  • Login: RomainPastureau
  • Kind: user

GitHub Events

Total
  • Create event: 5
  • Release event: 6
  • Issues event: 9
  • Watch event: 3
  • Delete event: 1
  • Issue comment event: 7
  • Push event: 25
  • Fork event: 1
Last Year
  • Create event: 5
  • Release event: 6
  • Issues event: 9
  • Watch event: 3
  • Delete event: 1
  • Issue comment event: 7
  • Push event: 25
  • Fork event: 1

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 2
  • Total pull requests: 0
  • Average time to close issues: about 1 month
  • Average time to close pull requests: N/A
  • Total issue authors: 2
  • Total pull request authors: 0
  • Average comments per issue: 0.5
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 0
  • Average time to close issues: about 1 month
  • Average time to close pull requests: N/A
  • Issue authors: 2
  • Pull request authors: 0
  • Average comments per issue: 0.5
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • denkorz (2)
  • csu-roycheng (1)
  • TomasLenc (1)
  • asapsmc (1)
  • RomainPastureau (1)
Pull Request Authors
  • RomainPastureau (1)
Top Labels
Issue Labels
enhancement (3) bug (3) critical (1) waiting for feedback (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 3,078 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 15
  • Total maintainers: 1
pypi.org: find-delay

Calculate the delay between two arrays

  • Versions: 15
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 3,078 Last month
Rankings
Dependent packages count: 9.4%
Average: 35.8%
Dependent repos count: 62.2%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/main.yml actions
  • codecov/codecov-action v4.0.1 composite
docs/source/requirements.txt pypi
  • matplotlib >=3.7
  • numpy >=1.25.0
  • scipy >=1.11.0
  • sphinx ==7.0.1
  • sphinx-autodoc-typehints ==1.24.0
  • sphinx-copybutton ==0.5.2
  • sphinx-tabs ==3.4.4
  • sphinx_rtd_theme ==1.3.0
pyproject.toml pypi
  • matplotlib >= 3.7
  • numpy >= 1.25.0
  • scipy >= 1.11.0
requirements.txt pypi
  • matplotlib >=3.7
  • numpy >=1.25.0
  • scipy >=1.11.0
setup.py pypi