Hello,
I am following the tutorial on this article
The problem is that when we enter the code in the tutorial :
#library for understanding music
from music21 import *
#defining function to read MIDI files
def read_midi(file):print("Loading Music File:",file) notes=[] notes_to_parse = None #parsing a midi file midi = converter.parse(file) #grouping based on different instruments s2 = instrument.partitionByInstrument(midi) #Looping over all the instruments for part in s2.parts: #select elements of only piano if 'Piano' in str(part): notes_to_parse = part.recurse() #finding whether a particular element is note or a chord for element in notes_to_parse: #note if isinstance(element, note.Note): notes.append(str(element.pitch)) #chord elif isinstance(element, chord.Chord): notes.append('.'.join(str(n) for n in element.normalOrder)) return np.array(notes)#for listing down the file names
import os#Array Processing
import numpy as np#specify the path
path=‘schubert/’#read all the filenames
files=[i for i in os.listdir(path) if i.endswith(".mid")]#reading each midi file
notes_array = np.array([read_midi(path+i) for i in files])
I have this error (note that line 41 is the last line) :
Loading Music File: /Users/aydinabiar/Desktop/schubert/schumm-1.mid
Traceback (most recent call last):
File “/Users/aydinabiar/hello/.vscode/test 2.py”, line 41, in
notes_array = np.array([read_midi(path+i) for i in files])
File “/Users/aydinabiar/hello/.vscode/test 2.py”, line 41, in
notes_array = np.array([read_midi(path+i) for i in files])
File “/Users/aydinabiar/hello/.vscode/test 2.py”, line 10, in read_midi
midi = converter.parse(file)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/converter/init.py”, line 1137, in parse
return parseFile(valueStr, number=number, format=m21Format,
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/converter/init.py”, line 1010, in parseFile
v.parseFile(fp, number=number, format=format, forceSource=forceSource, **keywords)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/converter/init.py”, line 551, in parseFile
self.parseFileNoPickle(fp, number, format, forceSource, **keywords)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/converter/init.py”, line 485, in parseFileNoPickle
self.subConverter.parseFile(fp, number=number, **keywords)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/converter/subConverters.py”, line 1048, in parseFile
midiTranslate.midiFilePathToStream(fp, self.stream, **keywords)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/midi/translate.py”, line 2151, in midiFilePathToStream
return midiFileToStream(mf, inputM21, **keywords)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/midi/translate.py”, line 2311, in midiFileToStream
midiTracksToStreams(mf.tracks,
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/midi/translate.py”, line 2050, in midiTracksToStreams
midiTrackToStream(mt,
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/midi/translate.py”, line 1657, in midiTrackToStream
metaEvents = getMetaEvents(events)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/midi/translate.py”, line 1604, in getMetaEvents
metaObj = midiEventsToInstrument(e)
File “/Users/aydinabiar/hello/.venv/lib/python3.8/site-packages/music21/midi/translate.py”, line 700, in midiEventsToInstrument
i = instrument.fromString(event.data.decode(‘utf-8’))
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xa9 in position 10: invalid start byte
Do you have any idea how to fix it ? I encounter on other forum like stack overflow other people having this trouble when they follow this tutorial but they didn’t get answers
I’m working on MACOS with python 3.8.6 on Visual Studio and I download the latest version of music21
Thank you very much
1 post - 1 participant