-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_midi_to_wav.py
53 lines (42 loc) · 1.47 KB
/
convert_midi_to_wav.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import subprocess
__all__ = ["convert"]
MIDI_TO_WAV_LIST = {
"midi_songs.list": "wav_songs.list",
"midi_songs_expanse.list": "wav_songs_expanse.list"
}
def write_wav_list(song_midi_path, converted_names):
song_wav_list_filename = MIDI_TO_WAV_LIST[song_midi_path]
with open(song_wav_list_filename, 'w') as list_file:
lines = [
filename + '\n'
for filename in converted_names
]
list_file.writelines(lines)
def convert(filenames_list):
print("Converting songs...")
midi_songs = []
for filename in filenames_list:
with open(filename, 'r') as ms:
midi_songs.extend(
(
filename,
ms.readlines()
)
)
commands = []
for source, songs in midi_songs:
converted_names = []
for song in songs:
song = song.replace('\n', '')
converted_song_name = song.split('/')[-1].replace('.mid', '.wav')
converted_song_pathname = 'songs_wav/{}'.format(
converted_song_name
)
converted_names.append(converted_song_pathname)
command = 'timidity {} -Ow -o {}'.format(
song, converted_song_pathname
)
commands.append(command)
write_wav_list(song_midi_path=source, converted_names=converted_names)
for command in commands:
subprocess.run(command, shell=True)