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.
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 df0pip install df0-pitchTo also install the dependencies required to run the demo notebook:
pip install "df0-pitch[demo]"git clone https://github.com/groupmm/df0.git
cd df0
pip install -e .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.
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.wavTo get the predictions for all .wav files in dir_audio/, use:
dswipe dir_audio/*.wavBy 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_csvUse 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
...We provide automated tests for each algorithm. To run them:
pip install "df0-pitch[test]"
pytestAutomated code style checks via pre-commit:
pip install pre-commit
pre-commit install
pre-commit run --all-filesThe code for this toolbox is published under an MIT license.
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.