-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtract.py
More file actions
45 lines (27 loc) · 1.08 KB
/
Extract.py
File metadata and controls
45 lines (27 loc) · 1.08 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
import fnmatch
import os
import zipfile
def extract_files(zip_file, out_dir, delete_zip=False):
audio_dir = os.path.join(out_dir, 'audio')
if not os.path.exists(audio_dir):
os.makedirs(audio_dir)
transcripts_dir = os.path.join(out_dir, 'transcripts')
if not os.path.exists(audio_dir):
os.makedirs(transcripts_dir)
zip_ref = zipfile.ZipFile(zip_file)
for f in zip_ref.namelist(): # iterate through files in zip file
if f.endswith('.wav'):
zip_ref.extract(f, audio_dir)
elif fnmatch.fnmatch(f, '*TRANSCRIPT.csv'):
zip_ref.extract(f, transcripts_dir)
zip_ref.close()
if delete_zip:
os.remove(zip_file)
if __name__ == '__main__':
dir_name = '/Home/Documents/depression-detection/DAIC-WOZ'
out_dir = '/Home/Documents/depression-detection/src/raw'
delete_zip = False
for file in os.listdir(dir_name):
if file.endswith('.zip'):
zip_file = os.path.join(dir_name, file)
extract_files(zip_file, out_dir, delete_zip=delete_zip)