Commit 8df8f5b23895795a19d7c35f3b0c99146d65adf1
1 parent
4d4eaadf41
Exists in
master
Solve issue
Showing 1 changed file with 0 additions and 4 deletions Inline Diff
volia/skyrim.py
1 | 1 | ||
2 | import argparse | 2 | import argparse |
3 | from utils import SubCommandRunner | 3 | from utils import SubCommandRunner |
4 | from core.data import read_lst | 4 | from core.data import read_lst |
5 | import os | 5 | import os |
6 | 6 | ||
7 | 7 | ||
8 | 8 | ||
9 | def lst2wav(lst: str, root: str, outfile: str): | 9 | def lst2wav(lst: str, root: str, outfile: str): |
10 | lst_ = read_lst(lst) | 10 | lst_ = read_lst(lst) |
11 | 11 | ||
12 | with open(outfile, "w") as f: | 12 | with open(outfile, "w") as f: |
13 | for id_ in lst_: | 13 | for id_ in lst_: |
14 | # Split id | 14 | # Split id |
15 | splited = id_.replace("\n", "").split(",") | 15 | splited = id_.replace("\n", "").split(",") |
16 | 16 | ||
17 | # Get language | 17 | # Get language |
18 | language = None | 18 | language = None |
19 | if splited[0] == "en-us": | 19 | if splited[0] == "en-us": |
20 | language = "english" | 20 | language = "english" |
21 | elif splited[0] == "fr-fr": | 21 | elif splited[0] == "fr-fr": |
22 | language = "french" | 22 | language = "french" |
23 | 23 | ||
24 | # Create wav filename | 24 | # Create wav filename |
25 | splited3 = splited[3].split(".") | 25 | splited3 = splited[3].split(".") |
26 | wav = ("-".join(splited3) + ".wav").replace(" ", "") | 26 | wav = ("-".join(splited3) + ".wav").replace(" ", "") |
27 | 27 | ||
28 | # Create full path | 28 | # Create full path |
29 | full_path = os.path.join(root, language, "wave-audio", wav) | 29 | full_path = os.path.join(root, language, "wave-audio", wav) |
30 | 30 | ||
31 | f.write(f"{id_} {full_path}\n") | 31 | f.write(f"{id_} {full_path}\n") |
32 | 32 | ||
33 | 33 | ||
34 | def utt2spk(lst: str, outfile: str): | 34 | def utt2spk(lst: str, outfile: str): |
35 | lst_ = read_lst(lst) | 35 | lst_ = read_lst(lst) |
36 | 36 | ||
37 | with open(outfile, "w") as f: | 37 | with open(outfile, "w") as f: |
38 | for id_ in lst_: | 38 | for id_ in lst_: |
39 | splited = id_.split(",") | 39 | splited = id_.split(",") |
40 | spk_id = splited[0] + "-" + splited[1] | 40 | spk_id = splited[0] + "-" + splited[1] |
41 | f.write(id_ + " " + spk_id + "\n") | 41 | f.write(id_ + " " + spk_id + "\n") |
42 | 42 | ||
43 | 43 | ||
44 | def utt2char(lst: str, outfile: str): | 44 | def utt2char(lst: str, outfile: str): |
45 | lst_ = read_lst(lst) | 45 | lst_ = read_lst(lst) |
46 | 46 | ||
47 | with open(outfile, "w") as f: | 47 | with open(outfile, "w") as f: |
48 | for id_ in lst_: | 48 | for id_ in lst_: |
49 | splited = id_.split(",") | 49 | splited = id_.split(",") |
50 | char_id = splited[1] | 50 | char_id = splited[1] |
51 | f.write(id_ + " " + char_id + "\n") | 51 | f.write(id_ + " " + char_id + "\n") |
52 | 52 | ||
53 | 53 | ||
54 | def utt2char(): | ||
55 | pass | ||
56 | |||
57 | |||
58 | if __name__ == '__main__': | 54 | if __name__ == '__main__': |
59 | # Main parser | 55 | # Main parser |
60 | parser = argparse.ArgumentParser(description="Skyrim data-management commands") | 56 | parser = argparse.ArgumentParser(description="Skyrim data-management commands") |
61 | subparsers = parser.add_subparsers(title="action") | 57 | subparsers = parser.add_subparsers(title="action") |
62 | 58 | ||
63 | parser_lst2wav = subparsers.add_parser("lst2wav", help="Generate wav file from lst") | 59 | parser_lst2wav = subparsers.add_parser("lst2wav", help="Generate wav file from lst") |
64 | parser_lst2wav.add_argument("--lst", type=str, help="list file .lst") | 60 | parser_lst2wav.add_argument("--lst", type=str, help="list file .lst") |
65 | parser_lst2wav.add_argument("--root", type=str, help="root directory with audio files") | 61 | parser_lst2wav.add_argument("--root", type=str, help="root directory with audio files") |
66 | parser_lst2wav.add_argument("--outfile", type=str, help="output wav.scp-like file") | 62 | parser_lst2wav.add_argument("--outfile", type=str, help="output wav.scp-like file") |
67 | parser_lst2wav.set_defaults(which="lst2wav") | 63 | parser_lst2wav.set_defaults(which="lst2wav") |
68 | 64 | ||
69 | parser_utt2spk = subparsers.add_parser("utt2spk", help="generate utt2spk file") | 65 | parser_utt2spk = subparsers.add_parser("utt2spk", help="generate utt2spk file") |
70 | parser_utt2spk.add_argument("--lst", required=True, type=str, help="list file .lst") | 66 | parser_utt2spk.add_argument("--lst", required=True, type=str, help="list file .lst") |
71 | parser_utt2spk.add_argument("--outfile", required=True, type=str, help="utt2spk output file") | 67 | parser_utt2spk.add_argument("--outfile", required=True, type=str, help="utt2spk output file") |
72 | parser_utt2spk.set_defaults(which="utt2spk") | 68 | parser_utt2spk.set_defaults(which="utt2spk") |
73 | 69 | ||
74 | parser_utt2char = subparsers.add_parser("utt2char", help="..") | 70 | parser_utt2char = subparsers.add_parser("utt2char", help="..") |
75 | parser_utt2char.add_argument("--lst", required=True, type=str, help="list file .lst") | 71 | parser_utt2char.add_argument("--lst", required=True, type=str, help="list file .lst") |
76 | parser_utt2char.add_argument("--outfile", required=True, type=str, help="utt2char output file") | 72 | parser_utt2char.add_argument("--outfile", required=True, type=str, help="utt2char output file") |
77 | parser_utt2char.set_defaults(which="utt2char") | 73 | parser_utt2char.set_defaults(which="utt2char") |
78 | 74 | ||
79 | # Parse | 75 | # Parse |
80 | args = parser.parse_args() | 76 | args = parser.parse_args() |
81 | 77 | ||
82 | # Run commands | 78 | # Run commands |
83 | runner = SubCommandRunner({ | 79 | runner = SubCommandRunner({ |
84 | "lst2wav": lst2wav, | 80 | "lst2wav": lst2wav, |
85 | "utt2spk": utt2spk, | 81 | "utt2spk": utt2spk, |
86 | "utt2char": utt2char | 82 | "utt2char": utt2char |
87 | }) | 83 | }) |
88 | 84 | ||
89 | runner.run(args.which, args.__dict__, remove="which") | 85 | runner.run(args.which, args.__dict__, remove="which") |
90 | 86 |