code: def dataio_prepare(hparams, tokenizer):
      """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["train_loader_kwargs"]["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["train_loader_kwargs"]["shuffle"] = False
  
      elif hparams["sorting"] == "random":
          pass
  
      else:
          raise NotImplementedError(
              "sorting must be random, ascending or descending"
          )
  
      valid_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["valid_csv"],
          replacements={"data_root": data_folder},
      )
      # We also sort the validation data so it is faster to validate
      valid_data = valid_data.filtered_sorted(sort_key="duration")
  
      test_data = sb.dataio.dataset.DynamicItemDataset.from_csv(
          csv_path=hparams["test_csv"],
          replacements={"data_root": data_folder},
      )
  
      # We also sort the validation data so it is faster to validate
      test_data = test_data.filtered_sorted(sort_key="duration")
  
      datasets = [train_data, valid_data, test_data]
  
      # 2. Define audio pipeline:
      @sb.utils.data_pipeline.takes("clean_wav")
      @sb.utils.data_pipeline.provides("clean_sig")
      def audio_pipeline_clean(wav):
          info = torchaudio.info(wav)
          clean_sig = sb.dataio.dataio.read_audio(wav)
          clean_sig = torchaudio.transforms.Resample(
              info.sample_rate,
              hparams["enhance_sample_rate"],
          )(clean_sig)
          return clean_sig
  
      @sb.utils.data_pipeline.takes("noise_wav")
      @sb.utils.data_pipeline.provides("noise_sig")
      def audio_pipeline_noise(wav):
          info = torchaudio.info(wav)
          noise_sig = sb.dataio.dataio.read_audio(wav)
          noise_sig = torchaudio.transforms.Resample(
              info.sample_rate,
              hparams["enhance_sample_rate"],
          )(noise_sig)
          return noise_sig
  
      @sb.utils.data_pipeline.takes("noisy_wav")
      @sb.utils.data_pipeline.provides("noisy_wav", "noisy_sig")
      def audio_pipeline_noisy(wav):
          info = torchaudio.info(wav)
          noisy_sig = sb.dataio.dataio.read_audio(wav)
          noisy_sig = torchaudio.transforms.Resample(
              info.sample_rate,
              hparams["enhance_sample_rate"],
          )(noisy_sig)
          return wav, noisy_sig
  
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline_clean)
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline_noise)
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline_noisy)
  
      # 3. Define text pipeline:
      @sb.utils.data_pipeline.takes("wrd")
      @sb.utils.data_pipeline.provides(
          "wrd", "tokens_list", "tokens_bos", "tokens_eos", "tokens"
      )
      def text_pipeline(wrd):
          yield wrd
          tokens_list = tokenizer.encode(wrd)
          # avoid bos and eos tokens.
          tokens_list = tokens_list[1:-1]
          yield tokens_list
          tokens_bos = torch.LongTensor(
              [hparams["bos_index"]] + tokens_list
          )
          yield tokens_bos
          tokens_eos = torch.LongTensor(
              tokens_list + [hparams["eos_index"]]
          )
          yield tokens_eos
          tokens = torch.LongTensor(tokens_list)
          yield tokens
  
      sb.dataio.dataset.add_dynamic_item(datasets, text_pipeline)
  
      # 4. Set output:
      sb.dataio.dataset.set_output_keys(
          datasets,
          [
              "id",
              "clean_sig",
              "noise_sig",
              "noisy_sig",
              "tokens_list",
              "tokens_bos",
              "tokens_eos",
              "tokens",
              "noisy_wav",
          ],
      )
  
      return train_data, valid_data, test_data
  
imports: import os
  import sys
  import csv
  import logging
  import numpy
  from tqdm import tqdm
  from pesq import pesq
  from pystoi import stoi
  import torch
  import torchaudio
  import torch.nn.functional
  import speechbrain
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.metric_stats import MetricStats
  from speechbrain.utils.distributed import run_on_main
  from speechbrain.utils.data_utils import undo_padding
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams, tokenizer) and returns: train_data,  valid_data,  test_data, clean_sig, noise_sig, wav,  noisy_sig