f0curve

maelzel.snd.freqestimate.f0curve(sig, sr, minfreq=60, overlap=4, method='pyin', unvoicedFreqs='nan')[source]

Estimate the fundamental and its voicedness

The voicedness curve indicates how accurate the frequency reading is. The value should drop whenever the signal is either too low (during silences) or it turns noisy (during consonants in the case of speech)

This function combines all frequency estimation algorithms into one interface. For more detailed access to parameters of each method use the specific function (pyin vamp: f0curvePyinVamp(); pyin native: f0curvePyin(), etc)

Both the f0 curve and the voicedness curve are returned as bpfs. See https://bpf4.readthedocs.io for more information about bpfs

Parameters:
  • sig (ndarray) – the signal, a 1D float numpy array with samples between -1:1

  • sr (int) – the sr

  • minfreq – the min. frequency of the fundamental. Using this hint we estimate the best value for fft size / window size

  • overlap – the amount of overlap between analysis windows

  • method – the method used. One of ‘pyin’, ‘fft’, ‘hps’, ‘autocorrelation’. For pyin make sure that you are using the vamp plugin, since the fallback version (using an implementation based on librosa’s version of the algorithm) is very slow at the moment. If the vamp plugin is not available you should see a warning

  • unvoicedFreqs – (only relevant for method ‘pyin’). One of ‘nan’, ‘negative’. If ‘nan’ unvoiced frequencies (frequencies for segments where the f0 confidence is too low) are given as nan. If ‘negative’ unvoiced freqs are given as negative.

Return type:

tuple[BpfInterface, BpfInterface]

Returns:

a tuple (f0curve, f0voicedness)

Example

from maelzel.snd.audiosample import Sample
from maelzel.snd import freqestimate
samp = Sample("snd/finneganswake-fragm01.flac").getChannel(0, contiguous=True)
freq, voiced = freqestimate.f0curve(sig=samp.samples, sr=samp.sr, method='pyin')
freq.plot(figsize=(18, 6))
../_images/snd-freqestimate-f0curve.png

For a more in-depth example see notebooks/analysis-pyin.ipynb