code: def make_labs(args):
      """Make lab file for datasets."""
  
      from espnet2.text.cleaner import TextCleaner
  
      if not args.text_cleaner:
          args.text_cleaner = None
  
      corpus_dir = Path(args.corpus_dir)
      cleaner = None
      if args.text_cleaner is not None:
          cleaner = TextCleaner(args.text_cleaner)
  
      frontend = None
      if args.g2p_model.startswith("pyopenjtalk"):
          frontend = get_jp_text
  
      for dset in args.data_sets.split():
          logging.info("Preparing data for %s", dset)
          dset: Path = Path("data") / dset
          # Generate directories according to spk2utt
          utt2spk = dict()
          with open(dset / "utt2spk") as reader:
              for line in reader:
                  utt, spk = line.strip().split(maxsplit=1)
                  utt2spk[utt] = spk
              for spk in set(utt2spk.values()):
                  (corpus_dir / spk).mkdir(parents=True, exist_ok=True)
  
          # Generate labs according to text file
          with open(dset / "text", encoding="utf-8") as reader:
              for line in reader:
                  utt, text = line.strip().split(maxsplit=1)
                  if cleaner is not None:
                      text = cleaner(text).lower()
                  else:
                      text = text.lower()
                  # Convert single quotes into double quotes
                  #   so that MFA doesn't confuse them with clitics.
                  # Find ' not preceded by a letter to the last ' not followed by a letter
                  text = re.sub(
                      r"(\W|^)'(\w[\w .,!?']*)'(\W|$)",
                      r'\1"\2"\3',
                      text,
                  )
  
                  # Remove braces because MFA interprets them as enclosing a single word
                  text = re.sub(r"[\{\}]", "", text)
  
                  # In case of frontend, preprocess data.
                  if frontend is not None:
                      text = frontend(text)
  
                  try:
                      spk = utt2spk[utt]
                      with open(
                          corpus_dir / spk / f"{utt}.lab",
                          "w",
                          encoding="utf-8",
                      ) as writer:
                          writer.write(text)
                  except KeyError:
                      logging.warning(
                          f"{utt} is in text file but not in utt2spk"
                      )
  
          # Generate wavs according to wav.scp and segment files
          if (dset / "segments").exists():
              wscp = (dset / "wav.scp").as_posix()
              segments = (dset / "segments").as_posix()
              with kaldiio.ReadHelper(
                  f"scp:{wscp}", segments=segments
              ) as reader:
                  for utt, (rate, array) in reader:
                      try:
                          spk = utt2spk[utt]
                          dst_file = (
                              corpus_dir / spk / f"{utt}.wav"
                          ).as_posix()
                          sf.write(dst_file, array, rate)
                      except KeyError:
                          logging.warning(
                              f"{utt} is in wav.scp file but not in utt2spk"
                          )
          else:
              with open(dset / "wav.scp") as reader:
                  for line in reader:
                      utt, src_file = line.strip().split(maxsplit=1)
                      src_file = os.path.abspath(src_file)
                      try:
                          spk = utt2spk[utt]
                          dst_file = corpus_dir / spk / f"{utt}.wav"
                          if src_file.endswith(".wav"):
                              # Create symlink
                              dst_file.symlink_to(src_file)
                          else:
                              # Create wav file
                              rate, array = kaldiio.load_mat(src_file)
                              sf.write(dst_file.as_posix(), array, rate)
                      except KeyError:
                          logging.warning(
                              f"{utt} is in wav.scp file but not in utt2spk"
                          )
      logging.info("Finished writing .lab files")
  
imports: import argparse
  import codecs
  import json
  import logging
  import os
  import re
  import sys
  import traceback
  from pathlib import Path
  from typing import Dict
  import kaldiio
  import soundfile
  from pyopenjtalk import run_frontend
  from espnet2.text.phoneme_tokenizer import PhonemeTokenizer
label_desc: Use image node_id 8 for calling a global function with example usage: make_labs(args) without return types