ITADN
CNChTu/FCPE
CNChTu/FCPE · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

TorchFCPE

arXiv 

概述

TorchFCPE(Fast Context-based Pitch Estimation)是一个基于 PyTorch 的库,专为音频音高提取和 MIDI 转换而设计。本 README 提供了如何使用该库进行音频音高推理和 MIDI 提取的快速指南。

注意:FCPE 的 MIDI 提取器使用非神经网络方法从 f0 进行量化

注意:我短期内不会更新 FCPE(或基准测试),但我肯定会发布一个代码经过清理的版本,最迟不会晚于明年。

安装

在使用该库之前,请确保已安装必要的依赖项:

pip install torchfcpe

用法

1. 音频音高推断

from torchfcpe import spawn_bundled_infer_model
import torch
import librosa

# Configure device and target hop size
device = 'cpu'  # or 'cuda' if using a GPU
sr = 16000  # Sample rate
hop_size = 160  # Hop size for processing

# Load and preprocess audio
audio, sr = librosa.load('test.wav', sr=sr)
audio = librosa.to_mono(audio)
audio_length = len(audio)
f0_target_length = (audio_length // hop_size) + 1
audio = torch.from_numpy(audio).float().unsqueeze(0).unsqueeze(-1).to(device)

# Load the model
model = spawn_bundled_infer_model(device=device)

# Perform pitch inference
f0 = model.infer(
    audio,
    sr=sr,
    decoder_mode='local_argmax',  # Recommended mode
    threshold=0.006,  # Threshold for V/UV decision
    f0_min=80,  # Minimum pitch
    f0_max=880,  # Maximum pitch
    interp_uv=False,  # Interpolate unvoiced frames
    output_interp_target_length=f0_target_length,  # Interpolate to target length
)

print(f0)

2. MIDI 提取

# Extract MIDI from audio
midi = model.extact_midi(
    audio,
    sr=sr,
    decoder_mode='local_argmax',  # Recommended mode
    threshold=0.006,  # Threshold for V/UV decision
    f0_min=80,  # Minimum pitch
    f0_max=880,  # Maximum pitch
    output_path="test.mid",  # Save MIDI to file
)

print(midi)

备注

  • 推理参数:

    • audio:作为 torch.Tensor 的输入音频。
    • sr:音频的采样率。
    • decoder_mode(可选):解码模式,推荐 'local_argmax'。
    • threshold(可选):有声/无声判定的阈值;默认为 0.006。
    • f0_min(可选):最小音高值;默认为 80 Hz。
    • f0_max(可选):最大音高值;默认为 880 Hz。
    • interp_uv(可选):是否对无声帧进行插值;默认为 False。
    • output_interp_target_length(可选):输出音高应插值到的长度。
  • MIDI 提取参数:

    • audio:作为 torch.Tensor 的输入音频。
    • sr:音频的采样率。
    • decoder_mode(可选):解码模式;推荐 'local_argmax'。
    • threshold(可选):有声/无声判定的阈值;默认为 0.006。
    • f0_min(可选):最小音高值;默认为 80 Hz。
    • f0_max(可选):最大音高值;默认为 880 Hz。
    • output_path(可选):保存 MIDI 文件的文件路径。如果未提供,则仅返回 MIDI 结构。
    • tempo(可选):MIDI 文件的 BPM。如果为 None,则自动预测 BPM。

附加功能

  • 作为 PyTorch 模块使用: 您可以将该模型作为标准的 PyTorch 模块使用。例如:

    # Change device
    model = model.to(device)
    
    # Compile model
    model = torch.compile(model)

论文

如果您觉得我们的工作有用,请考虑引用该论文:

@misc{luo2025fcpefastcontextbasedpitch,
      title={FCPE: A Fast Context-based Pitch Estimation Model}, 
      author={Yuxin Luo and Ruoyi Zhang and Lu-Chuan Liu and Tianyu Li and Hangyu Liu},
      year={2025},
      eprint={2509.15140},
      archivePrefix={arXiv},
      primaryClass={cs.SD},
      url={https://arxiv.org/abs/2509.15140}, 
}

重要细节

我们在论文中使用的模型是 DDSP-200K,您可以从这里获取该模型:DDSP-200K Model.

还有一个更早发布的模型,您可以从这里获取 FCPE-Previous.

有关实验的更多信息将在论文被接受或拒绝后发布。