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.
      """
      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")
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["train_dataloader_opts"]["shuffle"] = False
  
      elif hparams["sorting"] == "descending":
          train_data = train_data.filtered_sorted(
              sort_key="duration", reverse=True
          )
          # when sorting do not shuffle in dataloader ! otherwise is pointless
          hparams["train_dataloader_opts"]["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},
      )
      valid_data = valid_data.filtered_sorted(sort_key="duration")
  
      # test is separate
      test_datasets = {}
      for csv_file in hparams["test_csv"]:
          name = Path(csv_file).stem
          test_datasets[
              name
          ] = sb.dataio.dataset.DynamicItemDataset.from_csv(
              csv_path=csv_file, replacements={"data_root": data_folder}
          )
          test_datasets[name] = test_datasets[name].filtered_sorted(
              sort_key="duration"
          )
  
      datasets = [train_data, valid_data] + [
          i for k, i in test_datasets.items()
      ]
  
      # 2. Define audio pipeline:
      @sb.utils.data_pipeline.takes("wav")
      @sb.utils.data_pipeline.provides("sig")
      def audio_pipeline(wav):
          sig = sb.dataio.dataio.read_audio(wav)
          return sig
  
      sb.dataio.dataset.add_dynamic_item(datasets, audio_pipeline)
      label_encoder = sb.dataio.encoder.CTCTextEncoder()
  
      # 3. Define text pipeline:
      @sb.utils.data_pipeline.takes("wrd")
      @sb.utils.data_pipeline.provides(
          "wrd", "char_list", "tokens_list", "tokens"
      )
      def text_pipeline(wrd):
          yield wrd
          char_list = list(wrd)
          yield char_list
          tokens_list = label_encoder.encode_sequence(char_list)
          yield tokens_list
          tokens = torch.LongTensor(tokens_list)
          yield tokens
  
      sb.dataio.dataset.add_dynamic_item(datasets, text_pipeline)
  
      lab_enc_file = os.path.join(
          hparams["save_folder"], "label_encoder.txt"
      )
      special_labels = {
          "blank_label": hparams["blank_index"],
      }
      label_encoder.load_or_create(
          path=lab_enc_file,
          from_didatasets=[train_data],
          output_key="char_list",
          special_labels=special_labels,
          sequence_input=True,
      )
  
      # 4. Set output:
      sb.dataio.dataset.set_output_keys(
          datasets,
          ["id", "sig", "wrd", "char_list", "tokens"],
      )
  
      return train_data, valid_data, test_datasets, label_encoder
  
file_path: speechbrain/recipes/LibriSpeech/ASR/CTC/train_with_wav2vec.py
imports: import os
  import sys
  import torch
  import logging
  import speechbrain
  from speechbrain.utils.distributed import run_on_main, if_main_process
  from hyperpyyaml import load_hyperpyyaml
  from pathlib import Path
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams) and returns: train_data,  valid_data,  test_datasets,  label_encoder, sig