code: def dataio_prepare(hparams):
      # Load lexicon
      lexicon = hparams["lexicon"]
      input_encoder = hparams.get("input_encoder")
  
      # add a dummy symbol for idx 0 - used for padding.
      lexicon = ["@@"] + lexicon
      input_encoder.update_from_iterable(lexicon, sequence_input=False)
      input_encoder.add_unk()
  
      # load audio, text and durations on the fly; encode audio and text.
      @sb.utils.data_pipeline.takes(
          "wav",
          "label_phoneme",
          "durations",
          "pitch",
          "start",
          "end",
          "spn_labels",
          "last_phoneme_flags",
      )
      @sb.utils.data_pipeline.provides("mel_text_pair")
      def audio_pipeline(
          wav,
          label_phoneme,
          dur,
          pitch,
          start,
          end,
          spn_labels,
          last_phoneme_flags,
      ):
          durs = np.load(dur)
          durs_seq = torch.from_numpy(durs).int()
          label_phoneme = label_phoneme.strip()
          label_phoneme = label_phoneme.split()
          text_seq = input_encoder.encode_sequence_torch(
              label_phoneme
          ).int()
  
          assert len(text_seq) == len(
              durs
          ), f"{len(text_seq)}, {len(durs), len(label_phoneme)}, ({label_phoneme})"  # ensure every token has a duration
  
          no_spn_label, last_phonemes = list(), list()
          for i in range(len(label_phoneme)):
              if label_phoneme[i] != "spn":
                  no_spn_label.append(label_phoneme[i])
                  last_phonemes.append(last_phoneme_flags[i])
  
          no_spn_seq = input_encoder.encode_sequence_torch(
              no_spn_label
          ).int()
  
          spn_labels = [
              spn_labels[i]
              for i in range(len(label_phoneme))
              if label_phoneme[i] != "spn"
          ]
  
          audio, fs = torchaudio.load(wav)
  
          audio = audio.squeeze()
          audio = audio[int(fs * start) : int(fs * end)]
  
          mel, energy = hparams["mel_spectogram"](audio=audio)
          mel = mel[:, : sum(durs)]
          energy = energy[: sum(durs)]
          pitch = np.load(pitch)
          pitch = torch.from_numpy(pitch)
          pitch = pitch[: mel.shape[-1]]
          return (
              text_seq,
              durs_seq,
              mel,
              pitch,
              energy,
              len(text_seq),
              last_phonemes,
              no_spn_seq,
              spn_labels,
          )
  
      # define splits and load it as sb dataset
      datasets = {}
  
      for dataset in hparams["splits"]:
          datasets[
              dataset
          ] = sb.dataio.dataset.DynamicItemDataset.from_json(
              json_path=hparams[f"{dataset}_json"],
              replacements={"data_root": hparams["data_folder"]},
              dynamic_items=[audio_pipeline],
              output_keys=[
                  "mel_text_pair",
                  "wav",
                  "label",
                  "durations",
                  "pitch",
              ],
          )
      return datasets, input_encoder
  
imports: import os
  import sys
  import torch
  import logging
  import torchaudio
  import numpy
  import speechbrain
  from speechbrain.inference.vocoders import HIFIGAN
  from pathlib import Path
  from hyperpyyaml import load_hyperpyyaml
  from speechbrain.utils.data_utils import scalarize
  from speechbrain.inference.text import GraphemeToPhoneme
label_desc: Use image node_id 1 for calling a global function with example usage: dataio_prepare(hparams) and returns: datasets,  input_encoder, text_seq,  durs_seq,  mel,  pitch,  energy,  len,  last_phonemes,  no_spn_seq,  spn_labels