masseffect.py 1.67 KB
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")