class_docstr: Base class for encoder decoder CTC-based models.
class_docstr_tok: ["Base","class","for","encoder","decoder","CTC-based","models","."]
docstr: Uses greedy decoding to transcribe audio files. Use this method for debugging and prototyping.
  Args:
      paths2audio_files: (a list) of paths to audio files.                 Recommended length per file is between 5 and 25 seconds.                 But it is possible to pass a few hours long file if enough GPU memory is available.
      batch_size: (int) batch size to use during inference.
          Bigger will result in better throughput performance but would use more memory.
      logprobs: (bool) pass True to get log probabilities instead of transcripts.
      return_hypotheses: (bool) Either return hypotheses or text
          With hypotheses can do some postprocessing like getting timestamp or rescoring
      num_workers: (int) number of workers for DataLoader
      channel_selector (int | Iterable[int] | str): select a single channel or a subset of channels from multi-channel audio. If set to `'average'`, it performs averaging across channels. Disabled if set to `None`. Defaults to `None`.
      augmentor: (DictConfig): Augment audio samples during transcription if augmentor is applied.
      verbose: (bool) whether to display tqdm progress bar
  Returns:
      A list of transcriptions (or raw log probabilities if logprobs is True) in the same order as paths2audio_files
docstr_tok: ["Uses","greedy","decoding","to","transcribe","audio","files",".","Use","this","method","for","debugging","and","prototyping",".","Args",":","paths2audio_files",":","(","a","list",")","of","paths","to","audio","files",".","Recommended","length","per","file","is","between","5","and","25","seconds",".","But","it","is","possible","to","pass","a","few","hours","long","file","if","enough","GPU","memory","is","available",".","batch_size",":","(","int",")","batch","size","to","use","during","inference",".","Bigger","will","result","in","better","throughput","performance","but","would","use","more","memory",".","logprobs",":","(","bool",")","pass","True","to","get","log","probabilities","instead","of","transcripts",".","return_hypotheses",":","(","bool",")","Either","return","hypotheses","or","text","With","hypotheses","can","do","some","postprocessing","like","getting","timestamp","or","rescoring","num_workers",":","(","int",")","number","of","workers","for","DataLoader","channel_selector","(","int","|","Iterable","[","int","]","|","str",")",":","select","a","single","channel","or","a","subset","of","channels","from","multi-channel","audio",".","If","set","to","`","'average","'","`",",","it","performs","averaging","across","channels",".","Disabled","if","set","to","`","None","`",".","Defaults","to","`","None","`",".","augmentor",":","(","DictConfig",")",":","Augment","audio","samples","during","transcription","if","augmentor","is","applied",".","verbose",":","(","bool",")","whether","to","display","tqdm","progress","bar","Returns",":","A","list","of","transcriptions","(","or","raw","log","probabilities","if","logprobs","is","True",")","in","the","same","order","as","paths2audio_files"]
code: def transcribe(
      self,
      paths2audio_files: List[str],
      batch_size: int = 4,
      logprobs: bool = False,
      return_hypotheses: bool = False,
      num_workers: int = 0,
      channel_selector: Optional[ChannelSelectorType] = None,
      augmentor: DictConfig = None,
      verbose: bool = True,
  ) -> List[str]:
      """
          Uses greedy decoding to transcribe audio files. Use this method for debugging and prototyping.
          Args:
              paths2audio_files: (a list) of paths to audio files. \
                  Recommended length per file is between 5 and 25 seconds. \
                  But it is possible to pass a few hours long file if enough GPU memory is available.
              batch_size: (int) batch size to use during inference.
                  Bigger will result in better throughput performance but would use more memory.
              logprobs: (bool) pass True to get log probabilities instead of transcripts.
              return_hypotheses: (bool) Either return hypotheses or text
                  With hypotheses can do some postprocessing like getting timestamp or rescoring
              num_workers: (int) number of workers for DataLoader
              channel_selector (int | Iterable[int] | str): select a single channel or a subset of channels from multi-channel audio. If set to `'average'`, it performs averaging across channels. Disabled if set to `None`. Defaults to `None`.
              augmentor: (DictConfig): Augment audio samples during transcription if augmentor is applied.
              verbose: (bool) whether to display tqdm progress bar
          Returns:
              A list of transcriptions (or raw log probabilities if logprobs is True) in the same order as paths2audio_files
          """
      if paths2audio_files is None or len(paths2audio_files) == 0:
          return {}
  
      if return_hypotheses and logprobs:
          raise ValueError(
              "Either `return_hypotheses` or `logprobs` can be True at any given time."
              "Returned hypotheses will contain the logprobs."
          )
  
      if num_workers is None:
          num_workers = min(batch_size, os.cpu_count() - 1)
  
      # We will store transcriptions here
      hypotheses = []
  
      # Model's mode and device
      mode = self.training
      device = next(self.parameters()).device
      dither_value = self.preprocessor.featurizer.dither
      pad_to_value = self.preprocessor.featurizer.pad_to
  
      try:
          self.preprocessor.featurizer.dither = 0.0
          self.preprocessor.featurizer.pad_to = 0
          # Switch model to evaluation mode
          self.eval()
          # Freeze the encoder and decoder modules
          self.encoder.freeze()
          self.transf_decoder.freeze()
          logging_level = logging.get_verbosity()
          logging.set_verbosity(logging.WARNING)
          # Work in tmp directory - will store manifest file there
          with tempfile.TemporaryDirectory() as tmpdir:
              with open(
                  os.path.join(tmpdir, "manifest.json"), "w"
              ) as fp:
                  for audio_file in paths2audio_files:
                      entry = {
                          "audio_filepath": audio_file,
                          "duration": 100000,
                          "text": "nothing",
                      }
                      fp.write(json.dumps(entry) + "\n")
  
              config = {
                  "paths2audio_files": paths2audio_files,
                  "batch_size": batch_size,
                  "temp_dir": tmpdir,
                  "num_workers": num_workers,
                  "channel_selector": channel_selector,
              }
  
              if augmentor:
                  config["augmentor"] = augmentor
  
              temporary_datalayer = self._setup_transcribe_dataloader(
                  config
              )
              for test_batch in tqdm(
                  temporary_datalayer,
                  desc="Transcribing",
                  disable=not verbose,
              ):
                  (
                      log_probs,
                      encoded_len,
                      enc_states,
                      enc_mask,
                  ) = self.forward(
                      input_signal=test_batch[0].to(device),
                      input_signal_length=test_batch[1].to(device),
                  )
  
                  beam_hypotheses = (
                      self.beam_search(
                          encoder_hidden_states=enc_states,
                          encoder_input_mask=enc_mask,
                          return_beam_scores=False,
                      )
                      .detach()
                      .cpu()
                      .numpy()
                  )
  
                  beam_hypotheses = [
                      self.tokenizer.ids_to_text(hyp)
                      for hyp in beam_hypotheses
                  ]
  
                  # TODO: add support for return_hypotheses=True @AlexGrinch
                  # if return_hypotheses:
                  #     # dump log probs per file
                  #     for idx in range(logits.shape[0]):
                  #         current_hypotheses[idx].y_sequence = logits[idx][: logits_len[idx]]
  
                  hypotheses += beam_hypotheses
  
                  del (
                      test_batch,
                      log_probs,
                      encoded_len,
                      enc_states,
                      enc_mask,
                  )
      finally:
          # set mode back to its original value
          self.train(mode=mode)
          self.preprocessor.featurizer.dither = dither_value
          self.preprocessor.featurizer.pad_to = pad_to_value
          if mode is True:
              self.encoder.unfreeze()
              self.transf_decoder.unfreeze()
          logging.set_verbosity(logging_level)
  
      return hypotheses
  
imports: import itertools
  import json
  import os
  import tempfile
  from math import ceil
  from typing import Dict, List, Optional, Union
  import editdistance
  import torch
  import torch.distributed
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from tqdm.auto import tqdm
  from nemo.collections.asr.data import audio_to_text_dataset
  from nemo.collections.asr.data.audio_to_text_dali import DALIOutputs
  from nemo.collections.asr.data.audio_to_text_lhotse import LhotseSpeechToTextBpeDataset
  from nemo.collections.asr.models.asr_model import ASRModel, ExportableEncDecModel
  from nemo.collections.asr.parts.mixins import ASRBPEMixin
  from nemo.collections.asr.parts.utils.audio_utils import ChannelSelectorType
  from nemo.collections.common.data.lhotse import get_lhotse_dataloader_from_config
  from nemo.collections.common.losses import SmoothedCrossEntropyLoss
  from nemo.collections.common.metrics import GlobalAverageLossMetric
  from nemo.collections.common.parts import transformer_weights_init
  from nemo.core.classes.common import typecheck
  from nemo.core.neural_types import AudioSignal, ChannelType, LabelsType, LengthsType, LogprobsType, MaskType, NeuralType, SpectrogramType
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling the EncDecTransfModelBPE obj's underlying member method code with example usage: obj.transcribe(paths2audio_files, batch_size, logprobs, return_hypotheses, num_workers, channel_selector, augmentor, verbose) and returns: hypotheses, dict