1.59 KB
import argparse
from utils import SubCommandRunner
from import read_lst
import os

def lst2wav(lst: str, root: str, outfile: str):
    lst_ = read_lst(lst)

    with open(outfile, "w") as f:
        for id_ in lst_:
            # Split id
            splited = id_.replace("\n", "").split(",")

            # Get language
            language = None
            if splited[0] == "en-us":
                language = "english"
            elif splited[0] == "":
                language = "french"

            # Create wav filename
            splited3 = splited[3].split(".")
            wav = "-".join(splited3) + ".wav"

            # Create full path
            full_path = os.path.join(language, "wave-audio", wav)

            f.write(f"{id_} {full_path}\n")

if __name__ == '__main__':
    # Main parser
    parser = argparse.ArgumentParser(description="Skyrim data-management commands")
    subparsers = parser.add_subparsers(title="action")

    parser_lst2wav = subparsers.add_parser("lst2wav", help="Generate wav file from lst")
    parser_lst2wav.add_argument("--lst", type=str, help="list file .lst")
    parser_lst2wav.add_argument("--root", type=str, help="root directory with audio files")
    parser_lst2wav.add_argument("--outfile", type=str, help="output wav.scp-like file")

    # Parse
    args = parser.parse_args()

    # Run commands
    runner = SubCommandRunner({
        "lst2wav" : lst2wav
    }), args.__dict__, remove="which")