字节跳动Piano transcription钢琴转录(Windows)使用详细教程

  1. 下载源码

    打开项目仓库,并将其git clone/下载到本地文件夹

    https://github.com/bytedance/piano_transcription
    
  2. 搭建编译环境

    阅读仓库README.md 文件,发现字节跳动是用Python 3.7和Pytorch 1.4.0搭建的项目

    下载地址:

    (1)Python 3.7: 不妨使用Python 3.7.9

    https://www.python.org/downloads/release/python-379/
    

    在这里插入图片描述

    安装时,记得在第一个页面勾选 ”Path“ 选项框

    (2)Pytorch 1.4.0: Python安装完毕后,打开cmd控制台,输入命令

    pip install torch===1.4.0 torchvision===0.5.0 -f https://download.pytorch.org/whl/torch_stable.html
    

    等待下载(可能速度会很慢,大概800M,建议科学上网)

  3. 安装依赖文件

    打开cmd控制台,将位置定位到…/piano_transcription,输入命令

    pip install -r requirements.txt
    

    这一步会将依赖都安装好

  4. 下载训练集

    打开训练集项目仓库,并将其git clone/下载到本地文件夹

    https://github.com/qiuqiangkong/piano_transcription_inference
    
  5. 安装训练集

    打开cmd控制台,将位置定位到…/piano_transcription_inference,输入命令

    pip install piano_transcription_inference
    

    等待安装完成

    注意:最后要操作mp3文件需要安装ffmpeg插件,具体可参考网址
    https://www.jianshu.com/p/6bae57859325
    
  6. 下载已有的训练模型

    进入网站,下载高分辨率钢琴转录系统的训练模型

    https://zenodo.org/record/4034264#.X7vAB2gzZPY
    

    在这里插入图片描述

    下载成功后,将文件改名为

    note_F1=0.9677_pedal_F1=0.9186.pth
    

    并放入特定文件夹

    C:\Users\lenovo\piano_transcription_inference_data
    
  7. 实现转录

    在cmd中将位置定位到…/piano_transcription_inference,输入命令

    python
    

    进入python模式后,依次输入命令

    from piano_transcription_inference import PianoTranscription, sample_rate, load_audio
    
    # Load audio, 'resources/cut_liszt.mp3' is the resource of your .mp3 file.
    (audio, _) = load_audio('resources/cut_liszt.mp3', sr=sample_rate, mono=True)  # 输入文件路径
    
    # Transcriptor
    transcriptor = PianoTranscription(device='cuda')    # 'cuda' | 'cpu'
    
    # Transcribe and write out to MIDI file, 'cut_liszt.mid' is the result of your .mid file
    transcribed_dict = transcriptor.transcribe(audio, 'cut_liszt.mid')  # 输出文件路径
    

    即可在…/piano_transcription_inference文件夹内找到转录成功的.mid文件

    注意:在Load andio这一步可能会有类似提示:‘wget’命令错误。可在网址下载wget.exe文件
    https://eternallybored.org/misc/wget/
    

    在这里插入图片描述

    然后放入C:\windows\system32目录下即可
  8. Python脚本实现多文件转录

    创建项目文件夹,包含4个文件:

    (1)装载待转录.mp3文件的文件夹

    (2)装载待生成.mid文件的文件夹

    (3)note.pth文件,是在6.中下载的训练模型,将它稍作改名

    (4)test.py文件,是Python脚本文件

在这里插入图片描述

test.py脚本代码及注释:

from piano_transcription_inference import PianoTranscription, sample_rate, load_audio
import os


def mp32mid(fp):
    # Load audio
    (audio, _) = load_audio(fp, sr=sample_rate, mono=True)
    print('loaded')
    # Transcriptor
    transcriptor = PianoTranscription(device='cuda', checkpoint_path='note.pth')  # 'cuda' | 'cpu'
    fname=fp.split('\\')[-1]
    print(fname+' is processing...')
    # Transcribe and write out to MIDI file
    transcribed_dict = transcriptor.transcribe(audio, 'mid/' + fname + '.mid')  # 设置输出路径(文件名)


def file_name(file_dir):
    l = []
    for root, dirs, files in os.walk(file_dir):
        for file in files:
            if os.path.splitext(file)[1] == '.mp3':  # 想要保存的文件格式
                l.append(os.path.join(root, file))
    return l

print('start')
for l in file_name('./mp3'):  # 设置输入路径(文件夹)
    print(l)
    mp32mid(l)
pass

打开cmd控制台,将位置定位到该项目文件夹,输入命令

python test.py

等待转录工作完成即可

测试下来,使用cuda转录速度较快(约1分钟一首),cpu较慢

  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值