GithubHelp home page GithubHelp logo

fcpe's Introduction

TorchFCPE

Useage

from torchfcpe import spawn_bundled_infer_model
import torch
import librosa

# configure device and target hop_size
device = 'cpu'
sr = 16000
hop_size = 160

# load 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 model
model = spawn_bundled_infer_model(device=device)

# infer
'''
audio: wav, torch.Tensor
sr: sample rate
decoder_mode: [Optional] 'local_argmax' is recommended
threshold: [Optional] threshold for V/UV decision, 0.006 is recommended
f0_min: [Optional] minimum f0
f0_max: [Optional] maximum f0
interp_uv: [Optional] whether to interpolate unvoiced frames
output_interp_target_length: [Optional] If not None, the output f0 will be
    interpolated to the target length
'''
f0 = model.infer(
    audio,
    sr=sr,
    decoder_mode='local_argmax',
    threshold=0.006,
    f0_min=80,
    f0_max=880,
    interp_uv=False,
    output_interp_target_length=f0_target_length,
)

print(f0)

''' MIDI Extract '''
'''
audio: wav, torch.Tensor
sr: sample rate
decoder_mode: [Optional] 'local_argmax' is recommended
threshold: [Optional] threshold for V/UV decision, 0.006 is recommended
f0_min: [Optional] minimum f0
f0_max: [Optional] maximum f0
output_path: [Optional] If input, save midi; otherwise, only return midi structure
tempo: [Optional] BPM, if None, Automatic prediction of bpm
'''

midi = model.extact_midi(
    audio,
    sr=sr,
    decoder_mode='local_argmax',
    threshold=0.006,
    f0_min=80,
    f0_max=880,
    output_path="test.mid"
)

print(midi)


# the model is son class of torch.nn.Module, so you can use it as a normal pytorch model
# example: change device
model = model.to(device)
# example: compile model
model = torch.compile(model)

fcpe's People

Contributors

cnchtu avatar ylzz1997 avatar qiuqiao avatar tps-f avatar soulmelody avatar narusemioshirakana avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.