code: def convert_rttm_text(
      path: Union[Path, str],
      wavscp_path: Union[Path, str],
      sampling_rate: int,
      output_path: Union[Path, str],
  ) -> None:
      """Convert a RTTM file
  
      Note: only support speaker information now
      """
  
      output_handler = Path(
          os.path.join(output_path, "espnet_rttm")
      ).open("w", encoding="utf-8")
  
      assert check_argument_types()
      utt_ids = set()
      with Path(path).open("r", encoding="utf-8") as f:
          for linenum, line in enumerate(f, 1):
              sps = re.split(" +", line.rstrip())
  
              # RTTM format must have exactly 9 fields
              assert (
                  len(sps) == 9
              ), "{} does not have exactly 9 fields".format(path)
              (
                  label_type,
                  utt_id,
                  channel,
                  start,
                  duration,
                  _,
                  _,
                  spk_id,
                  _,
              ) = sps
  
              # Only support speaker label now
              assert label_type == "SPEAKER"
  
              utt_ids.add(utt_id)
              start = int(np.rint(float(start) * sampling_rate))
              end = start + int(
                  np.rint(float(duration) * sampling_rate)
              )
  
              output_handler.write(
                  "{} {} {} {} {} <NA> <NA> {} <NA>\n".format(
                      label_type, utt_id, channel, start, end, spk_id
                  )
              )
  
      with Path(wavscp_path).open("r", encoding="utf-8") as f:
          for linenum, line in enumerate(f, 1):
              sps = re.split("[ \t]+", line.rstrip())
              utt_id, wav_path = sps
              assert (
                  utt_id in utt_ids
              ), "{} is not in corresponding rttm {}".foramt(
                  utt_id, path
              )
  
              sf = soundfile.SoundFile(wav_path)
              assert sf.samplerate == sampling_rate
              output_handler.write(
                  (
                      "{} {} <NA> <NA> {} <NA> <NA> <NA> <NA>\n".format(
                          "END", utt_id, sf.frames
                      )
                  )
              )
  
      output_handler.close()
  
file_path: espnet/egs2/swbd_sentiment/asr1/pyscripts/utils/convert_rttm.py
imports: import argparse
  import collections.abc
  import logging
  import os
  import re
  from pathlib import Path
  from typing import Union
  import humanfriendly
  import numpy
  import soundfile
  from typeguard import check_argument_types
  from espnet2.utils.types import str_or_int
label_desc: Use image node_id 1 for calling a global function with example usage: convert_rttm_text(path, wavscp_path, sampling_rate, output_path) without return types