如何使用音乐准备Midi文件以进入神经网络

我正在尝试处理一个midi文件,用它来喂入一个神经网络,但是我遇到了错误。

它应该产生输入旋律 在这里,我将“ Twinkle,Twinkle Little Star”旋律的MIDI版本转换为可被我们的网络消化的输入序列。

# Parse a MIDI file and extrac the notes.
twinkle_stream = music21.converter.parse("/content/drive/My Drive/Root_USP/RNA/style_transfer/midis/xmas_bk_xmas1.mid")
only_part = twinkle_stream.parts[0]
melody_notes = []
for the_note in only_part:
  if isinstance(the_note,music21.note.Note):
    melody_notes.append(the_note)

# Convert the notes in the melody to our vocab.
melody = []
for the_note in melody_notes:
  note_str = the_note.step + str(the_note.octave)
  index = pitchnames.index(note_str)
  melody.append(index)

melody = np.array(melody) / n_vocab
curr_ind = 0
while len(melody) < 100:
  melody = np.concatenate((melody,[melody[curr_ind]]))
  curr_ind += 1

print("Twinkle Length: {}".format(len(melody)))
print(melody)

结果应为:

[0.86871508 0.86871508 0.99162011 0.99162011 0.79608939 0.79608939
 0.99162011 0.95810056 0.95810056 0.92458101 0.92458101 0.88826816
 0.88826816 0.86871508 0.99162011 0.99162011 0.95810056 0.95810056
 0.92458101 0.92458101 0.88826816 0.99162011 0.99162011 0.95810056
 0.95810056 0.92458101 0.92458101 0.88826816 0.86871508 0.86871508
 0.99162011 0.99162011 0.79608939 0.79608939 0.99162011 0.95810056
 0.95810056 0.92458101 0.92458101 0.88826816 0.88826816 0.86871508
 0.86871508 0.86871508 0.99162011 0.99162011 0.79608939 0.79608939
 0.99162011 0.95810056 0.95810056 0.92458101 0.92458101 0.88826816
 0.88826816 0.86871508 0.99162011 0.99162011 0.95810056 0.95810056
 0.92458101 0.92458101 0.88826816 0.99162011 0.99162011 0.95810056
 0.95810056 0.92458101 0.92458101 0.88826816 0.86871508 0.86871508
 0.99162011 0.99162011 0.79608939 0.79608939 0.99162011 0.95810056
 0.95810056 0.92458101 0.92458101 0.88826816 0.88826816 0.86871508
 0.86871508 0.86871508 0.99162011 0.99162011 0.79608939 0.79608939
 0.99162011 0.95810056 0.95810056 0.92458101 0.92458101 0.88826816
 0.88826816 0.86871508 0.99162011 0.99162011]

错误如下:

IndexError                                Traceback (most recent call last)

<ipython-input-26-3309b98a56fc> in <module>()
     16 curr_ind = 0
     17 while len(melody) < 100:
---> 18   melody = np.concatenate((melody,[melody[curr_ind]]))
     19   curr_ind += 1
     20 

IndexError: index 0 is out of bounds for axis 0 with size 0

谢谢

leaved_poplar 回答:如何使用音乐准备Midi文件以进入神经网络

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3095779.html

大家都在问