代码(by 字节跳动孔大佬):
https://github.com/qiuqiangkong/piano_transcription_inference
使用:
1.安装package
pip install piano_transcription_inference
2.下载预训练模型
https://zenodo.org/record/4034264
3.运行代码
from piano_transcription_inference import PianoTranscription, sample_rate, load_audio# Load audio
(audio, _) = load_audio('piano.wav', sr=sample_rate, mono=True)# Transcriptor
transcriptor = PianoTranscription(device='cpu', checkpoint_path='CRNN_note_F1=0.9677_pedal_F1=0.9186.pth') # device: 'cuda' | 'cpu'# Transcribe and write out to MIDI file
transcribed_dict = transcriptor.transcribe(audio, 'cut_liszt.mid')
D:\python\Environment\Scripts\python.exe D:/pycharm_profession/Projects-professional/b20_summarization/钢琴转midi.py
Checkpoint path: CRNN_note_F1=0.9677_pedal_F1=0.9186.pth
Using cpu for inference.
Using CPU.
Segment 0 / 61
Segment 1 / 61
Segment 2 / 61
…
Segment 61 / 61
Write out to cut_liszt.mid
Process finished with exit code 0