code: def create_json(metadata, audio_data_folder, folds_list, json_file):
      """
      Creates the json file given a list of wav files.
      Arguments
      ---------
      metadata: dict
          A dictionary containing the ESC50 metadata file modified for the
          SpeechBrain, such that keys are IDs (which are the .wav file names without the file extension).
      audio_data_folder : str or Path
          Data folder that stores ESC50 samples.
      folds_list : list of int
          The list of folds [1,5] to include in this batch
      json_file : str
          The path of the output json file
      """
      # Processing all the wav files in the list
      json_dict = {}
  
      for ID, sample_metadata in metadata.items():
          fold_num = int(sample_metadata["fold"])
          if fold_num in folds_list:
              # Reading the signal (to retrieve duration in seconds)
              wav_file = os.path.join(
                  os.path.abspath(audio_data_folder),
                  # "fold" + str(fold_num) + "/",
                  sample_metadata["filename"],
              )
              try:
                  signal = read_audio(wav_file)
                  file_info = torchaudio.info(wav_file)
  
                  # If we're using sox/soundfile backend, file_info will have the old type
                  if isinstance(
                      file_info, torchaudio.backend.common.AudioMetaData
                  ):
                      duration = signal.shape[0] / file_info.sample_rate
                  else:
                      duration = signal.shape[0] / file_info[0].rate
  
                  # Create entry for this sample ONLY if we have successfully read-in the file using SpeechBrain/torchaudio
                  json_dict[ID] = {
                      "wav": sample_metadata["filename"],
                      "classID": int(sample_metadata["target"]),
                      "class_string": sample_metadata["class_string"],
                      # "salience": int(sample_metadata["salience"]),
                      "fold": sample_metadata["fold"],
                      "duration": duration,
                  }
              except Exception:
                  print(
                      f"There was a problem reading the file:{wav_file}. Skipping duration field for it."
                  )
                  logger.exception(
                      f"There was a problem reading the file:{wav_file}. Skipping it."
                  )
  
      # Writing the dictionary to the json file
      # Need to make sure sub folder "manifest" exists, if not create it
      parent_dir = os.path.dirname(json_file)
      if not os.path.exists(parent_dir):
          os.mkdir(parent_dir)
  
      with open(json_file, mode="w") as json_f:
          json.dump(json_dict, json_f, indent=2)
  
      logger.info(f"{json_file} successfully created!")
  
file_path: speechbrain/recipes/ESC50/classification/esc50_prepare.py
imports: import os
  import shutil
  import json
  import logging
  import torchaudio
  from speechbrain.dataio.dataio import read_audio
  from speechbrain.dataio.dataio import load_data_csv
  from speechbrain.utils.fetching import fetch
label_desc: Use image node_id 3 for calling a global function with example usage: create_json(metadata, audio_data_folder, folds_list, json_file) without return types