-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorganize_files.py
36 lines (26 loc) · 981 Bytes
/
organize_files.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
import os
from random import sample
test_rate = .2
rsr_path = os.getcwd() + "\\rsr2015\\"
data_path = os.getcwd() + "\\data\\"
for folder in ["male\\", "female\\"]:
os.chdir(rsr_path + folder)
subfolders = os.listdir()
num_speakers = len(subfolders)
num_test = test_rate * num_speakers
for subfolder in subfolders:
if (int(subfolder[-3:]) <= num_test):
target = data_path + "test\\"
else:
target = data_path + "train\\"
os.chdir(rsr_path + folder + subfolder)
files = os.listdir()
pos = [f for f in files if f.endswith("042.wav")]
neg = sample([f for f in files if f not in pos], len(pos)*3)
for f in pos:
command = ("copy " + f + " " + target + f)
os.system(command)
for f in neg:
command = ("copy " + f + " " + target + f)
os.system(command)
print("Subfolder " + folder + subfolder + " sampled")