-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioRenamer.py
More file actions
169 lines (150 loc) · 10.5 KB
/
AudioRenamer.py
File metadata and controls
169 lines (150 loc) · 10.5 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import os
import shutil
desktop_path = os.path.join(os.path.expanduser("~"), "Desktop")
audio_dir = os.path.join(desktop_path, 'AudioInput')
audio_files = os.listdir(audio_dir)
template = "VMM3_{trial}_{type}_{run}_{pre/post}.wav"
run1b = "25_segments"
run2b = "47_segments"
run3b = "14_segments"
run1a = "55_pre_segments"
run2a = "44_pre_segments"
run3a = "13_29_pre_segments"
# handles directory creation
headFolder = "ET Organized Audio"
subject = "ET"
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Bpress_equivalent")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1/{subject}_Bv_RUN1_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1/{subject}_Gl_RUN1_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1/{subject}_Hv_RUN1_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2/{subject}_Bv_RUN2_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2/{subject}_Gl_RUN2_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2/{subject}_Hv_RUN2_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3/{subject}_Bv_RUN3_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3/{subject}_Gl_RUN3_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3/{subject}_Hv_RUN3_post")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1/{subject}_Bv_RUN1_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1/{subject}_Gl_RUN1_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1/{subject}_Hv_RUN1_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2/{subject}_Bv_RUN2_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2/{subject}_Gl_RUN2_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2/{subject}_Hv_RUN2_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3/{subject}_Bv_RUN3_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3/{subject}_Gl_RUN3_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3/{subject}_Hv_RUN3_pre")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/{subject}_HighVowels")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/{subject}_BackVowels")
os.makedirs(f"/Users/coleman/Desktop/AudioInput/{headFolder}/{subject}_Glides")
for filename in audio_files:
print(filename)
# handles renaming files
if filename.endswith("segments"):
for item in os.listdir(os.path.join(audio_dir, filename)):
templateCopy = template
if item.endswith(".wav"):
# print(item)
# handles the run number and pre/post
if filename.endswith(run1b):
templateCopy = templateCopy.replace("{run}", "run1")
templateCopy = templateCopy.replace("{pre/post}", "post")
elif filename.endswith(run2b):
templateCopy = templateCopy.replace("{run}", "run2")
templateCopy = templateCopy.replace("{pre/post}", "post")
elif filename.endswith(run3b):
templateCopy = templateCopy.replace("{run}", "run3")
templateCopy = templateCopy.replace("{pre/post}", "post")
elif filename.endswith(run1a):
templateCopy = templateCopy.replace("{run}", "run1")
templateCopy = templateCopy.replace("{pre/post}", "pre")
elif filename.endswith(run2a):
templateCopy = templateCopy.replace("{run}", "run2")
templateCopy = templateCopy.replace("{pre/post}", "pre")
elif filename.endswith(run3a):
templateCopy = templateCopy.replace("{run}", "run3")
templateCopy = templateCopy.replace("{pre/post}", "pre")
# handles trial type
if item.endswith("glide.wav"):
templateCopy = templateCopy.replace("{type}", "Gl")
elif item.endswith("backv.wav"):
templateCopy = templateCopy.replace("{type}", "Bv")
elif item.endswith("highv.wav"):
templateCopy = templateCopy.replace("{type}", "Hv")
# handles trial number
index = item.find("_T") + 1
# accounts for glitch in single digit naming
if item[index+2] == "_":
oldItem = item
item = item[:index+1] + "0" + item[index+1:]
os.rename(os.path.join(os.path.join(audio_dir, filename), oldItem), os.path.join(os.path.join(audio_dir, filename), item))
trialNumber = item[index:(index+3)]
templateCopy = templateCopy.replace("{trial}", trialNumber)
# renames files and slots into directories
# print(templateCopy)
runFolder = os.path.join(audio_dir, filename)
itemFile = os.path.join(runFolder, item)
itemFileRenamed = os.path.join(runFolder, templateCopy)
# renames file in same spot
os.rename(itemFile, itemFileRenamed)
# copies into new folder where appropriate
if "run1_post" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1")
if "Hv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1/{subject}_Hv_RUN1_post")
elif "Gl" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1/{subject}_Gl_RUN1_post")
elif "Bv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN1/{subject}_Bv_RUN1_post")
elif "run2_post" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2")
if "Hv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2/{subject}_Hv_RUN2_post")
elif "Gl" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2/{subject}_Gl_RUN2_post")
elif "Bv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN2/{subject}_Bv_RUN2_post")
elif "run3_post" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3")
if "Hv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3/{subject}_Hv_RUN3_post")
elif "Gl" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3/{subject}_Gl_RUN3_post")
elif "Bv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Post/RUN3/{subject}_Bv_RUN3_post")
elif "run1_pre" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1")
if "Hv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1/{subject}_Hv_RUN1_pre")
elif "Gl" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1/{subject}_Gl_RUN1_pre")
elif "Bv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN1/{subject}_Bv_RUN1_pre")
elif "run2_pre" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2")
if "Hv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2/{subject}_Hv_RUN2_pre")
elif "Gl" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2/{subject}_Gl_RUN2_pre")
elif "Bv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN2/{subject}_Bv_RUN2_pre")
elif "run3_pre" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3")
if "Hv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3/{subject}_Hv_RUN3_pre")
elif "Gl" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3/{subject}_Gl_RUN3_pre")
elif "Bv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/Pre/RUN3/{subject}_Bv_RUN3_pre")
if "Hv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/{subject}_HighVowels")
elif "Bv" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/{subject}_BackVowels")
elif "Gl" in templateCopy:
shutil.copy(itemFileRenamed, f"/Users/coleman/Desktop/AudioInput/{headFolder}/{subject}_Glides")