code: def get_dali_char_dataset(
      config: dict,
      shuffle: bool,
      device_id: int,
      global_rank: int,
      world_size: int,
      preprocessor_cfg: Optional[DictConfig] = None,
  ) -> audio_to_text_dali.AudioToCharDALIDataset:
      """
      Instantiates a Character Encoding based AudioToCharDALIDataset.
  
      Args:
          config: Config of the AudioToCharDALIDataset.
          shuffle: Bool flag whether to shuffle the dataset.
          device_id: Index of the GPU to be used (local_rank). Only applicable when device == 'gpu'. Defaults to 0.
          global_rank: Global rank of this device.
          world_size: Global world size in the training method.
          augmentor: Optional AudioAugmentor object for augmentations on audio data.
          preprocessor_cfg: Preprocessor configuration. Supports AudioToMelSpectrogramPreprocessor and AudioToMFCCPreprocessor.
  
      Returns:
          An instance of AudioToCharDALIDataset.
      """
      device = "gpu" if torch.cuda.is_available() else "cpu"
      dataset = audio_to_text_dali.AudioToCharDALIDataset(
          manifest_filepath=config["manifest_filepath"],
          device=device,
          batch_size=config["batch_size"],
          labels=config["labels"],
          sample_rate=config["sample_rate"],
          audio_tar_filepaths=config.get(
              "tarred_audio_filepaths", None
          ),
          audio_tar_index_filepaths=config.get(
              "tarred_audio_index_filepaths", None
          ),
          max_duration=config.get("max_duration", None),
          min_duration=config.get("min_duration", None),
          blank_index=config.get("blank_index", -1),
          unk_index=config.get("unk_index", -1),
          normalize=config.get("normalize_transcripts", False),
          trim=config.get("trim_silence", False),
          parser=config.get("parser", "en"),
          shuffle=shuffle,
          shard_strategy=config.get("tarred_shard_strategy", "scatter"),
          device_id=device_id,
          global_rank=global_rank,
          world_size=world_size,
          preprocessor_cfg=preprocessor_cfg,
          return_sample_id=config.get("return_sample_id", False),
      )
      return dataset
  
imports: import copy
  import json
  import random
  from math import isclose
  from typing import Any, List, Optional, Union
  import torch
  from omegaconf import DictConfig, OmegaConf, open_dict
  from omegaconf.listconfig import ListConfig
  from pytorch_lightning.callbacks import BasePredictionWriter
  from torch.utils.data import ChainDataset
  from nemo.collections.asr.data import audio_to_text, audio_to_text_dali
  from nemo.collections.asr.data.huggingface.hf_audio_to_text_dataset import get_hf_audio_to_text_bpe_dataset, get_hf_audio_to_text_char_dataset
  from nemo.collections.asr.parts.preprocessing.perturb import process_augmentations
  from nemo.collections.common.data.dataset import CodeSwitchedDataset, ConcatDataset
  from nemo.utils import logging
label_desc: Use image node_id 9 for calling a global function with example usage: get_dali_char_dataset(config, shuffle, device_id, global_rank, world_size, preprocessor_cfg) and returns: dataset