code: def prepare_chime6(
      corpus_dir: Pathlike,
      output_dir: Optional[Pathlike] = None,
      dset_part: str = "dev",
      mic: str = "mdm",
      normalize_text: str = "chime6",
      json_dir: Optional[
          Pathlike
      ] = None,  # alternative annotation e.g. from non-oracle diarization
      ignore_shorter: Optional[float] = 0.2,
  ) -> Dict[str, Dict[str, Union[RecordingSet, SupervisionSet]]]:
      """
      Returns the manifests which consist of the Recordings and Supervisions
      :param corpus_dir: Pathlike, the path of CHiME-6 main directory.
      :param output_dir: Pathlike, the path where to write the manifests.
      :param mic: str, the microphone type to use,
      choose from "ihm" (close-talk) or "mdm"
          (multi-microphone array) settings.
          For MDM, there are 6 array devices with 4
          channels each, so the resulting recordings will have 24 channels.
      :param normalize_text: str, the text normalization method,
      choose from "chime6" or "chime7".
      """
      import soundfile as sf
  
      assert mic in ["ihm", "mdm"], "mic must be either 'ihm' or 'mdm'."
      txt_normalization = choose_txt_normalization(normalize_text)
      transcriptions_dir = (
          os.path.join(corpus_dir, "transcriptions_scoring")
          if json_dir is None
          else json_dir
      )
  
      if output_dir:
          output_dir = Path(output_dir)
          output_dir.mkdir(parents=True, exist_ok=True)
  
      all_sessions = [
          Path(x).stem
          for x in glob.glob(
              os.path.join(transcriptions_dir, dset_part, "*.json")
          )
      ]
      manifests = defaultdict(dict)
      recordings = []
      supervisions = []
      # First we create the recordings
      if mic == "ihm":
          for session in all_sessions:
              audio_paths = [
                  Path(x)
                  for x in glob.glob(
                      os.path.join(
                          corpus_dir,
                          "audio",
                          dset_part,
                          f"{session}_P*.wav",
                      )
                  )
              ]
              if len(audio_paths) == 0:
                  raise FileNotFoundError(
                      f"No audio found for session {session} in {dset_part} set."
                  )
              sources = []
              # NOTE: Each headset microphone is binaural
              for idx, audio_path in enumerate(audio_paths):
                  channels = [0, 1]  # if dset_part == "train" else [0]
                  sources.append(
                      AudioSource(
                          type="file",
                          channels=channels,
                          source=str(audio_path),
                      )
                  )
                  spk_id = audio_path.stem.split("_")[1]
                  audio_sf = sf.SoundFile(str(audio_paths[0]))
                  recordings.append(
                      Recording(
                          id=session + f"_{spk_id}",
                          sources=sources,
                          sampling_rate=int(audio_sf.samplerate),
                          num_samples=audio_sf.frames,
                          duration=audio_sf.frames
                          / audio_sf.samplerate,
                      )
                  )
      else:
          for session in all_sessions:
              audio_paths = [
                  Path(x)
                  for x in glob.glob(
                      os.path.join(
                          corpus_dir,
                          "audio",
                          dset_part,
                          f"{session}_U*.wav",
                      )
                  )
              ]
              # discard some arrays because their
              # files length is a lot different and causes GSS to fail
              if session == "S12":
                  audio_paths = [
                      x
                      for x in audio_paths
                      if not Path(x).stem.startswith("S12_U05")
                  ]
              elif session == "S24":
                  audio_paths = [
                      x
                      for x in audio_paths
                      if not Path(x).stem.startswith("S24_U06")
                  ]
              elif session == "S18":
                  audio_paths = [
                      x
                      for x in audio_paths
                      if not Path(x).stem.startswith("S18_U06")
                  ]
              sources = []
              for idx, audio_path in enumerate(sorted(audio_paths)):
                  sources.append(
                      AudioSource(
                          type="file",
                          channels=[idx],
                          source=str(audio_path),
                      )
                  )
  
              audio_sf = sf.SoundFile(str(audio_paths[0]))
              recordings.append(
                  Recording(
                      id=session,
                      sources=sources,
                      sampling_rate=int(audio_sf.samplerate),
                      num_samples=audio_sf.frames,
                      duration=audio_sf.frames / audio_sf.samplerate,
                  )
              )
      recordings = RecordingSet.from_recordings(recordings)
  
      def _get_channel(session, dset_part):
          if mic == "ihm":
              return [0, 1] if dset_part == "train" else [0]
          else:
              recording = recordings[session]
              return list(range(recording.num_channels))
  
      # Then we create the supervisions
      for session in all_sessions:
          with open(
              os.path.join(
                  transcriptions_dir, dset_part, f"{session}.json"
              )
          ) as f:
              transcript = json.load(f)
              for idx, segment in enumerate(transcript):
                  spk_id = segment["speaker"]
                  channel = _get_channel(session, dset_part)
                  start = float(segment["start_time"])
                  end = float(segment["end_time"])
                  if (
                      ignore_shorter is not None
                      and (end - start) < ignore_shorter
                  ):
                      print(
                          "Ignored segment session {} speaker "
                          "{} seconds {} to {}, because shorter than {}"
                          "".format(
                              session,
                              spk_id,
                              start,
                              end,
                              ignore_shorter,
                          )
                      )
                      continue
                  if (
                      start >= end
                  ):  # some segments may have negative duration
                      continue
  
                  ex_id = (
                      f"{spk_id}_chime6_{session}_{idx}-"
                      f"{round(100*start):06d}_{round(100*end):06d}-{mic}"
                  )
  
                  if "words" not in segment.keys():
                      assert json_dir is not None
                      segment["words"] = "placeholder"
  
                  supervisions.append(
                      SupervisionSegment(
                          id=ex_id,
                          recording_id=session
                          if mic == "mdm"
                          else session + f"_{spk_id}",
                          start=start,
                          duration=add_durations(
                              end, -start, sampling_rate=16000
                          ),
                          channel=channel,
                          text=txt_normalization(segment["words"]),
                          language="English",
                          speaker=spk_id,
                      )
                  )
  
      supervisions = SupervisionSet.from_segments(supervisions)
      recording_set, supervision_set = fix_manifests(
          recordings=recordings, supervisions=supervisions
      )
      # Fix manifests
      validate_recordings_and_supervisions(
          recording_set, supervision_set
      )
      supervision_set.to_file(
          os.path.join(
              output_dir,
              f"chime6-{mic}_supervisions_{dset_part}.jsonl.gz",
          )
      )
      recording_set.to_file(
          os.path.join(
              output_dir,
              f"chime6-{mic}_recordings_{dset_part}.jsonl.gz",
          )
      )
      manifests[dset_part] = {
          "recordings": recording_set,
          "supervisions": supervision_set,
      }
      return manifests
  
file_path: espnet/egs2/chime7_task1/asr1/local/get_lhotse_manifests.py
imports: import argparse
  import glob
  import json
  import os.path
  from collections import defaultdict
  from pathlib import Path
  from typing import Dict, Optional, Union
  import lhotse
  import soundfile
  from gen_task1_data import choose_txt_normalization
  from lhotse import fix_manifests, validate_recordings_and_supervisions
  from lhotse.audio import AudioSource, Recording, RecordingSet
  from lhotse.supervision import SupervisionSegment, SupervisionSet
  from lhotse.utils import Pathlike, add_durations, safe_extract, urlretrieve_progress
label_desc: Use image node_id 1 for calling a global function with example usage: prepare_chime6(corpus_dir, output_dir, dset_part, mic, normalize_text, json_dir, ignore_shorter) and returns: manifests, unknown, list