code: def load_sb_extended_csv(csv_path, replacements={}):
      """Loads SB Extended CSV and formats string values.
  
      Uses the SpeechBrain Extended CSV data format, where the
      CSV must have an 'ID' and 'duration' fields.
  
      The rest of the fields come in triplets:
      ``<name>, <name>_format, <name>_opts``.
  
      These add a <name>_sb_data item in the dict. Additionally, a
      basic DynamicItem (see DynamicItemDataset) is created, which
      loads the _sb_data item.
  
      Bash-like string replacements with $to_replace are supported.
  
      This format has its restriction, but they allow some tasks to
      have loading specified by the CSV.
  
      Arguments
      ----------
      csv_path : str
          Path to the CSV file.
      replacements : dict
          Optional dict:
          e.g. ``{"data_folder": "/home/speechbrain/data"}``
          This is used to recursively format all string values in the data.
  
      Returns
      -------
      dict
          CSV data with replacements applied.
      list
          List of DynamicItems to add in DynamicItemDataset.
  
      """
      with open(csv_path, newline="") as csvfile:
          result = {}
          reader = csv.DictReader(csvfile, skipinitialspace=True)
          variable_finder = re.compile(r"\$([\w.]+)")
          if not reader.fieldnames[0] == "ID":
              raise KeyError(
                  "CSV has to have an 'ID' field, with unique ids"
                  " for all data points"
              )
          if not reader.fieldnames[1] == "duration":
              raise KeyError(
                  "CSV has to have an 'duration' field, "
                  "with the length of the data point in seconds."
              )
          if not len(reader.fieldnames[2:]) % 3 == 0:
              raise ValueError(
                  "All named fields must have 3 entries: "
                  "<name>, <name>_format, <name>_opts"
              )
          names = reader.fieldnames[2::3]
          for row in reader:
              # Make a triplet for each name
              data_point = {}
              # ID:
              data_id = row["ID"]
              del row["ID"]  # This is used as a key in result, instead.
              # Duration:
              data_point["duration"] = float(row["duration"])
              del row["duration"]  # This is handled specially.
              if data_id in result:
                  raise ValueError(f"Duplicate id: {data_id}")
              # Replacements:
              # Only need to run these in the actual data,
              # not in _opts, _format
              for key, value in list(row.items())[::3]:
                  try:
                      row[key] = variable_finder.sub(
                          lambda match: replacements[match[1]], value
                      )
                  except KeyError:
                      raise KeyError(
                          f"The item {value} requires replacements "
                          "which were not supplied."
                      )
              for i, name in enumerate(names):
                  triplet = CSVItem(
                      *list(row.values())[i * 3 : i * 3 + 3]
                  )
                  data_point[name + ITEM_POSTFIX] = triplet
              result[data_id] = data_point
          # Make a DynamicItem for each CSV entry
          # _read_csv_item delegates reading to further
          dynamic_items_to_add = []
          for name in names:
              di = {
                  "func": _read_csv_item,
                  "takes": name + ITEM_POSTFIX,
                  "provides": name,
              }
              dynamic_items_to_add.append(di)
          return result, dynamic_items_to_add, names
  
file_path: speechbrain/speechbrain/dataio/legacy.py
imports: from speechbrain.dataio.dataset import DynamicItemDataset
  import collections
  import csv
  import pickle
  import logging
  import torch
  import torchaudio
  import re
label_desc: Use image node_id 1 for calling a global function with example usage: load_sb_extended_csv(csv_path, replacements) and returns: result,  dynamic_items_to_add,  names