我目前正在做一个 PYTHON 程序,我想在没有库或程序或网站的情况下将 midi 转换为 wav。我发现多个帖子告诉我要下载一个库,但我正在 Pythonista(适用于 iPhone 和 iPad 的 Python IDE)中编码,所以由于我在移动设备上,我无法下载这些库......</p>
所以如果有可能有人可以告诉我怎么做吗?
我的代码:
# modes: 1 = short classical songs, 2 = soundtrack games boss battle, 3 = sad music
mode = 2
from midiutil.MidiFile import MIDIFile
from random import randint as random
import sound
from time import sleep as wait
midi = MIDIFile(1, adjust_origin=True)
duration = 0
if mode == 1:
duration = random(30, 200)
midi.addTempo(0, 0, random(60, 360))
elif mode == 2:
duration = random(660, 960)
midi.addTempo(0, 0, random(360, 660))
elif mode == 3:
duration = random(10,80)
midi.addTempo(0, 0, random(30, 60))
for t in range(duration):
pitch = random(60,80)
midi.addNote(0, 0, pitch, t * 1 + random(0, 2), 1, 100)
with open('machine made song.txt', 'wb') as f:
midi.writeFile(f)
player = sound.MIDIPlayer('machine made song.txt')
player.play()