code: def get_code_switched_dataset(
      config: dict,
      shuffle_n: int,
      global_rank: int,
      world_size: int,
      tokenizer: Optional["TokenizerSpec"] = None,
      augmentor: Optional["AudioAugmentor"] = None,
  ) -> CodeSwitchedDataset:
      if "manifest_filepath" not in config:
          raise ValueError(
              "`manifest_filepath` must be provided in the dataset config if `is_code_switched=True`"
          )
      if "code_switched" not in config:
          raise ValueError(
              "`code_switched` param group must be in the dataset config if `is_code_switched=True`"
          )
  
      manifest_filepaths = config["manifest_filepath"]
      tarred_audio_filepaths = config.get(
          "tarred_audio_filepaths", None
      )
  
      cs_config = OmegaConf.to_container(config["code_switched"])
  
      # needed to support validation Datasets that arrive here as
      # [[dataset1,dataset2]] otherwise ModelPT would interfere
      if len(manifest_filepaths) == 1 and not isinstance(
          manifest_filepaths[0], str
      ):
          manifest_filepaths = config["manifest_filepath"][0]
      if tarred_audio_filepaths is None:
          tarred_audio_filepaths = [None] * len(manifest_filepaths)
  
      if len(manifest_filepaths) != len(tarred_audio_filepaths):
          raise ValueError(
              f"manifest_filepaths (length={len(manifest_filepaths)}) and tarred_audio_filepaths (length={len(tarred_audio_filepaths)}) need to have the same number of items."
          )
  
      datasets = []
      for dataset_idx, (
          tarred_audio_filepath,
          manifest_filepath,
      ) in enumerate(zip(tarred_audio_filepaths, manifest_filepaths)):
          conf = copy.deepcopy(config)
          conf["manifest_filepath"] = manifest_filepath
          with open_dict(conf):
              conf["tarred_audio_filepaths"] = tarred_audio_filepath
          if (
              tarred_audio_filepath is None
              or len(tarred_audio_filepath) == 0
          ):
              if tokenizer is None:
                  dataset = get_char_dataset(
                      config=conf, augmentor=None
                  )
              else:
                  dataset = get_bpe_dataset(
                      config=conf, tokenizer=tokenizer, augmentor=None
                  )
          else:
              dataset = get_tarred_dataset(
                  config=conf,
                  tokenizer=tokenizer,
                  shuffle_n=shuffle_n,
                  global_rank=global_rank,
                  world_size=world_size,
                  augmentor=None,
              )
          datasets.append(dataset)
  
      config = OmegaConf.to_container(config)
  
      dataset = CodeSwitchedDataset(
          datasets,
          shuffle=cs_config.get("shuffle", True),
          min_duration=cs_config.get("min_duration", 4),
          max_duration=cs_config.get("max_duration", 20),
          min_monolingual=cs_config.get("min_monolingual", 0.3),
          lang_probs=cs_config.get("probs", None),
          db_norm=cs_config.get("db_norm", -25.0),
          pause_start=cs_config.get("pause_start", 0),
          pause_join=cs_config.get("pause_join", 0),
          pause_end=cs_config.get("pause_end", 0),
          sampling_scales=cs_config.get("sampling_scales", None),
          seed=cs_config.get("seed", None),
          global_rank=global_rank,
          world_size=world_size,
          pure_random=cs_config.get("pure_random", False),
          force_monochannel=cs_config.get("force_monochannel", True),
          infinity_mode=cs_config.get("infinity_mode", False),
          sample_rate=config["sample_rate"],
          augmentor=augmentor,
      )
  
      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 8 for calling a global function with example usage: get_code_switched_dataset(config, shuffle_n, global_rank, world_size, tokenizer, augmentor) and returns: dataset