code: def prepare_GSC(
      data_folder,
      save_folder,
      validation_percentage=10,
      testing_percentage=10,
      percentage_unknown=10,
      percentage_silence=10,
      words_wanted=[
          "yes",
          "no",
          "up",
          "down",
          "left",
          "right",
          "on",
          "off",
          "stop",
          "go",
      ],
      skip_prep=False,
  ):
      """
      Prepares the Google Speech Commands V2 dataset.
  
      Arguments
      ---------
      data_folder : str
          path to dataset. If not present, it will be downloaded here.
      save_folder: str
          folder where to store the data manifest files.
      validation_percentage: int
          How much of the data set to use for validation.
      testing_percentage: int
          How much of the data set to use for testing.
      percentage unknown: int.
          How much data outside of the known (i.e wanted) words to preserve; relative to the total number of known words.
      percentage silence: int
          How many silence samples to generate; relative to the total number of known words.
      skip_prep: bool
          If True, skip data preparation.
  
      Example
      -------
      >>> data_folder = '/path/to/GSC'
      >>> prepare_GSC(data_folder)
      """
  
      if skip_prep:
          return
  
      # If the data folders do not exist, we need to extract the data
      if not os.path.isdir(os.path.join(data_folder, "train-synth")):
          # Check for zip file and download if it doesn't exist
          tar_location = os.path.join(
              data_folder, "speech_commands_v0.02.tar.gz"
          )
          if not os.path.exists(tar_location):
              download_file(GSC_URL, tar_location, unpack=True)
          else:
              logger.info("Extracting speech_commands_v0.02.tar.gz...")
              shutil.unpack_archive(tar_location, data_folder)
  
      # Define the words that we do not want to identify
      unknown_words = list(np.setdiff1d(all_words, words_wanted))
  
      # All metadata fields to appear within our dataset annotation files (i.e. train.csv, valid.csv, test.cvs)
      fields = {
          "ID": [],
          "duration": [],
          "start": [],
          "stop": [],
          "wav": [],
          "spk_id": [],
          "command": [],
          "transcript": [],
      }
  
      splits = {
          "train": copy.deepcopy(fields),
          "valid": copy.deepcopy(fields),
          "test": copy.deepcopy(fields),
      }
  
      num_known_samples_per_split = {"train": 0, "valid": 0, "test": 0}
      words_wanted_parsed = False
      commands = words_wanted + unknown_words
      for i, command in enumerate(commands):
          # logger.info("Preparing {}/{} commands...".format(i, len(commands)))
  
          # Indicate once all wanted words are parsed
          if i >= len(words_wanted) and not words_wanted_parsed:
              num_known_samples_total = np.sum(
                  list(num_known_samples_per_split.values())
              )
              num_unknown_samples_total = (
                  105829 - num_known_samples_total
              )
              percentage_applied_to_unknown_samples = (
                  percentage_unknown * num_known_samples_total
              ) / num_unknown_samples_total
              words_wanted_parsed = True
  
          # Read all files under a specific class (i.e. command)
          files = []
          for dirpath, dirnames, filenames in walk(
              os.path.join(data_folder, command)
          ):
              files.extend(filenames)
              break
  
          # Fill in all fields with metadata for each audio sample file under a specific class
          for filename in files:
              # Once all wanted words are parsed, only retain the required percentage of unknown words
              if (
                  words_wanted_parsed
                  and torch.rand(1)[0].tolist()
                  > percentage_applied_to_unknown_samples / 100
              ):
                  continue
  
              # select the required split (i.e. set) for the sample
              split = which_set(
                  filename, validation_percentage, testing_percentage
              )
  
              splits[split]["ID"].append(
                  command + "/" + re.sub(r".wav", "", filename)
              )
  
              # We know that all recordings are 1 second long (i.e.16000 frames). No need to compute the duration.
              splits[split]["duration"].append(1.0)
              splits[split]["start"].append(0)
              splits[split]["stop"].append(16000)
  
              splits[split]["wav"].append(
                  os.path.join(data_folder, command, filename)
              )
  
              splits[split]["spk_id"].append(
                  re.sub(r"_.*", "", filename)
              )
  
              if command in words_wanted:
                  splits[split]["command"].append(command)
  
                  num_known_samples_per_split[split] += 1
              else:
                  splits[split]["command"].append("unknown")
  
              splits[split]["transcript"].append(command)
  
      if percentage_silence > 0:
          generate_silence_data(
              num_known_samples_per_split,
              splits,
              data_folder,
              percentage_silence=percentage_silence,
          )
  
      for split in splits:
          new_filename = os.path.join(save_folder, split) + ".csv"
          new_df = pd.DataFrame(splits[split])
          new_df.to_csv(new_filename, index=False)
  
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 1 for calling a global function with example usage: prepare_GSC(data_folder, save_folder, validation_percentage, testing_percentage, percentage_unknown, percentage_silence, words_wanted, skip_prep) without return types