code: def main(cfg: TranscriptionConfig) -> TranscriptionConfig:
      logging.info(f"Hydra config: {OmegaConf.to_yaml(cfg)}")
      torch.set_grad_enabled(False)
  
      for key in cfg:
          cfg[key] = None if cfg[key] == "None" else cfg[key]
  
      if is_dataclass(cfg):
          cfg = OmegaConf.structured(cfg)
  
      if cfg.random_seed:
          pl.seed_everything(cfg.random_seed)
  
      if cfg.model_path is None and cfg.pretrained_name is None:
          raise ValueError(
              "Both cfg.model_path and cfg.pretrained_name cannot be None!"
          )
      if cfg.audio_dir is None and cfg.dataset_manifest is None:
          raise ValueError(
              "Both cfg.audio_dir and cfg.dataset_manifest cannot be None!"
          )
  
      filepaths = None
      manifest = cfg.dataset_manifest
      if cfg.audio_dir is not None:
          filepaths = list(
              glob.glob(
                  os.path.join(cfg.audio_dir, f"**/*.{cfg.audio_type}"),
                  recursive=True,
              )
          )
          manifest = None  # ignore dataset_manifest if audio_dir and dataset_manifest both presents
  
      # setup GPU
      if cfg.cuda is None:
          if torch.cuda.is_available():
              device = [0]  # use 0th CUDA device
              accelerator = "gpu"
          else:
              device = 1
              accelerator = "cpu"
      else:
          device = [cfg.cuda]
          accelerator = "gpu"
      map_location = torch.device(
          "cuda:{}".format(device[0]) if accelerator == "gpu" else "cpu"
      )
      logging.info(f"Inference will be done on device : {device}")
  
      asr_model, model_name = setup_model(cfg, map_location)
  
      model_cfg = copy.deepcopy(asr_model._cfg)
      OmegaConf.set_struct(model_cfg.preprocessor, False)
      # some changes for streaming scenario
      model_cfg.preprocessor.dither = 0.0
      model_cfg.preprocessor.pad_to = 0
  
      if model_cfg.preprocessor.normalize != "per_feature":
          logging.error(
              "Only EncDecCTCModelBPE models trained with per_feature normalization are supported currently"
          )
  
      # Disable config overwriting
      OmegaConf.set_struct(model_cfg.preprocessor, True)
  
      # setup AMP (optional)
      if (
          cfg.amp
          and torch.cuda.is_available()
          and hasattr(torch.cuda, "amp")
          and hasattr(torch.cuda.amp, "autocast")
      ):
          logging.info("AMP enabled!\n")
          autocast = torch.cuda.amp.autocast
      else:
  
          @contextlib.contextmanager
          def autocast():
              yield
  
      # Compute output filename
      cfg = compute_output_filename(cfg, model_name)
  
      # if transcripts should not be overwritten, and already exists, skip re-transcription step and return
      if not cfg.overwrite_transcripts and os.path.exists(
          cfg.output_filename
      ):
          logging.info(
              f"Previous transcripts found at {cfg.output_filename}, and flag `overwrite_transcripts`"
              f"is {cfg.overwrite_transcripts}. Returning without re-transcribing text."
          )
          return cfg
  
      # Setup decoding strategy
      if hasattr(asr_model, "change_decoding_strategy"):
          if not isinstance(
              asr_model, EncDecCTCModel
          ) and not isinstance(asr_model, EncDecHybridRNNTCTCModel):
              raise ValueError(
                  "The script supports ctc model and hybrid model with ctc decodng!"
              )
  
          else:
              if cfg.compute_langs:
                  raise ValueError(
                      "CTC models do not support `compute_langs` at the moment."
                  )
  
              if hasattr(
                  asr_model, "cur_decoder"
              ):  # hybrid model with ctc decoding or potential other models containing decoding switch feature
                  asr_model.change_decoding_strategy(
                      cfg.decoding, decoder_type="ctc"
                  )
  
              else:  # ctc model
                  asr_model.change_decoding_strategy(cfg.decoding)
  
      asr_model.eval()
      asr_model = asr_model.to(asr_model.device)
  
      feature_stride = model_cfg.preprocessor["window_stride"]
      model_stride_in_secs = feature_stride * cfg.model_stride
      total_buffer = cfg.total_buffer_in_secs
      chunk_len = float(cfg.chunk_len_in_secs)
  
      tokens_per_chunk = math.ceil(chunk_len / model_stride_in_secs)
      mid_delay = math.ceil(
          (chunk_len + (total_buffer - chunk_len) / 2)
          / model_stride_in_secs
      )
      logging.info(
          f"tokens_per_chunk is {tokens_per_chunk}, mid_delay is {mid_delay}"
      )
  
      frame_asr = FrameBatchASR(
          asr_model=asr_model,
          frame_len=chunk_len,
          total_buffer=cfg.total_buffer_in_secs,
          batch_size=cfg.batch_size,
      )
  
      hyps = get_buffered_pred_feat(
          frame_asr,
          chunk_len,
          tokens_per_chunk,
          mid_delay,
          model_cfg.preprocessor,
          model_stride_in_secs,
          asr_model.device,
          manifest,
          filepaths,
      )
      output_filename, pred_text_attr_name = write_transcription(
          hyps,
          cfg,
          model_name,
          filepaths=filepaths,
          compute_langs=False,
          compute_timestamps=False,
      )
      logging.info(
          f"Finished writing predictions to {output_filename}!"
      )
  
      if cfg.calculate_wer:
          output_manifest_w_wer, total_res, _ = cal_write_wer(
              pred_manifest=output_filename,
              pred_text_attr_name=pred_text_attr_name,
              clean_groundtruth_text=cfg.clean_groundtruth_text,
              langid=cfg.langid,
              use_cer=cfg.use_cer,
              output_filename=None,
          )
          if output_manifest_w_wer:
              logging.info(
                  f"Writing prediction and error rate of each sample to {output_manifest_w_wer}!"
              )
              logging.info(f"{total_res}")
  
      return cfg
  
file_path: NeMo/examples/asr/asr_chunked_inference/ctc/speech_to_text_buffered_infer_ctc.py
imports: import contextlib
  import copy
  import glob
  import math
  import os
  from dataclasses import dataclass, is_dataclass
  from typing import Optional
  import pytorch_lightning
  import torch
  from omegaconf import OmegaConf
  from nemo.collections.asr.models import EncDecCTCModel, EncDecHybridRNNTCTCModel
  from nemo.collections.asr.parts.submodules.ctc_decoding import CTCDecodingConfig
  from nemo.collections.asr.parts.utils.eval_utils import cal_write_wer
  from nemo.collections.asr.parts.utils.streaming_utils import FrameBatchASR
  from nemo.collections.asr.parts.utils.transcribe_utils import compute_output_filename, get_buffered_pred_feat, setup_model, write_transcription
  from nemo.core.config import hydra_runner
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling a global function with example usage: main(cfg) and returns: cfg, cfg