code: def generate_silence_data(
      num_known_samples_per_split,
      splits,
      data_folder,
      percentage_silence=26,
  ):
      """Generates silence samples.
  
      Arguments
      ---------
      num_known_samples_per_split: int
          Total number of samples of known words for each split (i.e. set).
      splits: str
          Training, validation and test sets.
      data_folder: str
          path to dataset.
      percentage_silence: int
          How many silence samples to generate; relative to the total number of known words.
      """
      for split in splits:
          num_silence_samples = int(
              (percentage_silence / 100.0)
              * num_known_samples_per_split[split]
          )
  
          # Fetch all background noise wav files used to generate silence samples
          search_path = os.path.join(
              data_folder, "_background_noise_", "*.wav"
          )
          silence_paths = []
          for wav_path in glob.glob(search_path):
              silence_paths.append(wav_path)
  
          # Generate random silence samples
          # Assumes that the pytorch seed has been defined in the HyperPyYaml file
          num_silence_samples_per_path = int(
              num_silence_samples / len(silence_paths)
          )
          for silence_path in silence_paths:
              signal = read_audio(silence_path)
              random_starts = (
                  (
                      torch.rand(num_silence_samples_per_path)
                      * (signal.shape[0] - 16001)
                  )
                  .type(torch.int)
                  .tolist()
              )
  
              for i, random_start in enumerate(random_starts):
                  splits[split]["ID"].append(
                      re.sub(
                          r".wav",
                          "/" + str(random_start) + "_" + str(i),
                          re.sub(
                              r".+?(?=_background_noise_)",
                              "",
                              silence_path,
                          ),
                      )
                  )
  
                  splits[split]["duration"].append(1.0)
                  splits[split]["start"].append(random_start)
                  splits[split]["stop"].append(random_start + 16000)
                  splits[split]["wav"].append(silence_path)
                  splits[split]["spk_id"].append(None)
                  splits[split]["command"].append("silence")
                  splits[split]["transcript"].append(None)
  
file_path: speechbrain/recipes/Google-speech-commands/prepare_GSC.py
imports: import os
  from os import walk
  import glob
  import shutil
  import logging
  import torch
  import re
  import hashlib
  import copy
  import numpy
  from speechbrain.utils.data_utils import download_file
  from speechbrain.dataio.dataio import read_audio
label_desc: Use image node_id 3 for calling a global function with example usage: generate_silence_data(num_known_samples_per_split, splits, data_folder, percentage_silence) without return types