Open ymm-youbaba opened 2 years ago
Hi! I faced the same error. It looks like some midi-files are corrupted or the encoding algorithm has a bug. For a while I solved this problem by moving the statement midi_fp.close()
near the place where the object was created.
if(os.path.isfile(midi_txt_name)):
midi_fp = open(midi_txt_name, "r")
encoded_midi = midi_fp.read()
midi_fp.close()
else:
# Create a music21 stream and open the midi file
midi = m21.midi.MidiFile()
midi.open(file_path)
midi.read()
midi.close()
# Translate midi to stream of notes and chords
encoded_midi = midi2encoding(midi, sample_freq, piano_range, transpose_range, stretching_range)
if len(encoded_midi) > 0:
midi_fp = open(midi_txt_name, "w+")
midi_fp.write(encoded_midi)
midi_fp.flush()
midi_fp.close()
Kinda works. But the reason for the error is not clear still.