code: def prep_chime6(
      root_dir, out_dir, scoring_txt_normalization="chime7", eval_opt=0
  ):
      scoring_txt_normalization = choose_txt_normalization(
          scoring_txt_normalization
      )
  
      def normalize_chime6(annotation, txt_normalizer, eval_opt=False):
          annotation_scoring = []
          for ex in annotation:
              ex["start_time"] = "{:.3f}".format(
                  TimeFormatConverter.hms_to_seconds(ex["start_time"])
              )
              ex["end_time"] = "{:.3f}".format(
                  TimeFormatConverter.hms_to_seconds(ex["end_time"])
              )
              if eval_opt > 0 and "ref" in ex.keys():
                  del ex["ref"]
                  del ex["location"]
                  # cannot be used in inference
              ex_scoring = deepcopy(ex)
              ex_scoring["words"] = txt_normalizer(ex["words"])
              if eval_opt == 1:
                  ex["words"] = "placeholder"
              if len(ex_scoring["words"]) > 0:
                  if eval_opt == 1:
                      ex_scoring["words"] = "placeholder"
                  annotation_scoring.append(ex_scoring)
              # if empty remove segment from scoring
          return annotation, annotation_scoring
  
      splits = ["train", "dev", "eval"]
      # pre-create all destination folders
      for split in splits:
          Path(os.path.join(out_dir, "audio", split)).mkdir(
              parents=True, exist_ok=True
          )
          Path(os.path.join(out_dir, "transcriptions", split)).mkdir(
              parents=True, exist_ok=True
          )
          Path(
              os.path.join(out_dir, "transcriptions_scoring", split)
          ).mkdir(parents=True, exist_ok=True)
          Path(os.path.join(out_dir, "uem", split)).mkdir(
              parents=True, exist_ok=True
          )
  
      all_uem = {k: [] for k in splits}
      for split in splits:
          json_dir = os.path.join(root_dir, "transcriptions", split)
          ann_json = glob.glob(os.path.join(json_dir, "*.json"))
          assert len(ann_json) > 0, (
              "CHiME-6 JSON annotation was not found in {}, please check if "
              "CHiME-6 data was downloaded correctly and the CHiME-6 main dir "
              "path is set correctly".format(json_dir)
          )
          # we also create audio files symlinks here
          audio_files = glob.glob(
              os.path.join(root_dir, "audio", split, "*.wav")
          )
          sess2audio = {}
          for x in audio_files:
              session_name = Path(x).stem.split("_")[0]
              if (
                  Path(x).stem.split("_")[-1].startswith("P")
                  and eval_opt > 0
              ):
                  continue
              if session_name not in sess2audio:
                  sess2audio[session_name] = [x]
              else:
                  sess2audio[session_name].append(x)
  
          # for each json file
  
          for j_file in ann_json:
              with open(j_file, "r") as f:
                  annotation = json.load(f)
              sess_name = Path(j_file).stem
  
              annotation, scoring_annotation = normalize_chime6(
                  annotation, scoring_txt_normalization, eval_opt
              )
  
              tsplit = None  # find chime7 destination split
              for k in ["train", "dev", "eval"]:
                  if sess_name in chime6_map[k]:
                      tsplit = k
  
              # create symlinks too
              if eval_opt == 0 and tsplit == "eval":
                  continue
              if eval_opt > 0 and tsplit != "eval":
                  continue
  
              [
                  os.symlink(
                      x,
                      os.path.join(
                          out_dir, "audio", tsplit, Path(x).stem
                      )
                      + ".wav",
                  )
                  for x in sess2audio[sess_name]
              ]
  
              with open(
                  os.path.join(
                      out_dir,
                      "transcriptions",
                      tsplit,
                      sess_name + ".json",
                  ),
                  "w",
              ) as f:
                  json.dump(annotation, f, indent=4)
              # retain original annotation but dump also the scoring one
              with open(
                  os.path.join(
                      out_dir,
                      "transcriptions_scoring",
                      tsplit,
                      sess_name + ".json",
                  ),
                  "w",
              ) as f:
                  json.dump(scoring_annotation, f, indent=4)
  
              first = sorted(
                  [float(x["start_time"]) for x in annotation]
              )[0]
              end = max(
                  [
                      sf.SoundFile(x).frames
                      for x in sess2audio[sess_name]
                  ]
              )
              c_uem = "{} 1 {} {}\n".format(
                  sess_name,
                  "{:.3f}".format(float(first)),
                  "{:.3f}".format(end / 16000),
              )
              all_uem[tsplit].append(c_uem)
  
      for k in all_uem.keys():
          c_uem = all_uem[k]
          if len(c_uem) > 0:
              c_uem = sorted(c_uem)
              with open(
                  os.path.join(out_dir, "uem", k, "all.uem"), "w"
              ) as f:
                  f.writelines(c_uem)
  
file_path: espnet/egs2/chime7_task1/asr1/local/gen_task1_data.py
imports: import argparse
  import glob
  import json
  import os
  from copy import deepcopy
  from datetime import datetime
  from pathlib import Path
  import jiwer
  import soundfile
  from jiwer.transforms import RemoveKaldiNonWords
  from lhotse.recipes.chime6 import TimeFormatConverter, normalize_text_chime6
label_desc: Use image node_id 4 for calling a global function with example usage: prep_chime6(root_dir, out_dir, scoring_txt_normalization, eval_opt) and returns: annotation,  annotation_scoring