Commit 9a08c7beb32df9c5341fa130ba6568fc6637d130

Authored by Mathias Quillot
1 parent 66e4279a77
Exists in master

Fix issue

Showing 1 changed file with 3 additions and 5 deletions Inline Diff

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] == "": 21 elif splited[0] == "fr-fr":
22 language = "french" 22 language = "french"
23 print(splited[0])
24 print(language)
25 23
26 # Create wav filename 24 # Create wav filename
27 splited3 = splited[3].split(".") 25 splited3 = splited[3].split(".")
28 wav = "-".join(splited3) + ".wav" 26 wav = ("-".join(splited3) + ".wav").replace(" ", "")
29 27
30 # Create full path 28 # Create full path
31 full_path = os.path.join(language, "wave-audio", wav) 29 full_path = os.path.join(root, language, "wave-audio", wav)
32 30
33 f.write(f"{id_} {full_path}\n") 31 f.write(f"{id_} {full_path}\n")
34 pass 32 pass
35 pass 33 pass
36 34
37 35
38 if __name__ == '__main__': 36 if __name__ == '__main__':
39 # Main parser 37 # Main parser
40 parser = argparse.ArgumentParser(description="Skyrim data-management commands") 38 parser = argparse.ArgumentParser(description="Skyrim data-management commands")
41 subparsers = parser.add_subparsers(title="action") 39 subparsers = parser.add_subparsers(title="action")
42 40
43 parser_lst2wav = subparsers.add_parser("lst2wav", help="Generate wav file from lst") 41 parser_lst2wav = subparsers.add_parser("lst2wav", help="Generate wav file from lst")
44 parser_lst2wav.add_argument("--lst", type=str, help="list file .lst") 42 parser_lst2wav.add_argument("--lst", type=str, help="list file .lst")
45 parser_lst2wav.add_argument("--root", type=str, help="root directory with audio files") 43 parser_lst2wav.add_argument("--root", type=str, help="root directory with audio files")
46 parser_lst2wav.add_argument("--outfile", type=str, help="output wav.scp-like file") 44 parser_lst2wav.add_argument("--outfile", type=str, help="output wav.scp-like file")
47 parser_lst2wav.set_defaults(which="lst2wav") 45 parser_lst2wav.set_defaults(which="lst2wav")
48 46
49 # Parse 47 # Parse
50 args = parser.parse_args() 48 args = parser.parse_args()
51 49
52 # Run commands 50 # Run commands
53 runner = SubCommandRunner({ 51 runner = SubCommandRunner({
54 "lst2wav" : lst2wav 52 "lst2wav" : lst2wav
55 }) 53 })
56 54
57 runner.run(args.which, args.__dict__, remove="which") 55 runner.run(args.which, args.__dict__, remove="which")
58 56