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.
  
  Attributes
  ---------
  asr_model : EncoderDecoderASR
      Speechbrain ASR interface. This requires a model that has a
      trained CTC layer for inference. It is better to use a model with
      single-character tokens to get a better time resolution.
      Please note that the inference complexity with Transformer models
      usually increases quadratically with audio length.
      It is therefore recommended to use RNN-based models, if available.
  kaldi_style_text : bool
      A kaldi-style text file includes the name of the
      utterance at the start of the line. If True, the utterance name
      is expected as first word at each line. If False, utterance
      names are automatically generated. Set this option according to
      your input data. Default: True.
  text_converter : str
      How CTC segmentation handles text.
      "tokenize": Use the ASR model tokenizer to tokenize the text.
      "classic": The text is preprocessed as text pieces which takes
      token length into account. If the ASR model has longer tokens,
      this option may yield better results. Default: "tokenize".
  time_stamps : str
      Choose the method how the time stamps are
      calculated. While "fixed" and "auto" use both the sample rate,
      the ratio of samples to one frame is either automatically
      determined for each inference or fixed at a certain ratio that
      is initially determined by the module, but can be changed via
      the parameter ``samples_to_frames_ratio``. Recommended for
      longer audio files: "auto".
  **ctc_segmentation_args
      Parameters for CTC segmentation.
      The full list of parameters is found in ``set_config``.
  
  Example
  -------
      >>> # using example file included in the SpeechBrain repository
      >>> from speechbrain.inference.ASR import EncoderDecoderASR
      >>> from speechbrain.alignment.ctc_segmentation import CTCSegmentation
      >>> # load an ASR model
      >>> pre_trained = "speechbrain/asr-transformer-transformerlm-librispeech"
      >>> asr_model = EncoderDecoderASR.from_hparams(source=pre_trained)  # doctest: +SKIP
      >>> aligner = CTCSegmentation(asr_model, kaldi_style_text=False)  # doctest: +SKIP
      >>> # load data
      >>> audio_path = "tests/samples/single-mic/example1.wav"
      >>> text = ["THE BIRCH CANOE", "SLID ON THE", "SMOOTH PLANKS"]
      >>> segments = aligner(audio_path, text, name="example1")  # doctest: +SKIP
  
  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 obj́ect.
  
  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: Set CTC segmentation parameters.
  
  Parameters for timing
  ---------------------
  time_stamps : str
      Select method how CTC index duration is estimated, and
      thus how the time stamps are calculated.
  fs : int
      Sample rate. Usually derived from ASR model; use this parameter
      to overwrite the setting.
  samples_to_frames_ratio : float
      If you want to directly determine the
      ratio of samples to CTC frames, set this parameter, and
      set ``time_stamps`` to "fixed".
      Note: If you want to calculate the time stamps from a model
      with fixed subsampling, set this parameter to:
      ``subsampling_factor * frame_duration / 1000``.
  
  Parameters for text preparation
  -------------------------------
  set_blank : int
      Index of blank in token list. Default: 0.
  replace_spaces_with_blanks : bool
      Inserts blanks between words, which is
      useful for handling long pauses between words. Only used in
      ``text_converter="classic"`` preprocessing mode. Default: False.
  kaldi_style_text : bool
      Determines whether the utterance name is expected
      as fist word of the utterance. Set at module initialization.
  text_converter : str
      How CTC segmentation handles text.
      Set at module initialization.
  
  Parameters for alignment
  ------------------------
  min_window_size : int
      Minimum number of frames considered for a single
      utterance. The current default value of 8000 corresponds to
      roughly 4 minutes (depending on ASR model) and should be OK in
      most cases. If your utterances are further apart, increase
      this value, or decrease it for smaller audio files.
  max_window_size : int
      Maximum window size. It should not be necessary
      to change this value.
  gratis_blank : bool
      If True, the transition cost of blank is set to zero.
      Useful for long preambles or if there are large unrelated segments
      between utterances. Default: False.
  
  Parameters for calculation of confidence score
  ----------------------------------------------
  scoring_length : int
      Block length to calculate confidence score. The
      default value of 30 should be OK in most cases.
      30 corresponds to roughly 1-2s of audio.
docstr_tok: ["Set","CTC","segmentation","parameters",".","Parameters","for","timing","--","--","--","--","--","--","--","--","--","--","-","time_stamps",":","str","Select","method","how","CTC","index","duration","is","estimated",",","and","thus","how","the","time","stamps","are","calculated",".","fs",":","int","Sample","rate",".","Usually","derived","from","ASR","model",";","use","this","parameter","to","overwrite","the","setting",".","samples_to_frames_ratio",":","float","If","you","want","to","directly","determine","the","ratio","of","samples","to","CTC","frames",",","set","this","parameter",",","and","set","``","time_stamps","``","to","``","fixed","''",".","Note",":","If","you","want","to","calculate","the","time","stamps","from","a","model","with","fixed","subsampling",",","set","this","parameter","to",":","``","subsampling_factor","*","frame_duration","\/","1000","``",".","Parameters","for","text","preparation","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","-","set_blank",":","int","Index","of","blank","in","token","list",".","Default",":","0.","replace_spaces_with_blanks",":","bool","Inserts","blanks","between","words",",","which","is","useful","for","handling","long","pauses","between","words",".","Only","used","in","``","text_converter=","''","classic","''","``","preprocessing","mode",".","Default",":","False",".","kaldi_style_text",":","bool","Determines","whether","the","utterance","name","is","expected","as","fist","word","of","the","utterance",".","Set","at","module","initialization",".","text_converter",":","str","How","CTC","segmentation","handles","text",".","Set","at","module","initialization",".","Parameters","for","alignment","--","--","--","--","--","--","--","--","--","--","--","--","min_window_size",":","int","Minimum","number","of","frames","considered","for","a","single","utterance",".","The","current","default","value","of","8000","corresponds","to","roughly","4","minutes","(","depending","on","ASR","model",")","and","should","be","OK","in","most","cases",".","If","your","utterances","are","further","apart",",","increase","this","value",",","or","decrease","it","for","smaller","audio","files",".","max_window_size",":","int","Maximum","window","size",".","It","should","not","be","necessary","to","change","this","value",".","gratis_blank",":","bool","If","True",",","the","transition","cost","of","blank","is","set","to","zero",".","Useful","for","long","preambles","or","if","there","are","large","unrelated","segments","between","utterances",".","Default",":","False",".","Parameters","for","calculation","of","confidence","score","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","scoring_length",":","int","Block","length","to","calculate","confidence","score",".","The","default","value","of","30","should","be","OK","in","most","cases",".","30","corresponds","to","roughly","1-2s","of","audio","."]
code: def set_config(
      self,
      time_stamps: Optional[str] = None,
      fs: Optional[int] = None,
      samples_to_frames_ratio: Optional[float] = None,
      set_blank: Optional[int] = None,
      replace_spaces_with_blanks: Optional[bool] = None,
      kaldi_style_text: Optional[bool] = None,
      text_converter: Optional[str] = None,
      gratis_blank: Optional[bool] = None,
      min_window_size: Optional[int] = None,
      max_window_size: Optional[int] = None,
      scoring_length: Optional[int] = None,
  ):
      """Set CTC segmentation parameters.
  
      Parameters for timing
      ---------------------
      time_stamps : str
          Select method how CTC index duration is estimated, and
          thus how the time stamps are calculated.
      fs : int
          Sample rate. Usually derived from ASR model; use this parameter
          to overwrite the setting.
      samples_to_frames_ratio : float
          If you want to directly determine the
          ratio of samples to CTC frames, set this parameter, and
          set ``time_stamps`` to "fixed".
          Note: If you want to calculate the time stamps from a model
          with fixed subsampling, set this parameter to:
          ``subsampling_factor * frame_duration / 1000``.
  
      Parameters for text preparation
      -------------------------------
      set_blank : int
          Index of blank in token list. Default: 0.
      replace_spaces_with_blanks : bool
          Inserts blanks between words, which is
          useful for handling long pauses between words. Only used in
          ``text_converter="classic"`` preprocessing mode. Default: False.
      kaldi_style_text : bool
          Determines whether the utterance name is expected
          as fist word of the utterance. Set at module initialization.
      text_converter : str
          How CTC segmentation handles text.
          Set at module initialization.
  
      Parameters for alignment
      ------------------------
      min_window_size : int
          Minimum number of frames considered for a single
          utterance. The current default value of 8000 corresponds to
          roughly 4 minutes (depending on ASR model) and should be OK in
          most cases. If your utterances are further apart, increase
          this value, or decrease it for smaller audio files.
      max_window_size : int
          Maximum window size. It should not be necessary
          to change this value.
      gratis_blank : bool
          If True, the transition cost of blank is set to zero.
          Useful for long preambles or if there are large unrelated segments
          between utterances. Default: False.
  
      Parameters for calculation of confidence score
      ----------------------------------------------
      scoring_length : int
          Block length to calculate confidence score. The
          default value of 30 should be OK in most cases.
          30 corresponds to roughly 1-2s of audio.
      """
      # Parameters for timing
      if time_stamps is not None:
          if time_stamps not in self.choices_time_stamps:
              raise NotImplementedError(
                  f"Parameter ´time_stamps´ has to be one of "
                  f"{list(self.choices_time_stamps)}",
              )
          self.time_stamps = time_stamps
      if fs is not None:
          self.fs = float(fs)
      if samples_to_frames_ratio is not None:
          self.samples_to_frames_ratio = float(samples_to_frames_ratio)
      # Parameters for text preparation
      if set_blank is not None:
          self.config.blank = int(set_blank)
      if replace_spaces_with_blanks is not None:
          self.config.replace_spaces_with_blanks = bool(
              replace_spaces_with_blanks
          )
      if kaldi_style_text is not None:
          self.kaldi_style_text = bool(kaldi_style_text)
      if text_converter is not None:
          if text_converter not in self.choices_text_converter:
              raise NotImplementedError(
                  f"Parameter ´text_converter´ has to be one of "
                  f"{list(self.choices_text_converter)}",
              )
          self.text_converter = text_converter
      # Parameters for alignment
      if min_window_size is not None:
          self.config.min_window_size = int(min_window_size)
      if max_window_size is not None:
          self.config.max_window_size = int(max_window_size)
      if gratis_blank is not None:
          self.config.blank_transition_cost_zero = bool(gratis_blank)
      if (
          self.config.blank_transition_cost_zero
          and self.config.replace_spaces_with_blanks
          and not self.warned_about_misconfiguration
      ):
          logger.error(
              "Blanks are inserted between words, and also the transition cost of"
              " blank is zero. This configuration may lead to misalignments!"
          )
          self.warned_about_misconfiguration = True
      # Parameter for calculation of confidence score
      if scoring_length is not None:
          self.config.score_min_mean_over_L = int(scoring_length)
  
imports: import logging
  from pathlib import Path
  from types import SimpleNamespace
  from typing import Optional
  from typing import Union
  import numpy
  import torch
  from typing import List
  from speechbrain.inference.ASR import EncoderASR, EncoderDecoderASR
label_desc: Use image node_id 2 for calling the CTCSegmentation obj's underlying member method code with example usage: obj.set_config(time_stamps, fs, samples_to_frames_ratio, set_blank, replace_spaces_with_blanks, kaldi_style_text, text_converter, gratis_blank, min_window_size, max_window_size, scoring_length) without return types