-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
63 lines (56 loc) · 1.47 KB
/
utils.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
import yaml
import json
from librosa import get_duration
def parse_yaml(filepath="conf.yaml"):
"""
This method parses the YAML configuration file and returns the parsed info
as python dictionary.
Args:
filepath (string): relative path of the YAML configuration file
"""
with open(filepath, 'r') as fin:
try:
d = yaml.safe_load(fin)
return d
except Exception as exc:
print("ERROR while parsing YAML conf.")
return exc
def build_manifest(wav_path):
"""
This function takes the absolute path of the wav file and writes
the metadata of the wav into json file on the following format:
{
"audio_filepath": wav_path,
"duration": 100,
"text": ""
}
"""
filename = 'audio.json'
duration = get_duration(filename=wav_path)
d = {
"audio_filepath": wav_path,
"duration": duration,
"text": ""
}
with open(filename, 'w') as fout:
json.dump(d, fout)
return filename
def build_text_path(text):
"""
This function takes the a text as input and writes the metadata into json
file on the following format:
{
"audio_filepath": "",
"duration": 1.0,
"text": text
}
"""
filename = 'text.json'
d = {
"audio_filepath": "",
"duration": 1.0,
"text": text
}
with open(filename, 'w') as fout:
json.dump(d, fout)
return filename