code: def prepare_metadata(
      rttm_file,
      save_dir,
      data_dir,
      filename,
      max_subseg_dur,
      overlap,
      mic_type,
  ):
      # Read RTTM, get unique meeting_IDs (from RTTM headers)
      # For each MeetingID. select that meetID -> merge -> subsegment -> json -> append
  
      # Read RTTM
      RTTM = []
      with open(rttm_file, "r") as f:
          for line in f:
              entry = line[:-1]
              RTTM.append(entry)
  
      spkr_info = filter(lambda x: x.startswith("SPKR-INFO"), RTTM)
      rec_ids = list(set([row.split(" ")[1] for row in spkr_info]))
      rec_ids.sort()  # sorting just to make JSON look in proper sequence
  
      # For each recording merge segments and then perform subsegmentation
      MERGED_SEGMENTS = []
      SUBSEGMENTS = []
      for rec_id in rec_ids:
          segs_iter = filter(
              lambda x: x.startswith("SPEAKER " + str(rec_id)), RTTM
          )
          gt_rttm_segs = [row.split(" ") for row in segs_iter]
  
          # Merge, subsegment and then convert to json format.
          merged_segs = merge_rttm_intervals(
              gt_rttm_segs
          )  # We lose speaker_ID after merging
          MERGED_SEGMENTS = MERGED_SEGMENTS + merged_segs
  
          # Divide segments into smaller sub-segments
          subsegs = get_subsegments(
              merged_segs, max_subseg_dur, overlap
          )
          SUBSEGMENTS = SUBSEGMENTS + subsegs
  
      # Write segment AND sub-segments (in RTTM format)
      segs_file = save_dir + "/" + filename + ".segments.rttm"
      subsegment_file = save_dir + "/" + filename + ".subsegments.rttm"
  
      with open(segs_file, "w") as f:
          for row in MERGED_SEGMENTS:
              line_str = " ".join(row)
              f.write("%s\n" % line_str)
  
      with open(subsegment_file, "w") as f:
          for row in SUBSEGMENTS:
              line_str = " ".join(row)
              f.write("%s\n" % line_str)
  
      # Create JSON from subsegments
      json_dict = {}
      for row in SUBSEGMENTS:
          rec_id = row[1]
          strt = str(round(float(row[3]), 4))
          end = str(round((float(row[3]) + float(row[4])), 4))
          subsegment_ID = rec_id + "_" + strt + "_" + end
          dur = row[4]
          start_sample = int(float(strt) * SAMPLERATE)
          end_sample = int(float(end) * SAMPLERATE)
  
          # If multi-mic audio is selected
          if mic_type == "Array1":
              wav_file_base_path = (
                  data_dir
                  + "/"
                  + rec_id
                  + "/audio/"
                  + rec_id
                  + "."
                  + mic_type
                  + "-"
              )
  
              f = []  # adding all 8 mics
              for i in range(8):
                  f.append(
                      wav_file_base_path + str(i + 1).zfill(2) + ".wav"
                  )
              audio_files_path_list = f
  
              # Note: key "files" with 's' is used for multi-mic
              json_dict[subsegment_ID] = {
                  "wav": {
                      "files": audio_files_path_list,
                      "duration": float(dur),
                      "start": int(start_sample),
                      "stop": int(end_sample),
                  },
              }
          else:
              # Single mic audio
              wav_file_path = (
                  data_dir
                  + "/"
                  + rec_id
                  + "/audio/"
                  + rec_id
                  + "."
                  + mic_type
                  + ".wav"
              )
  
              # Note: key "file" without 's' is used for single-mic
              json_dict[subsegment_ID] = {
                  "wav": {
                      "file": wav_file_path,
                      "duration": float(dur),
                      "start": int(start_sample),
                      "stop": int(end_sample),
                  },
              }
  
      out_json_file = (
          save_dir + "/" + filename + "." + mic_type + ".subsegs.json"
      )
      with open(out_json_file, mode="w") as json_f:
          json.dump(json_dict, json_f, indent=2)
  
      msg = "%s JSON prepared" % (out_json_file)
      logger.debug(msg)
  
file_path: speechbrain/recipes/AMI/Diarization/ami_prepare.py
imports: import os
  import logging
  import xml.etree.ElementTree
  import glob
  import json
  from ami_splits import get_AMI_split
  from speechbrain.dataio.dataio import load_pkl, save_pkl
label_desc: Use image node_id 7 for calling a global function with example usage: prepare_metadata(rttm_file, save_dir, data_dir, filename, max_subseg_dur, overlap, mic_type) without return types