Skip to main content

Python package with Pytorch implementations of differentiable variants of classical fundamental frequency estimators (dYIN and dSWIPE)

Project description

df0: Differentiable Variants of Classical Fundamental Frequency Estimators

PyPI version tests License: MIT

This is a Python package containing Pytorch implementations of differentiable variants of classical fundamental frequency estimators (dYIN and dSWIPE). This code accompanies the following paper:

@article{StrahlM25_df0_TASLPRO,
  author  = {Sebastian Strahl and Meinard M{\"u}ller},
  title   = {{dYIN} and {dSWIPE}: {D}ifferentiable Variants of Classical Fundamental Frequency Estimators},
  journal = {{IEEE/ACM} Transactions on Audio, Speech, and Language Processing},
  volume  = {33},
  pages   = {2622--2633},
  year    = {2025},
  doi     = {10.1109/TASLPRO.2025.3581119}
}

For details and references, please check out this paper.

Installation

1. Set up Python environment

We recommend setting up a Python environment including Pytorch before installing df0. You may use the example environment provided as part of this package:

git clone https://github.com/groupmm/df0.git
cd df0
conda env create -f environment.yaml
conda activate df0

2. Install df0

Option 1: Install from PyPI

pip install df0-pitch

To also install the dependencies required to run the demo notebook:

pip install "df0-pitch[demo]"

Option 2: Install by cloning this repository (for development)

git clone https://github.com/groupmm/df0.git
cd df0
pip install -e .

Usage

Python

import torch
import librosa
from df0.dyin import dYIN
from df0.dswipe import dSWIPE

x, fs = librosa.load("audio.wav", sr=16000)
x = torch.from_numpy(x)

dyin = dYIN(fs=fs, hop_size=160)
f0_hz = dyin(x)["f0_hz"]  # shape: (n_frames,)

dswipe = dSWIPE(fs=fs, hop_size=160)
f0_hz = dswipe(x)["f0_hz"]  # shape: (n_frames,)

For more details, see demo.ipynb.

Command-line interface

To get the F0 predictions for an audio file, you can use the command-line interface, running one of the following commands in a terminal:

dswipe audio.wav
dyin audio.wav

To get the predictions for all .wav files in dir_audio/, use:

dswipe dir_audio/*.wav

By running these commands, the F0 predictions are stored as .csv files in a folder specified by the command-line argument dir_out (default: f0_csv). Example usage:

dswipe dir_audio/*.wav --dir_out f0_dswipe_csv

Use dswipe -h or dyin -h for an overview of available command-line options.

The output format of our methods is similar to that of CREPE and PESTO, except that there is no confidence:

time,frequency
0.000,63.544
0.010,651.683
0.020,655.458
0.030,651.683
0.040,666.915
0.050,678.573
...

Tests

We provide automated tests for each algorithm. To run them:

pip install "df0-pitch[test]"
pytest

Contribution

Automated code style checks via pre-commit:

pip install pre-commit
pre-commit install
pre-commit run --all-files

License

The code for this toolbox is published under an MIT license.

Acknowledgements

This work was funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Grant No. 500643750 (MU 2686/15-1). The authors are with the International Audio Laboratories Erlangen, a joint institution of the Friedrich-Alexander-Universität Erlangen-Nürnberg (FAU) and Fraunhofer Institute for Integrated Circuits IIS.

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

df0_pitch-1.0.1.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

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

df0_pitch-1.0.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file df0_pitch-1.0.1.tar.gz.

File metadata

  • Download URL: df0_pitch-1.0.1.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for df0_pitch-1.0.1.tar.gz
Algorithm Hash digest
SHA256 08c6f95ed5e9dd54d58c451c0bc76a96e5a7bbc974212b65a34094101aabd544
MD5 b689c0691c27084e68fd55a8749e87a8
BLAKE2b-256 ec2028f25837e0d713ac76d8dfffd3a9b22bafd7fc468d35a561c7f9c4b4197f

See more details on using hashes here.

Provenance

The following attestation bundles were made for df0_pitch-1.0.1.tar.gz:

Publisher: publish_pypi.yml on groupmm/df0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file df0_pitch-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: df0_pitch-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for df0_pitch-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aae383b3db3995afab404b7db4ade34d5b62ac240999e2b63f8493e9d1808dcb
MD5 0762f6ea9bc633d4416d3351073a504f
BLAKE2b-256 9ef28b10f96af12e36a841642e8970246a2611d204ba5f7b1abd432cd7cef853

See more details on using hashes here.

Provenance

The following attestation bundles were made for df0_pitch-1.0.1-py3-none-any.whl:

Publisher: publish_pypi.yml on groupmm/df0

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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