code: def write_transcription(
      transcriptions: Union[
          List[rnnt_utils.Hypothesis],
          List[List[rnnt_utils.Hypothesis]],
          List[str],
      ],
      cfg: DictConfig,
      model_name: str,
      filepaths: List[str] = None,
      compute_langs: bool = False,
      compute_timestamps: bool = False,
  ) -> Tuple[str, str]:
      """Write generated transcription to output file."""
      if cfg.append_pred:
          logging.info(
              f'Transcripts will be written in "{cfg.output_filename}" file'
          )
          if cfg.pred_name_postfix is not None:
              pred_by_model_name = cfg.pred_name_postfix
          else:
              pred_by_model_name = model_name
          pred_text_attr_name = "pred_text_" + pred_by_model_name
      else:
          pred_text_attr_name = "pred_text"
  
      return_hypotheses = True
      if isinstance(transcriptions[0], str):  # List[str]:
          best_hyps = transcriptions
          return_hypotheses = False
      elif isinstance(
          transcriptions[0], rnnt_utils.Hypothesis
      ):  # List[rnnt_utils.Hypothesis]
          best_hyps = transcriptions
          assert (
              cfg.decoding.beam.return_best_hypothesis
          ), "Works only with return_best_hypothesis=true"
      elif isinstance(transcriptions[0], list) and isinstance(
          transcriptions[0][0], rnnt_utils.Hypothesis
      ):  # List[List[rnnt_utils.Hypothesis]] NBestHypothesis
          best_hyps, beams = [], []
          for hyps in transcriptions:
              best_hyps.append(hyps[0])
              if not cfg.decoding.beam.return_best_hypothesis:
                  beam = []
                  for hyp in hyps:
                      beam.append((hyp.text, hyp.score))
                  beams.append(beam)
      else:
          raise TypeError
  
      with open(
          cfg.output_filename, "w", encoding="utf-8", newline="\n"
      ) as f:
          if cfg.audio_dir is not None:
              for idx, transcription in enumerate(
                  best_hyps
              ):  # type: rnnt_utils.Hypothesis or str
                  if not return_hypotheses:  # transcription is str
                      item = {
                          "audio_filepath": filepaths[idx],
                          pred_text_attr_name: transcription,
                      }
                  else:  # transcription is Hypothesis
                      item = {
                          "audio_filepath": filepaths[idx],
                          pred_text_attr_name: transcription.text,
                      }
  
                      if compute_timestamps:
                          timestamps = transcription.timestep
                          if timestamps is not None and isinstance(
                              timestamps, dict
                          ):
                              timestamps.pop(
                                  "timestep", None
                              )  # Pytorch tensor calculating index of each token, not needed.
                              for key in timestamps.keys():
                                  values = normalize_timestamp_output(
                                      timestamps[key]
                                  )
                                  item[f"timestamps_{key}"] = values
  
                      if compute_langs:
                          item["pred_lang"] = transcription.langs
                          item[
                              "pred_lang_chars"
                          ] = transcription.langs_chars
                      if not cfg.decoding.beam.return_best_hypothesis:
                          item["beams"] = beams[idx]
                  f.write(json.dumps(item) + "\n")
          else:
              with open(
                  cfg.dataset_manifest, "r", encoding="utf-8"
              ) as fr:
                  for idx, line in enumerate(fr):
                      item = json.loads(line)
                      if not return_hypotheses:  # transcription is str
                          item[pred_text_attr_name] = best_hyps[idx]
                      else:  # transcription is Hypothesis
                          item[pred_text_attr_name] = best_hyps[
                              idx
                          ].text
  
                          if compute_timestamps:
                              timestamps = best_hyps[idx].timestep
                              if timestamps is not None and isinstance(
                                  timestamps, dict
                              ):
                                  timestamps.pop(
                                      "timestep", None
                                  )  # Pytorch tensor calculating index of each token, not needed.
                                  for key in timestamps.keys():
                                      values = (
                                          normalize_timestamp_output(
                                              timestamps[key]
                                          )
                                      )
                                      item[f"timestamps_{key}"] = values
  
                          if compute_langs:
                              item["pred_lang"] = best_hyps[idx].langs
                              item["pred_lang_chars"] = best_hyps[
                                  idx
                              ].langs_chars
  
                          if (
                              not cfg.decoding.beam.return_best_hypothesis
                          ):
                              item["beams"] = beams[idx]
                      f.write(json.dumps(item) + "\n")
  
      return cfg.output_filename, pred_text_attr_name
  
imports: import glob
  import json
  import os
  import re
  from dataclasses import dataclass
  from typing import List, Optional, Tuple, Union
  import torch
  from omegaconf import DictConfig
  from tqdm.auto import tqdm
  import nemo.collections.asr
  from nemo.collections.asr.metrics.wer import word_error_rate
  from nemo.collections.asr.models import ASRModel, EncDecHybridRNNTCTCModel
  from nemo.collections.asr.parts.utils import rnnt_utils
  from nemo.collections.asr.parts.utils.streaming_utils import FrameBatchASR
  from nemo.collections.common.metrics.punct_er import OccurancePunctuationErrorRate
  from nemo.collections.common.parts.preprocessing.manifest import get_full_path
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 8 for calling a global function with example usage: write_transcription(transcriptions, cfg, model_name, filepaths, compute_langs, compute_timestamps) and returns: cfg,  pred_text_attr_name