gpt4 book ai didi

python - 在 python (numpy) 中将 MIDI 文件转录为钢琴卷轴

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:17 24 4
gpt4 key购买 nike

以下网页http://www-etud.iro.umontreal.ca/~boulanni/icml2012提到可以在 python 中将 MIDI 文件转换为钢琴卷轴:

Below are the source files (MIDI) for the 4 datasets evaluated in the paper (split in train, validation and test sets). You can generate piano-rolls from the source files by transposing each sequence in C major or C minor and sampling frames every eighth note (quarter note for JSB chorales) following the beat information present in the MIDI file. Alternatively, pickled piano-rolls for use with the Python language are also provided.

他们已经做了几个例子。我想知道如何做到这一点,但我在他们的代码库中找不到完成此操作的任何地方。有没有简单的方法可以做到这一点?

所以我从 How to convert midi files to keypresses (in Python)? 知道我能做到的

import midi
midi.read_midifile('example.mid')

这将返回给我类似的模式

midi.Pattern(format=1, resolution=220, tracks=\
[midi.Track(\
[midi.NoteOnEvent(tick=0, channel=0, data=[43, 20]),
midi.NoteOffEvent(tick=100, channel=0, data=[43, 0]),
midi.EndOfTrackEvent(tick=1, data=[])])])

但是我该如何将音序转调为 C 大调或小调,以及如何每隔八个音符对帧进行采样呢?

因此,在上面引用的代码中,它们是这样做的:

from midi.utils import midiread, midiwrite
midiread(midi_file, (21, 109), 0.3).piano_roll

那么我的问题就变成了,在哪里可以找到那些 midi.utils 以及如何确保序列以正确的键转置并以正确的速率采样?

最佳答案

看来他们有原始 midi 库 ( https://github.com/vishnubob/python-midi ) 的修改版本,用于创建钢琴卷帘。代码的修改版本可以在这里找到:http://www.iro.umontreal.ca/~lisa/deep/midi.zip

关于python - 在 python (numpy) 中将 MIDI 文件转录为钢琴卷轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43347599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com