Pythonで使える基本周波数(ピッチ)抽出ツール

並べてみるとこんな感じ:

抽出方法(CREPE と FCNF0++ を除く):

import librosa
import parselmouth
import pyreaper
import pysptk
import pyworld as pw

filename = "./hoge.wav"

sr = 48000 # Hz
frame_length = 2048 # point
frame_period = 5  # msec
hop_length = int(fs * (frame_period / 1000)) # point
fmin, fmax = librosa.note_to_hz("C3"), librosa.note_to_hz("C5")

y, _ = librosa.load(filename, sr=sr)

f0_rapt = pysptk.sptk.rapt(y.astype(np.float32), sr, hop_length, fmin, fmax)
f0_swipe = pysptk.sptk.swipe(y.astype(np.float32), sr, hop_length, fmin, fmax)
f0_pyin, _, _ = librosa.pyin(
    y=y, fmin=fmin, fmax=fmax, sr=sr, frame_length=frame_length, hop_length=hop_length
)
f0_dio, _ = pw.dio(y.astype(np.float64), sr, frame_period=frame_period)
f0_harvest, _ = pw.harvest(y.astype(np.float64), sr, frame_period=frame_period)
f0_praat = parselmouth.Sound(y, sr).to_pitch().selected_array["frequency"]

x = (np.iinfo(np.int16).max * y).astype(np.int16)
_, _, _, f0_reaper, _ = pyreaper.reaper(
    x, sr, fmin, fmax, frame_period=frame_period / 1000
)

CREPE と FCNF0++ は MacOS 26.4.1, Python 3.14 ではうまくインストールできなかった.Tensorflow が Python 3.14 非対応という点は大きい.