code: def main(cfg: ProcessConfig) -> ProcessConfig:
      logging.info(f"Hydra config: {OmegaConf.to_yaml(cfg)}")
  
      if is_dataclass(cfg):
          cfg = OmegaConf.structured(cfg)
  
      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!"
          )
  
      # 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"
      )
  
      # setup model
      if cfg.model_path is not None:
          # restore model from .nemo file path
          model_cfg = AudioToAudioModel.restore_from(
              restore_path=cfg.model_path, return_config=True
          )
          classpath = model_cfg.target  # original class path
          imported_class = model_utils.import_class_by_path(
              classpath
          )  # type: AudioToAudioModel
          logging.info(f"Restoring model : {imported_class.__name__}")
          audio_to_audio_model = imported_class.restore_from(
              restore_path=cfg.model_path,
              override_config_path=cfg.override_config_path,
              map_location=map_location,
          )  # type: AudioToAudioModel
          model_name = os.path.splitext(
              os.path.basename(cfg.model_path)
          )[0]
      else:
          # restore model by name
          audio_to_audio_model = AudioToAudioModel.from_pretrained(
              model_name=cfg.pretrained_name, map_location=map_location
          )  # type: AudioToAudioModel
          model_name = cfg.pretrained_name
  
      trainer = pl.Trainer(devices=device, accelerator=accelerator)
      audio_to_audio_model.set_trainer(trainer)
      audio_to_audio_model = audio_to_audio_model.eval()
  
      if cfg.audio_dir is not None:
          filepaths = list(
              glob.glob(
                  os.path.join(cfg.audio_dir, f"**/*.{cfg.audio_type}"),
                  recursive=True,
              )
          )
      else:
          # get filenames from manifest
          filepaths = []
          if os.stat(cfg.dataset_manifest).st_size == 0:
              raise RuntimeError(
                  f"The input dataset_manifest {cfg.dataset_manifest} is empty."
              )
  
          input_key = (
              "audio_filepath"
              if cfg.input_key is None
              else cfg.input_key
          )
          manifest_dir = Path(cfg.dataset_manifest).parent
          with open(cfg.dataset_manifest, "r") as f:
              for line in f:
                  item = json.loads(line)
                  audio_file = Path(item[input_key])
                  if (
                      not audio_file.is_file()
                      and not audio_file.is_absolute()
                  ):
                      audio_file = manifest_dir / audio_file
                  filepaths.append(str(audio_file.absolute()))
  
      if cfg.max_utts is not None:
          # Limit the number of utterances to process
          filepaths = filepaths[: cfg.max_utts]
  
      logging.info(f"\nProcessing {len(filepaths)} files...\n")
  
      # 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
      if cfg.output_dir is None:
          # create default output filename
          if cfg.audio_dir is not None:
              cfg.output_dir = (
                  os.path.dirname(os.path.join(cfg.audio_dir, "."))
                  + f"_processed_{model_name}"
              )
          else:
              cfg.output_dir = (
                  os.path.dirname(cfg.dataset_manifest)
                  + f"_processed_{model_name}"
              )
  
      # Compute output filename
      if cfg.output_filename is None:
          # create default output filename
          cfg.output_filename = (
              cfg.output_dir.rstrip("/") + "_manifest.json"
          )
  
      # if transcripts should not be overwritten, and already exists, skip re-transcription step and return
      if not cfg.overwrite_output and os.path.exists(cfg.output_dir):
          raise RuntimeError(
              f"Previous output found at {cfg.output_dir}, and flag `overwrite_output`"
              f"is {cfg.overwrite_output}. Returning without processing."
          )
  
      # Process audio
      with autocast():
          with torch.no_grad():
              paths2processed_files = audio_to_audio_model.process(
                  paths2audio_files=filepaths,
                  output_dir=cfg.output_dir,
                  batch_size=cfg.batch_size,
                  num_workers=cfg.num_workers,
                  input_channel_selector=cfg.input_channel_selector,
              )
  
      logging.info(f"Finished processing {len(filepaths)} files!")
      logging.info(
          f"Processed audio is available in the output directory: {cfg.output_dir}"
      )
  
      # Prepare new/updated manifest with a new key for processed audio
      with open(cfg.output_filename, "w", encoding="utf-8") as f:
          if cfg.dataset_manifest is not None:
              with open(cfg.dataset_manifest, "r") as fr:
                  for idx, line in enumerate(fr):
                      item = json.loads(line)
                      item[
                          "processed_audio_filepath"
                      ] = paths2processed_files[idx]
                      f.write(json.dumps(item) + "\n")
  
                      if (
                          cfg.max_utts is not None
                          and idx >= cfg.max_utts - 1
                      ):
                          break
          else:
              for idx, processed_file in enumerate(
                  paths2processed_files
              ):
                  item = {"processed_audio_filepath": processed_file}
                  f.write(json.dumps(item) + "\n")
  
      return cfg
  
file_path: NeMo/examples/audio_tasks/process_audio.py
imports: import contextlib
  import glob
  import json
  import os
  from dataclasses import dataclass, is_dataclass
  from pathlib import Path
  from typing import List, Optional
  import pytorch_lightning
  import torch
  from omegaconf import OmegaConf
  from nemo.collections.asr.models import AudioToAudioModel
  from nemo.core.config import hydra_runner
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 1 for calling a global function with example usage: main(cfg) and returns: cfg