-
Notifications
You must be signed in to change notification settings - Fork 1
/
batch_preprocess.py
68 lines (56 loc) · 2.52 KB
/
batch_preprocess.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'''
This function makes a new folder for each existing folder in the SoundFiles directory, then calls the audio_preprocess function
and puts them into their respective folders, ready for model training
Warning: deletes before copying, don't run unless doing preprocessing
'''
import os
import shutil
from audio_preprocess import *
# Paths of the operation, root path is old folder parent is parent folder new path is new folder
root_path = 'Stem-SeperationDL\SoundFiles'
new_path = 'Stem-SeperationDL\SoundFilesPrep'
def batch_preprocess():
# Prints each directors and each file in the directory
for (root,dirs,files) in os.walk(root_path):
print (root)
print (files)
print ('--------------------------------')
# !!WARNING!!
# Deletes the SoundFilesPrep folder and then creates a copy of the SoundFiles folder
shutil.rmtree(new_path)
destination = shutil.copytree(root_path,new_path)
# Walks through the directories
for(subdir, dirs, files) in os.walk(new_path):
# For each file in the directory
for file in files:
# File path
file_path = subdir + "\\" + file
print(file_path)
# New file is the file with preprocessing from the file path
new_file = audio_preprocess(file_path,0,10000)
# Export and replace the old file with the new one
new_file.export(file_path, format="wav")
# Paths of the operation, root path is old folder parent is parent folder new path is new folder
root_path2 = 'Stem-SeperationDL\TestFiles'
new_path2 = 'Stem-SeperationDL\TestFilesPrep'
def batch_preprocess_test():
# Prints each directors and each file in the directory
for (root,dirs,files) in os.walk(root_path2):
print (root)
print (files)
print ('--------------------------------')
# !!WARNING!!
# Deletes the SoundFilesPrep folder and then creates a copy of the SoundFiles folder
shutil.rmtree(new_path2)
destination = shutil.copytree(root_path2,new_path2)
# Walks through the directories
for(subdir, dirs, files) in os.walk(new_path2):
# For each file in the directory
for file in files:
# File path
file_path = subdir + "\\" + file
print(file_path)
# New file is the file with preprocessing from the file path
new_file = audio_preprocess(file_path,0,10000)
# Export and replace the old file with the new one
new_file.export(file_path, format="wav")