-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
51 lines (44 loc) · 1.65 KB
/
process.py
File metadata and controls
51 lines (44 loc) · 1.65 KB
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
import os
from scipy.io import wavfile
from tqdm import trange
from PIL import Image
print("If running this with newly added songs, make sure to remove previously converted songs from directory")
song_file = input("Input Directory of Songs: ")
index = 0
if os.path.isdir("data"):
index = len(os.listdir("data"))
else:
os.mkdir("data")
# Split songs in directory into 2 second clips
for song in os.listdir(song_file):
song_dir = os.path.join(song_file, song)
sample_rate, data = wavfile.read(song_dir)
len_data = len(data) # holds length of the numpy array
seconds = len_data / sample_rate # returns duration but in floats
print(f"Splitting {song}")
for starting_second in trange(0, int(seconds), 2):
output_file = f"data/{index}.wav"
os.system(
f"ffmpeg -ss {starting_second} -t 2 -i {song_dir} -bitexact -map_metadata -1 {output_file}")
index += 1
index = 0
# Convert into BMP
wav_files = os.listdir("data")
if os.path.isdir("bmp"):
bmp_files = os.listdir("bmp")
index = len(bmp_files)
else:
os.mkdir("bmp")
for file_number in range(index, len(os.listdir("data"))):
os.system(
f"arss -q data/{file_number}.wav bmp/{file_number}.bmp -min 27.5 -max 20000 -x 128 -y 128")
index = 0
if os.path.isdir("png"):
index = len(os.listdir("png"))
else:
os.mkdir("png")
bmp_files = os.listdir("bmp")
for file_number in trange(index, len(bmp_files)):
bmp_file_name = os.path.join("bmp", f"{file_number}.bmp")
png_file_name = os.path.join("png", f"{file_number}.png")
Image.open(bmp_file_name).convert('L').save(png_file_name)