code: def build_spk_hashtable_librimix(hparams):
      """
      This function builds a dictionary of speaker-utterance pairs to be used in dynamic mixing
      """
      libri_utterances = glob.glob(
          os.path.join(hparams["base_folder_dm"], "**/*.wav"),
          recursive=True,
      )
  
      spk_hashtable = {}
  
      # just for one file check if the sample rate is correct
      assert (
          torchaudio.info(libri_utterances[0]).sample_rate
          == hparams["sample_rate"]
      )
      for utt in tqdm(libri_utterances):
          path = os.path.normpath(utt)
          path_list = path.split(os.sep)
          spk_id = path_list[-3]
  
          # e.g. LibriSpeech/train-clean-100/441/128988/441-128988-0014.flac
          # id of speaker is 441 utterance is 128988-0014
  
          if spk_id not in spk_hashtable.keys():
              spk_hashtable[spk_id] = [utt]
          else:
              spk_hashtable[spk_id].append(utt)
  
      # calculate weights for each speaker ( len of list of utterances)
      spk_weights = [
          len(spk_hashtable[x]) for x in spk_hashtable.keys()
      ]
  
      return spk_hashtable, spk_weights
  
file_path: speechbrain/recipes/LibriMix/separation/dynamic_mixing.py
imports: import speechbrain
  import numpy
  import torch
  import torchaudio
  import glob
  import os
  from speechbrain.dataio.batch import PaddedBatch
  from tqdm import tqdm
  import warnings
  import pyloudnorm
  import random
label_desc: Use image node_id 1 for calling a global function with example usage: build_spk_hashtable_librimix(hparams) and returns: spk_hashtable,  spk_weights