code: def parse2json(asr_hyp, output_name, sess_regex="[^-]*"):
      with open(asr_hyp, "r") as f:
          hyps = f.readlines()
      hyps = [x.rstrip("\n") for x in hyps]
      to_json = []
      # session, spk_id, start and stop in seconds and words
      for h in hyps:
          utt_id = h.split(" ")[0]
          predictions = " ".join(h.split(" ")[1:])
          spk_id = utt_id.split("_")[0]
  
          rest = "_".join(utt_id.split("_")[1:])
          # mixer6 regex: ([0-9]+_[0-9]+_LDC_[0-9]+)
          session_id = re.search(sess_regex, rest).group()
          start, stop = (
              re.search("-([0-9]*_[0-9]*)", rest)
              .group()
              .lstrip("-")
              .split("_")
          )
          start = float(start) / 100
          stop = float(stop) / 100
  
          c_entry = {
              "words": predictions,
              "speaker": spk_id,
              "session_id": session_id,
              "start_time": str(start),
              "end_time": str(stop),
          }
          to_json.append(c_entry)
  
      # sort by starting time
      Path(output_name).mkdir(parents=True, exist_ok=True)
      to_json = sorted(
          to_json,
          key=lambda x: "{}_{}".format(x["speaker"], x["start_time"]),
      )
      with open(output_name + ".json", "w") as f:
          json.dump(to_json, f, indent=4)
  
      # write also to stm for asclite
  
      stm = []
      for seg in to_json:
          c_line = "{} A {} {} {} {}\n".format(
              seg["session_id"],
              seg["speaker"],
              seg["start_time"],
              seg["end_time"],
              seg["words"],
          )
          stm.append(c_line)
  
      with open(output_name + ".stm", "w") as f:
          f.writelines(stm)
  
imports: import argparse
  import json
  import os
  import re
  from pathlib import Path
label_desc: Use image node_id 1 for calling a global function with example usage: parse2json(asr_hyp, output_name, sess_regex) without return types