Commit 233b7d451bb4f8b0632c25899452061b70018c96

Authored by quillotm
1 parent b6c178927e
Exists in master

adding changelabels function

Showing 1 changed file with 22 additions and 3 deletions Side-by-side Diff

... ... @@ -4,6 +4,7 @@
4 4 from utils import SubCommandRunner
5 5 import os
6 6  
  7 +
7 8 def utt2char(features: str, outfile: str):
8 9 """Allow the user to generate utt2char file from masseffect features file.
9 10  
... ... @@ -54,7 +55,6 @@
54 55  
55 56 directories = dir_en + dir_fr
56 57 filenames = filenames_en + filenames_fr
57   -
58 58  
59 59 with open(outfile, "w") as f:
60 60 for i, fn in enumerate(filenames):
... ... @@ -66,7 +66,18 @@
66 66 f.write(f"{lang},{character},{record_id} {path}\n")
67 67  
68 68  
69   -
  69 +def changelabels(source: str, labels: str, outfile: str):
  70 + data_dict = core.data.read_id_values(source)
  71 + labels_dict = core.data.read_labels(labels)
  72 + keys = list(data_dict.keys())
  73 +
  74 + with open(outfile, "w") as f:
  75 + for key in keys:
  76 + splited = key.split(",")
  77 + splited[1] = labels_dict[key]
  78 + core.data.write_line(",".join(splited), data_dict[key])
  79 +
  80 +
70 81 if __name__ == '__main__':
71 82 # Main parser
72 83 parser = argparse.ArgumentParser(description="...")
... ... @@ -90,6 +101,13 @@
90 101 parser_wavscp.add_argument("--outfile", default="wav.scp", help="wav.scp output file")
91 102 parser_wavscp.set_defaults(which="wavscp")
92 103  
  104 + # Change labels
  105 + parser_changelabels = subparsers.add_parser("changelabels", help="...")
  106 + parser_changelabels.add_argument("--source", required=True, type=str, help="source file where we want to change ids.")
  107 + parser_changelabels.add_argument("--labels", required=True, type=str, help="file with labels")
  108 + parser_changelabels.add_argument("--outfile", required=True, type=str, help="Output file")
  109 + parser_changelabels.set_defaults(which="changelabels")
  110 +
93 111 # Parse
94 112 args = parser.parse_args()
95 113  
... ... @@ -97,7 +115,8 @@
97 115 runner = SubCommandRunner({
98 116 "utt2char" : utt2char,
99 117 "char2utt": char2utt,
100   - "wavscp": wavscp
  118 + "wavscp": wavscp,
  119 + "changelabels": changelabels
101 120 })
102 121  
103 122 runner.run(args.which, args.__dict__, remove="which")