class_docstr: Align text to audio using CTC segmentation.
  
  Usage:
      Initialize with given ASR model and parameters.
      If needed, parameters for CTC segmentation can be set with ``set_config(·)``.
      Then call the instance as function to align text within an audio file.
  
  Example:
      >>> # example file included in the ESPnet repository
      >>> import soundfile
      >>> speech, fs = soundfile.read("test_utils/ctc_align_test.wav")
      >>> # load an ASR model
      >>> from espnet_model_zoo.downloader import ModelDownloader
      >>> d = ModelDownloader()
      >>> wsjmodel = d.download_and_unpack( "kamo-naoyuki/wsj" )
      >>> # Apply CTC segmentation
      >>> aligner = CTCSegmentation( **wsjmodel )
      >>> text=["utt1 THE SALE OF THE HOTELS", "utt2 ON PROPERTY MANAGEMENT"]
      >>> aligner.set_config( gratis_blank=True )
      >>> segments = aligner( speech, text, fs=fs )
      >>> print( segments )
      utt1 utt 0.27 1.72 -0.1663 THE SALE OF THE HOTELS
      utt2 utt 4.54 6.10 -4.9646 ON PROPERTY MANAGEMENT
  
  On multiprocessing:
      To parallelize the computation with multiprocessing, these three steps
      can be separated:
      (1) ``get_lpz``: obtain the lpz,
      (2) ``prepare_segmentation_task``: prepare the task, and
      (3) ``get_segments``: perform CTC segmentation.
      Note that the function `get_segments` is a staticmethod and therefore
      independent of an already initialized CTCSegmentation object.
  
  References:
      CTC-Segmentation of Large Corpora for German End-to-end Speech Recognition
      2020, Kürzinger, Winkelbauer, Li, Watzel, Rigoll
      https://arxiv.org/abs/2007.09127
  
  More parameters are described in https://github.com/lumaku/ctc-segmentation
docstr: Preprocess text, and gather text and lpz into a task object.
  
  Text is pre-processed and tokenized depending on configuration.
  If ``speech_len`` is given, the timing configuration is updated.
  Text, lpz, and configuration is collected in a CTCSegmentationTask
  object. The resulting object can be serialized and passed in a
  multiprocessing computation.
  
  A minimal amount of text processing is done, i.e., splitting the
  utterances in ``text`` into a list and applying ``text_cleaner``.
  It is recommended that you normalize the text beforehand, e.g.,
  change numbers into their spoken equivalent word, remove special
  characters, and convert UTF-8 characters to chars corresponding to
  your ASR model dictionary.
  
  The text is tokenized based on the ``text_converter`` setting:
  
  The "tokenize" method is more efficient and the easiest for models
  based on latin or cyrillic script that only contain the main chars,
  ["a", "b", ...] or for Japanese or Chinese ASR models with ~3000
  short Kanji / Hanzi tokens.
  
  The "classic" method improves the the accuracy of the alignments
  for models that contain longer tokens, but with a greater complexity
  for computation. The function scans for partial tokens which may
  improve time resolution.
  For example, the word "▁really" will be broken down into
  ``['▁', '▁r', '▁re', '▁real', '▁really']``. The alignment will be
  based on the most probable activation sequence given by the network.
  
  Args:
      text: List or multiline-string with utterance ground truths.
      lpz: Log CTC posterior probabilities obtained from the CTC-network;
          numpy array shaped as ( <time steps>, <classes> ).
      name: Audio file name. Choose a unique name, or the original audio
          file name, to distinguish multiple audio files. Default: None.
      speech_len: Number of sample points. If given, the timing
          configuration is automatically derived from length of fs, length
          of speech and length of lpz. If None is given, make sure the
          timing parameters are correct, see time_stamps for reference!
          Default: None.
  
  Returns:
      task: CTCSegmentationTask object that can be passed to
          ``get_segments()`` in order to obtain alignments.
docstr_tok: ["Preprocess","text",",","and","gather","text","and","lpz","into","a","task","object",".","Text","is","pre-processed","and","tokenized","depending","on","configuration",".","If","``","speech_len","``","is","given",",","the","timing","configuration","is","updated",".","Text",",","lpz",",","and","configuration","is","collected","in","a","CTCSegmentationTask","object",".","The","resulting","object","can","be","serialized","and","passed","in","a","multiprocessing","computation",".","A","minimal","amount","of","text","processing","is","done",",","i.e.",",","splitting","the","utterances","in","``","text","``","into","a","list","and","applying","``","text_cleaner","``",".","It","is","recommended","that","you","normalize","the","text","beforehand",",","e.g.",",","change","numbers","into","their","spoken","equivalent","word",",","remove","special","characters",",","and","convert","UTF-8","characters","to","chars","corresponding","to","your","ASR","model","dictionary",".","The","text","is","tokenized","based","on","the","``","text_converter","``","setting",":","The","``","tokenize","''","method","is","more","efficient","and","the","easiest","for","models","based","on","latin","or","cyrillic","script","that","only","contain","the","main","chars",",","[","``","a","''",",","``","b","''",",","...","]","or","for","Japanese","or","Chinese","ASR","models","with","~3000","short","Kanji","\/","Hanzi","tokens",".","The","``","classic","''","method","improves","the","the","accuracy","of","the","alignments","for","models","that","contain","longer","tokens",",","but","with","a","greater","complexity","for","computation",".","The","function","scans","for","partial","tokens","which","may","improve","time","resolution",".","For","example",",","the","word","``","\u2581really","''","will","be","broken","down","into","``","[","'\u2581","'",",","'\u2581r","'",",","'\u2581re","'",",","'\u2581real","'",",","'\u2581really","'","]","``",".","The","alignment","will","be","based","on","the","most","probable","activation","sequence","given","by","the","network",".","Args",":","text",":","List","or","multiline-string","with","utterance","ground","truths",".","lpz",":","Log","CTC","posterior","probabilities","obtained","from","the","CTC-network",";","numpy","array","shaped","as","(","<","time","steps",">",",","<","classes",">",")",".","name",":","Audio","file","name",".","Choose","a","unique","name",",","or","the","original","audio","file","name",",","to","distinguish","multiple","audio","files",".","Default",":","None",".","speech_len",":","Number","of","sample","points",".","If","given",",","the","timing","configuration","is","automatically","derived","from","length","of","fs",",","length","of","speech","and","length","of","lpz",".","If","None","is","given",",","make","sure","the","timing","parameters","are","correct",",","see","time_stamps","for","reference","!","Default",":","None",".","Returns",":","task",":","CTCSegmentationTask","object","that","can","be","passed","to","``","get_segments","(",")","``","in","order","to","obtain","alignments","."]
code: def prepare_segmentation_task(
      self, text, lpz, name=None, speech_len=None
  ):
      """Preprocess text, and gather text and lpz into a task object.
  
      Text is pre-processed and tokenized depending on configuration.
      If ``speech_len`` is given, the timing configuration is updated.
      Text, lpz, and configuration is collected in a CTCSegmentationTask
      object. The resulting object can be serialized and passed in a
      multiprocessing computation.
  
      A minimal amount of text processing is done, i.e., splitting the
      utterances in ``text`` into a list and applying ``text_cleaner``.
      It is recommended that you normalize the text beforehand, e.g.,
      change numbers into their spoken equivalent word, remove special
      characters, and convert UTF-8 characters to chars corresponding to
      your ASR model dictionary.
  
      The text is tokenized based on the ``text_converter`` setting:
  
      The "tokenize" method is more efficient and the easiest for models
      based on latin or cyrillic script that only contain the main chars,
      ["a", "b", ...] or for Japanese or Chinese ASR models with ~3000
      short Kanji / Hanzi tokens.
  
      The "classic" method improves the the accuracy of the alignments
      for models that contain longer tokens, but with a greater complexity
      for computation. The function scans for partial tokens which may
      improve time resolution.
      For example, the word "▁really" will be broken down into
      ``['▁', '▁r', '▁re', '▁real', '▁really']``. The alignment will be
      based on the most probable activation sequence given by the network.
  
      Args:
          text: List or multiline-string with utterance ground truths.
          lpz: Log CTC posterior probabilities obtained from the CTC-network;
              numpy array shaped as ( <time steps>, <classes> ).
          name: Audio file name. Choose a unique name, or the original audio
              file name, to distinguish multiple audio files. Default: None.
          speech_len: Number of sample points. If given, the timing
              configuration is automatically derived from length of fs, length
              of speech and length of lpz. If None is given, make sure the
              timing parameters are correct, see time_stamps for reference!
              Default: None.
  
      Returns:
          task: CTCSegmentationTask object that can be passed to
              ``get_segments()`` in order to obtain alignments.
      """
      config = self.config
      # Update timing parameters, if needed
      if speech_len is not None:
          lpz_len = lpz.shape[0]
          timing_cfg = self.get_timing_config(speech_len, lpz_len)
          config.set(**timing_cfg)
      # `text` is needed in the form of a list.
      utt_ids, text = self._split_text(text)
      # Obtain utterance & label sequence from text
      if self.text_converter == "tokenize":
          # list of str --tokenize--> list of np.array
          token_list = [
              self.preprocess_fn("<dummy>", {"text": utt})["text"]
              for utt in text
          ]
          # filter out any instances of the <unk> token
          unk = config.char_list.index("<unk>")
          token_list = [utt[utt != unk] for utt in token_list]
          ground_truth_mat, utt_begin_indices = prepare_token_list(
              config, token_list
          )
      else:
          assert self.text_converter == "classic"
          text = [self.preprocess_fn.text_cleaner(utt) for utt in text]
          token_list = [
              "".join(self.preprocess_fn.tokenizer.text2tokens(utt))
              for utt in text
          ]
          token_list = [utt.replace("<unk>", "") for utt in token_list]
          ground_truth_mat, utt_begin_indices = prepare_text(
              config, token_list
          )
      task = CTCSegmentationTask(
          config=config,
          name=name,
          text=text,
          ground_truth_mat=ground_truth_mat,
          utt_begin_indices=utt_begin_indices,
          utt_ids=utt_ids,
          lpz=lpz,
      )
      return task
  
imports: import argparse
  import logging
  import sys
  from pathlib import Path
  from typing import List, Optional, TextIO, Union
  import numpy
  import soundfile
  import torch
  from ctc_segmentation import CtcSegmentationParameters, ctc_segmentation, determine_utterance_segments, prepare_text, prepare_token_list
  from typeguard import check_argument_types, check_return_type
  from espnet2.tasks.asr import ASRTask
  from espnet2.torch_utils.device_funcs import to_device
  from espnet2.utils import config_argparse
  from espnet2.utils.types import str2bool, str_or_none
  from espnet.utils.cli_utils import get_commandline_args
label_desc: Use image node_id 7 for calling the CTCSegmentation obj's underlying member method code with example usage: obj.prepare_segmentation_task(text, lpz, name, speech_len) and returns: task