skyrim.py
2.7 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import argparse
from utils import SubCommandRunner
from core.data 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] == "fr-fr":
language = "french"
# Create wav filename
splited3 = splited[3].split(".")
wav = ("-".join(splited3) + ".wav").replace(" ", "")
# Create full path
full_path = os.path.join(root, language, "wave-audio", wav)
f.write(f"{id_} {full_path}\n")
def utt2spk(lst: str, outfile: str):
lst_ = read_lst(lst)
with open(outfile, "w") as f:
for id_ in lst_:
splited = id_.split(",")
spk_id = splited[0] + "-" + splited[1]
f.write(id_ + " " + spk_id + "\n")
def utt2char(lst: str, outfile: str):
lst_ = read_lst(lst)
with open(outfile, "w") as f:
for id_ in lst_:
splited = id_.split(",")
char_id = splited[1]
f.write(id_ + " " + char_id + "\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")
parser_lst2wav.set_defaults(which="lst2wav")
parser_utt2spk = subparsers.add_parser("utt2spk", help="generate utt2spk file")
parser_utt2spk.add_argument("--lst", required=True, type=str, help="list file .lst")
parser_utt2spk.add_argument("--outfile", required=True, type=str, help="utt2spk output file")
parser_utt2spk.set_defaults(which="utt2spk")
parser_utt2char = subparsers.add_parser("utt2char", help="..")
parser_utt2char.add_argument("--lst", required=True, type=str, help="list file .lst")
parser_utt2char.add_argument("--outfile", required=True, type=str, help="utt2char output file")
parser_utt2char.set_defaults(which="utt2char")
# Parse
args = parser.parse_args()
# Run commands
runner = SubCommandRunner({
"lst2wav": lst2wav,
"utt2spk": utt2spk,
"utt2char": utt2char
})
runner.run(args.which, args.__dict__, remove="which")