![](/img/trans.png)
[英]How to make MIDI file from notes with Flute instrument in Python (music21 library)
[英]how to make music21 play a particular music instrument?
我已經訓練了一個使用 LSTM 生成音樂的神經網絡。 但它總是只從鋼琴返回音樂..我也嘗試過使用 instrument.Guitar() 方法。 它不起作用。 我只聽鋼琴曲。 為什么會發生這種情況? 任何建議都會有所幫助..這是我的代碼。
def convert_to_midi(prediction_output):
offset = 0
output_notes =[]
# create note and chord objects based on the values generated by the model
for pattern in prediction_output:
notes=[]
# pattern is a chord
if ('.' in pattern) or pattern.isdigit():
notes_in_chord = pattern.split('.')
for current_note in notes_in_chord:
cn=int(current_note)
new_note = note.Note(cn)
#new_note.storedInstrument = instrument.Guitar()
notes.append(new_note)
new_chord = chord.Chord(notes)
new_chord.offset = offset
output_notes.append(instrument.Violin())
output_notes.append(new_chord)
# pattern is a note
else:
new_note = note.Note(pattern)
new_note.offset = offset
#new_note.storedInstrument = instrument.Guitar()
output_notes.append(instrument.Violin())
output_notes.append(new_note)
# increase offset each iteration so that notes do not stack
offset += 1
#midi_stream1=stream.Score()
#midi_stream1.insert(output_notes)
#midi_stream = stream.Stream(output_notes)
#midi_stream.write('midi', fp='music11.mid')
#midi_stream1.write("midi", fp="music15.mid")
midi_stream = stream.Stream(output_notes)
midi_stream.write('midi', fp='final_music2.midi')
storedInstrument
屬性尚未提升為Note
對象,但可能會在music21
未來版本中music21
。 現在,嘗試在您需要更改 MIDI 程序的任何時候將一個instrument.Guitar
實例簡單地插入到Stream
對象中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.