我正在尝试从 Python 播放一些 MIDI 文件(使用 PyCharm)。这是我必须读取 MIDI 文件然后播放它但没有播放声音的代码。
import mido
from mido import MidiFile
class theMidi():
def __init__(self, fileName):
self.midiFileNameFullPath = fileName
self.midiObject = MidiFile(fileName)
print(self.midiObject)
self.out = mido.get_output_names()[0]
print (self.out)
self.outport = mido.open_output(self.out)
for msg in self.midiObject.play():
print (msg)
self.outport.send(msg)