masseffect.py
1.67 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
import argparse
import core.data
from utils import SubCommandRunner
def utt2char(features: str, outfile: str):
"""Allow the user to generate utt2char file from masseffect features file.
TODO: Don't forget to manage two cases: one with old ids, and an other with
new ones.
Args:
features (str): [description]
outfile (str): [description]
"""
data = core.data.read_features(features)
keys = list(data.keys())
with open(outfile, "w") as f:
for key in keys:
splited = key.replace("\n", "").split(",")
character = splited[1]
f.write(",".join(splited) + " " + character + "\n")
def char2utt(features: str, outfile: str):
raise Exception("Not implemented yet")
pass
if __name__ == '__main__':
# Main parser
parser = argparse.ArgumentParser(description="...")
subparsers = parser.add_subparsers(title="action")
# utt2char
parser_utt2char = subparsers.add_parser("utt2char")
parser_utt2char.add_argument("--features", type=str, help="features file")
parser_utt2char.add_argument("--outfile", type=str, help="output file")
parser_utt2char.set_defaults(which="utt2char")
# char2utt
parser_char2utt = subparsers.add_parser("char2utt")
parser_char2utt.add_argument("--features", type=str, help="features file")
parser_char2utt.add_argument("--outfile", type=str, help="output file")
parser_char2utt.set_defaults(which="char2utt")
# Parse
args = parser.parse_args()
# Run commands
runner = SubCommandRunner({
"utt2char" : utt2char,
"char2utt": char2utt,
})
runner.run(args.which, args.__dict__, remove="which")