code: def read_pkl(file, data_options={}, lab2ind=None):
      """This function reads tensors store in pkl format.
  
      Arguments
      ---------
      file : str
          The path to file to read.
      data_options : dict, optional
          A dictionary containing options for the reader.
      lab2ind : dict, optional
          Mapping from label to integer indices.
  
      Returns
      -------
      numpy.array
          The array containing the read signal.
      """
  
      # Trying to read data
      try:
          with open(file, "rb") as f:
              pkl_element = pickle.load(f)
      except pickle.UnpicklingError:
          err_msg = "cannot read the pkl file %s" % (file)
          raise ValueError(err_msg)
  
      type_ok = False
  
      if isinstance(pkl_element, list):
          if isinstance(pkl_element[0], float):
              tensor = torch.FloatTensor(pkl_element)
              type_ok = True
  
          if isinstance(pkl_element[0], int):
              tensor = torch.LongTensor(pkl_element)
              type_ok = True
  
          if isinstance(pkl_element[0], str):
              # convert string to integer as specified in self.label_dict
              if lab2ind is not None:
                  for index, val in enumerate(pkl_element):
                      pkl_element[index] = lab2ind[val]
  
              tensor = torch.LongTensor(pkl_element)
              type_ok = True
  
          if not (type_ok):
              err_msg = (
                  "The pkl file %s can only contain list of integers, "
                  "floats, or strings. Got %s"
              ) % (file, type(pkl_element[0]))
              raise ValueError(err_msg)
      else:
          tensor = pkl_element
  
      tensor_type = tensor.dtype
  
      # Conversion to 32 bit (if needed)
      if tensor_type == "float64":
          tensor = tensor.astype("float32")
  
      if tensor_type == "int64":
          tensor = tensor.astype("int32")
  
      return tensor
  
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 4 for calling a global function with example usage: read_pkl(file, data_options, lab2ind) and returns: tensor