Commit f774442a85d654636fd9904b1c324cbfbe20f9cf

Authored by quillotm
1 parent d727acc21a
Exists in master

Add converter creator action to the script

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

... ... @@ -78,6 +78,16 @@
78 78 core.data.write_line(",".join(splited), data_dict[key], out=f)
79 79  
80 80  
  81 +def converter(file: str, outtype: str, outfile: str):
  82 + data = core.data.read_id_values(file)
  83 +
  84 + with open(outfile, "w") as of:
  85 + for key in data:
  86 + splited = key.replace("\n", "").split(",")
  87 + of.write(key.replace("\n", "") + " " + ",".join([splited[0], splited[1], splited[3]]) + "\n")
  88 +
  89 +
  90 +
81 91 if __name__ == '__main__':
82 92 # Main parser
83 93 parser = argparse.ArgumentParser(description="...")
... ... @@ -108,6 +118,17 @@
108 118 parser_changelabels.add_argument("--outfile", required=True, type=str, help="Output file")
109 119 parser_changelabels.set_defaults(which="changelabels")
110 120  
  121 + # Create converter
  122 + parser_converter = subparsers.add_parser("converter", help="Create converter file")
  123 + parser_converter.add_argument("--file",
  124 + type=str,
  125 + required=True,
  126 + help="File with ids from which create converter.")
  127 + parser_converter.add_argument("--outtype", type=str, choices=["complet", "kaldi"])
  128 + parser_converter.add_argument("--outfile", type=str, required=True, help="")
  129 + parser_converter.set_defaults(which="converter")
  130 +
  131 +
111 132 # Parse
112 133 args = parser.parse_args()
113 134  
... ... @@ -116,7 +137,8 @@
116 137 "utt2char" : utt2char,
117 138 "char2utt": char2utt,
118 139 "wavscp": wavscp,
119   - "changelabels": changelabels
  140 + "changelabels": changelabels,
  141 + "converter": converter
120 142 })
121 143  
122 144 runner.run(args.which, args.__dict__, remove="which")