code: def dataio_prepare(hparams):
      """This function prepares the datasets to be used in the brain class.
      It also defines the data processing pipeline through user-defined functions.
      """
  
      # 1. Define datasets
      data_folder = hparams["data_folder"]
  
      train_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["train_csv"],
          replacements={"data_root": data_folder},
      )
  
      if hparams["sorting"] == "ascending":
          # we sort training data to speed up training and get better results.
          train_data = train_data.filtered_sorted(
              sort_key="duration",
              key_max_value={
                  "duration": hparams["avoid_if_longer_than"]
              },
          )
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["dataloader_options"]["shuffle"] = False
  
      elif hparams["sorting"] == "descending":
          train_data = train_data.filtered_sorted(
              sort_key="duration",
              reverse=True,
              key_max_value={
                  "duration": hparams["avoid_if_longer_than"]
              },
          )
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["dataloader_options"]["shuffle"] = False
  
      elif hparams["sorting"] == "random":
          pass
  
      else:
          raise NotImplementedError(
              "sorting must be random, ascending or descending"
          )
  
      datasets = [train_data]
  
      # 2. Define audio pipeline:
      @sb.utils.data_pipeline.takes("wav")
      @sb.utils.data_pipeline.provides("sig")
      def audio_pipeline(wav):
          info = torchaudio.info(wav)
          sig = sb.dataio.dataio.read_audio(wav)
          resampled = torchaudio.transforms.Resample(
              info.sample_rate,
              hparams["sample_rate"],
          )(sig)
          return resampled
  
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline)
  
      # 4. Set output:
      sb.dataio.dataset.set_output_keys(
          datasets,
          ["id", "sig"],
      )
      return train_data
  
file_path: speechbrain/recipes/CommonVoice/quantization/train.py
imports: import os
  import sys
  import logging
  import speechbrain
  import torchaudio
  from speechbrain.utils.distributed import run_on_main
  from hyperpyyaml import load_hyperpyyaml
  from torch.utils.data import DataLoader
  from speechbrain.dataio.dataloader import LoopedLoader
  from speechbrain.utils.kmeans import fetch_kmeans_model, train, save_model
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams) and returns: train_data, resampled