Commit acad79ac33be427c8d7b973d96e2b343eb6d8c30

Authored by quillotm
1 parent 4333e05c50
Exists in master

Generate wav file from lst one.

Showing 1 changed file with 55 additions and 0 deletions Side-by-side Diff

  1 +
  2 +import argparse
  3 +from utils import SubCommandRunner
  4 +from core.data import read_lst
  5 +import os
  6 +
  7 +
  8 +
  9 +def lst2wav(lst: str, root: str, outfile: str):
  10 + lst_ = read_lst(lst)
  11 +
  12 + with open(outfile, "w") as f:
  13 + for id_ in lst_:
  14 + # Split id
  15 + splited = id_.split(",")
  16 +
  17 + # Get language
  18 + language = None
  19 + if splited[0] == "en-us":
  20 + language = "english"
  21 + elif splited[0] == "":
  22 + language = "french"
  23 +
  24 + # Create wav filename
  25 + splited3 = splited[3].splited(".")
  26 + wav = "-".join(splited3) + ".wav"
  27 +
  28 + # Create full path
  29 + full_path = os.path.join(language, "wave-audio", wav)
  30 +
  31 + f.write(f"{id_} {full_path}\n")
  32 + pass
  33 + pass
  34 +
  35 +
  36 +if __name__ == '__main__':
  37 + # Main parser
  38 + parser = argparse.ArgumentParser(description="Skyrim data-management commands")
  39 + subparsers = parser.add_subparsers(title="action")
  40 +
  41 + parser_lst2wav = subparsers.add_parser("lst2wav", help="Generate wav file from lst")
  42 + parser_lst2wav.add_argument("--lst", type=str, help="list file .lst")
  43 + parser_lst2wav.add_argument("--root", type=str, help="root directory with audio files")
  44 + parser_lst2wav.add_argument("--outfile", type=str, help="output wav.scp-like file")
  45 + parser_lst2wav.set_defaults(which="lst2wav")
  46 +
  47 + # Parse
  48 + args = parser.parse_args()
  49 +
  50 + # Run commands
  51 + runner = SubCommandRunner({
  52 + "lst2wav" : lst2wav
  53 + })
  54 +
  55 + runner.run(args.which, args.__dict__, remove="which")