From 62fc82e59a9eb5d76499d57175ed1a8475ecf995 Mon Sep 17 00:00:00 2001 From: Quillot Mathias Date: Tue, 11 May 2021 13:55:07 +0200 Subject: [PATCH] Allow user to generate utt2char file. char2file is in building --- volia/masseffect.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 volia/masseffect.py diff --git a/volia/masseffect.py b/volia/masseffect.py new file mode 100644 index 0000000..c6119fc --- /dev/null +++ b/volia/masseffect.py @@ -0,0 +1,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") \ No newline at end of file -- 1.8.2.3