PyGame包含一个内置的midi模块,可用于Linux,Windows和MacOS,并且得到了很好的支持。
例如,这是pygame.midi.Input的文档:
Input is used to get midi input from midi devices. Input(device_id) Input(device_id, buffer_size) Input.close - closes a midi stream, flushing any pending buffers. closes a midi stream, flushing any pending buffers. Input.poll - returns true if there's data, or false if not. returns true if there's data, or false if not. Input.read - reads num_events midi events from the buffer. reads num_events midi events from the buffer.
如果您正在寻找替代方法,请查看Python
Wiki中的PythonInMusic。
那里有与MIDI输入和输出相关的各种不同项目,有些还适用于Windows。(在每个项目后单击小号>标记,以跟随指向项目主页的链接)
我个人没有使用过它们,但是我相信它会帮助您入门。



