Blame view

volia/skyrim.py 2.7 KB
acad79ac3   quillotm   Generate wav file...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  
  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
66e4279a7   quillotm   Little error solved
15
16
              splited = id_.replace("
  ", "").split(",")
acad79ac3   quillotm   Generate wav file...
17
18
19
20
21
  
              # Get language
              language = None
              if splited[0] == "en-us":
                  language = "english"
9a08c7beb   Mathias Quillot   Fix issue
22
              elif splited[0] == "fr-fr":
acad79ac3   quillotm   Generate wav file...
23
24
25
                  language = "french"
  
              # Create wav filename
83e2994d0   quillotm   Little error solved
26
              splited3 = splited[3].split(".")
9a08c7beb   Mathias Quillot   Fix issue
27
              wav = ("-".join(splited3) + ".wav").replace(" ", "")
acad79ac3   quillotm   Generate wav file...
28
29
  
              # Create full path
9a08c7beb   Mathias Quillot   Fix issue
30
              full_path = os.path.join(root, language, "wave-audio", wav)
acad79ac3   quillotm   Generate wav file...
31
32
33
  
              f.write(f"{id_} {full_path}
  ")
a36206bdd   quillotm   Add needed functi...
34
35
36
37
38
39
  
  
  def utt2spk(lst: str, outfile: str):
      lst_ = read_lst(lst)
  
      with open(outfile, "w") as f:
4d4eaadf4   quillotm   Solve issue
40
          for id_ in lst_:
a36206bdd   quillotm   Add needed functi...
41
42
43
44
45
46
47
48
49
50
              splited = id_.split(",")
              spk_id = splited[0] + "-" + splited[1]
              f.write(id_ + " " + spk_id + "
  ")
  
  
  def utt2char(lst: str, outfile: str):
      lst_ = read_lst(lst)
  
      with open(outfile, "w") as f:
4d4eaadf4   quillotm   Solve issue
51
          for id_ in lst_:
a36206bdd   quillotm   Add needed functi...
52
53
54
55
              splited = id_.split(",")
              char_id = splited[1]
              f.write(id_ + " " + char_id + "
  ")
acad79ac3   quillotm   Generate wav file...
56
57
58
59
60
61
62
63
64
65
  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")
a36206bdd   quillotm   Add needed functi...
66
67
68
69
70
71
72
73
74
      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")
acad79ac3   quillotm   Generate wav file...
75
76
77
78
79
      # Parse
      args = parser.parse_args()
  
      # Run commands
      runner = SubCommandRunner({
4d4eaadf4   quillotm   Solve issue
80
          "lst2wav": lst2wav,
a36206bdd   quillotm   Add needed functi...
81
82
          "utt2spk": utt2spk,
          "utt2char": utt2char
acad79ac3   quillotm   Generate wav file...
83
84
85
      })
  
      runner.run(args.which, args.__dict__, remove="which")