forked from Andong-Li-speech/DARCN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson_extract.py
28 lines (24 loc) · 958 Bytes
/
json_extract.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
import json
import os
from config import dataset_path, json_path
def json_ext(dataset_path, json_path, flag):
if flag is 'train':
dataset_path = os.path.join(dataset_path, 'train', 'mix')
json_path = os.path.join(json_path, 'train')
os.makedirs(json_path, exist_ok=True)
else:
dataset_path = os.path.join(dataset_path, 'dev', 'mix')
json_path = os.path.join(json_path, 'dev')
os.makedirs(json_path, exist_ok=True)
data_dir = os.listdir(dataset_path)
data_dir.sort()
data_num = len(data_dir)
data_list = []
for i in range(data_num):
file_name = data_dir[i]
file_name = os.path.splitext(file_name)[0]
data_list.append(file_name)
with open(os.path.join(json_path, 'files.json'), 'w') as f :
json.dump(data_list, f, indent=4)
json_ext(dataset_path, json_path, flag='train')
json_ext(dataset_path, json_path, flag='dev')