-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
46 lines (39 loc) · 1.36 KB
/
utils.py
File metadata and controls
46 lines (39 loc) · 1.36 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
import logging
def handle_scp(scp_path):
'''
Read scp file script
input:
scp_path: .scp file's file path
output:
scp_dict: {'key':'wave file path'}
'''
scp_dict = dict()
line = 0
lines = open(scp_path, 'r').readlines()
for l in lines:
scp_parts = l.strip().split()
line += 1
if len(scp_parts) != 2:
raise RuntimeError("For {}, format error in line[{:d}]: {}".format(
scp_path, line, scp_parts))
if len(scp_parts) == 2:
key, value = scp_parts
if key in scp_dict:
raise ValueError("Duplicated key \'{0}\' exists in {1}".format(
key, scp_path))
scp_dict[key] = value
return scp_dict
def get_logger(name, format_str="%(asctime)s [%(pathname)s:%(lineno)s - %(levelname)s ] %(message)s",
date_format='%Y-%m-%d %H:%M:%S', file=False):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
# file or console
handler = logging.StreamHandler() if not file else logging.FileHandler(
name)
handler.setLevel(logging.INFO)
formatter = logging.Formatter(fmt=format_str, datefmt=date_format)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger
if __name__ == "__main__":
print(len(handle_scp('./dataset/create_scp/cv_s2.scp')))