Download midi_utils.py from peter288/fa: direct link, hf CLI and curl.
- Browser
- Download file 610 Bytes
-
https://huggingface.co/spaces/peter288/fa/resolve/main/midi_utils.py
- Command line
-
hf download hf://spaces/peter288/fa/midi_utils.py
-
curl -L -o midi_utils.py https://huggingface.co/spaces/peter288/fa/resolve/main/midi_utils.py
610 Bytes
| import mido | |
| from io import BytesIO | |
| def process_midi(midi_bytes: bytes) -> BytesIO: | |
| """处理MIDI文件:将所有音符提高一个半音""" | |
| with BytesIO(midi_bytes) as input_buffer: | |
| mid = mido.MidiFile(file=input_buffer) | |
| for track in mid.tracks: | |
| for msg in track: | |
| if msg.type in ['note_on', 'note_off']: | |
| if msg.note < 127: | |
| msg.note += 1 | |
| output_buffer = BytesIO() | |
| mid.save(file=output_buffer) | |
| output_buffer.seek(0) | |
| return output_buffer |