code: def main_body():  # noqa
      """Main body of this file"""
  
      params = dict()
  
      # Load hyperparameters file with command-line overrides
      hparams_file, run_opts, overrides = sb.parse_arguments(
          sys.argv[1:]
      )
      with open(hparams_file) as fin:
          hparams = load_hyperpyyaml(fin, overrides)
  
      # Data Directories and Settings
      params["split_name"] = hparams["split_name"]
  
      # Audio Settings
      params["fs"] = int(hparams["sampling_rate"])
      params["fs_input"] = int(
          hparams["input_sampling_rate"]
      )  # Sampling rate of input data
      params["audioformat"] = hparams["audioformat"]
      params["audio_length"] = float(hparams["audio_length"])
      params["silence_length"] = float(hparams["silence_length"])
      params["total_hours"] = float(hparams["total_hours"])
  
      # Clean Data Categories
      params["use_singing_data"] = int(hparams["use_singing_data"])
      if hasattr(hparams, "clean_singing"):
          params["clean_singing"] = str(hparams["clean_singing"])
      params["singing_choice"] = int(hparams["singing_choice"])
  
      params["use_emotion_data"] = int(hparams["use_emotion_data"])
      if hasattr(hparams, "clean_emotion"):
          params["clean_emotion"] = str(hparams["clean_emotion"])
  
      params["use_mandarin_data"] = int(hparams["use_mandarin_data"])
      if hasattr(hparams, "clean_mandarin"):
          params["clean_mandarin"] = str(hparams["clean_mandarin"])
  
      # Room Impulse Response (RIR) Settings
      params["rir_choice"] = int(hparams["rir_choice"])
      params["lower_t60"] = float(hparams["lower_t60"])
      params["upper_t60"] = float(hparams["upper_t60"])
      params["rir_table_csv"] = str(hparams["rir_table_csv"])
  
      # File Indexing
      if (
          hparams["fileindex_start"] != "None"
          and hparams["fileindex_end"] != "None"
      ):
          params["num_files"] = int(hparams["fileindex_end"]) - int(
              params["fileindex_start"]
          )
          params["fileindex_start"] = int(hparams["fileindex_start"])
          params["fileindex_end"] = int(hparams["fileindex_end"])
      else:
          params["num_files"] = int(
              (params["total_hours"] * 60 * 60) / params["audio_length"]
          )
          params["fileindex_start"] = 0
          params["fileindex_end"] = params["num_files"]
  
      print("Number of files to be synthesized:", params["num_files"])
  
      # Data Generation and Synthesis Settings
      params["is_test_set"] = utils.str2bool(
          str(hparams["is_test_set"])
      )
      params["clean_activity_threshold"] = float(
          hparams["clean_activity_threshold"]
      )
      params["noise_activity_threshold"] = float(
          hparams["noise_activity_threshold"]
      )
      params["snr_lower"] = int(hparams["snr_lower"])
      params["snr_upper"] = int(hparams["snr_upper"])
      params["randomize_snr"] = utils.str2bool(
          str(hparams["randomize_snr"])
      )
      params["target_level_lower"] = int(hparams["target_level_lower"])
      params["target_level_upper"] = int(hparams["target_level_upper"])
  
      if hasattr(hparams, "snr"):
          params["snr"] = int(hparams["snr"])
      else:
          params["snr"] = int(
              (params["snr_lower"] + params["snr_upper"]) / 2
          )
  
      # Synthesized Data Destination
      params["samples_per_shard"] = hparams["samples_per_shard"]
      params["train_shard_destination"] = hparams[
          "train_shard_destination"
      ]
      params["valid_shard_destination"] = hparams[
          "valid_shard_destination"
      ]
  
      #### Shard data extraction ~~~
      # load the meta info json file
  
      with wds.gopen(hparams["clean_meta"], "rb") as f:
          clean_meta = json.load(f)
      with wds.gopen(hparams["noise_meta"], "rb") as f:
          noise_meta = json.load(f)
  
      def audio_pipeline(sample_dict: Dict, random_chunk=True):
          key = sample_dict["__key__"]
          audio_tensor = sample_dict["audio.pth"]
  
          sig = audio_tensor.squeeze()
  
          return {
              "sig": sig,
              "id": key,
          }
  
      clean_data = (
          wds.WebDataset(
              hparams["clean_fullband_shards"],
              cache_dir=hparams["shard_cache_dir"],
          )
          .repeat()
          .shuffle(1000)
          .decode("pil")
          .map(partial(audio_pipeline, random_chunk=True))
      )
      print(
          f"Clean data consist of {clean_meta['num_data_samples']} samples"
      )
  
      noise_data = (
          wds.WebDataset(
              hparams["noise_fullband_shards"],
              cache_dir=hparams["shard_cache_dir"],
          )
          .repeat()
          .shuffle(1000)
          .decode("pil")
          .map(partial(audio_pipeline, random_chunk=True))
      )
      print(
          f"Noise data consist of {noise_meta['num_data_samples']} samples"
      )
  
      params["clean_data"] = clean_data
      params["noise_data"] = noise_data
  
      # add singing voice to clean speech
      if params["use_singing_data"] == 1:
          raise NotImplementedError("Add sining voice to clean speech")
      else:
          print("NOT using singing data for training!")
  
      # add emotion data to clean speech
      if params["use_emotion_data"] == 1:
          raise NotImplementedError(
              "Add emotional data to clean speech"
          )
      else:
          print("NOT using emotion data for training!")
  
      # add mandarin data to clean speech
      if params["use_mandarin_data"] == 1:
          raise NotImplementedError("Add Mandarin data to clean speech")
      else:
          print("NOT using non-english (Mandarin) data for training!")
  
      # rir
      temp = pd.read_csv(
          params["rir_table_csv"],
          skiprows=[1],
          sep=",",
          header=None,
          names=["wavfile", "channel", "T60_WB", "C50_WB", "isRealRIR"],
      )
      temp.keys()
      # temp.wavfile
  
      rir_wav = temp["wavfile"][1:]  # 115413
      rir_channel = temp["channel"][1:]
      rir_t60 = temp["T60_WB"][1:]
      rir_isreal = temp["isRealRIR"][1:]
  
      rir_wav2 = [w.replace("\\", "/") for w in rir_wav]
      rir_channel2 = [w for w in rir_channel]
      rir_t60_2 = [w for w in rir_t60]
      rir_isreal2 = [w for w in rir_isreal]
  
      myrir = []
      mychannel = []
      myt60 = []
  
      lower_t60 = params["lower_t60"]
      upper_t60 = params["upper_t60"]
  
      if params["rir_choice"] == 1:  # real 3076 IRs
          real_indices = [
              i for i, x in enumerate(rir_isreal2) if x == "1"
          ]
  
          chosen_i = []
          for i in real_indices:
              if (float(rir_t60_2[i]) >= lower_t60) and (
                  float(rir_t60_2[i]) <= upper_t60
              ):
                  chosen_i.append(i)
  
          myrir = [rir_wav2[i] for i in chosen_i]
          mychannel = [rir_channel2[i] for i in chosen_i]
          myt60 = [rir_t60_2[i] for i in chosen_i]
  
      elif params["rir_choice"] == 2:  # synthetic 112337 IRs
          synthetic_indices = [
              i for i, x in enumerate(rir_isreal2) if x == "0"
          ]
  
          chosen_i = []
          for i in synthetic_indices:
              if (float(rir_t60_2[i]) >= lower_t60) and (
                  float(rir_t60_2[i]) <= upper_t60
              ):
                  chosen_i.append(i)
  
          myrir = [rir_wav2[i] for i in chosen_i]
          mychannel = [rir_channel2[i] for i in chosen_i]
          myt60 = [rir_t60_2[i] for i in chosen_i]
  
      elif params["rir_choice"] == 3:  # both real and synthetic
          all_indices = [i for i, x in enumerate(rir_isreal2)]
  
          chosen_i = []
          for i in all_indices:
              if (float(rir_t60_2[i]) >= lower_t60) and (
                  float(rir_t60_2[i]) <= upper_t60
              ):
                  chosen_i.append(i)
  
          myrir = [rir_wav2[i] for i in chosen_i]
          mychannel = [rir_channel2[i] for i in chosen_i]
          myt60 = [rir_t60_2[i] for i in chosen_i]
  
      else:  # default both real and synthetic
          all_indices = [i for i, x in enumerate(rir_isreal2)]
  
          chosen_i = []
          for i in all_indices:
              if (float(rir_t60_2[i]) >= lower_t60) and (
                  float(rir_t60_2[i]) <= upper_t60
              ):
                  chosen_i.append(i)
  
          myrir = [rir_wav2[i] for i in chosen_i]
          mychannel = [rir_channel2[i] for i in chosen_i]
          myt60 = [rir_t60_2[i] for i in chosen_i]
  
      params["myrir"] = myrir
      params["mychannel"] = mychannel
      params["myt60"] = myt60
  
      # Call main_gen() to generate audio
      (
          clean_source_files,
          clean_clipped_files,
          clean_low_activity_files,
          noise_source_files,
          noise_clipped_files,
          noise_low_activity_files,
      ) = main_gen(params)
  
      # Create log directory if needed, and write log files of clipped and low activity files
      log_dir = utils.get_dir(hparams, "log_dir", "Logs")
  
      utils.write_log_file(
          log_dir,
          "source_files.csv",
          clean_source_files + noise_source_files,
      )
      utils.write_log_file(
          log_dir,
          "clipped_files.csv",
          clean_clipped_files + noise_clipped_files,
      )
      utils.write_log_file(
          log_dir,
          "low_activity_files.csv",
          clean_low_activity_files + noise_low_activity_files,
      )
  
      # Compute and print stats about percentange of clipped and low activity files
      total_clean = (
          len(clean_source_files)
          + len(clean_clipped_files)
          + len(clean_low_activity_files)
      )
      total_noise = (
          len(noise_source_files)
          + len(noise_clipped_files)
          + len(noise_low_activity_files)
      )
      pct_clean_clipped = round(
          len(clean_clipped_files) / total_clean * 100, 1
      )
      pct_noise_clipped = round(
          len(noise_clipped_files) / total_noise * 100, 1
      )
      pct_clean_low_activity = round(
          len(clean_low_activity_files) / total_clean * 100, 1
      )
      pct_noise_low_activity = round(
          len(noise_low_activity_files) / total_noise * 100, 1
      )
  
      print(
          "\nOf the "
          + str(total_clean)
          + " clean speech files analyzed, "
          + str(pct_clean_clipped)
          + "% had clipping, and "
          + str(pct_clean_low_activity)
          + "% had low activity "
          + "(below "
          + str(params["clean_activity_threshold"] * 100)
          + "% active percentage)"
      )
      print(
          "Of the "
          + str(total_noise)
          + " noise files analyzed, "
          + str(pct_noise_clipped)
          + "% had clipping, and "
          + str(pct_noise_low_activity)
          + "% had low activity "
          + "(below "
          + str(params["noise_activity_threshold"] * 100)
          + "% active percentage)"
      )
  
imports: import sys
  import os
  from pathlib import Path
  import random
  import time
  import numpy
  from scipy import signal
  from scipy.io import wavfile
  import librosa
  import utils
  from audiolib import segmental_snr_mixer, activitydetector, is_clipped
  import pandas
  import json
  from functools import partial
  from typing import Dict
  from collections import defaultdict
  import speechbrain
  import webdataset
  from hyperpyyaml import load_hyperpyyaml
  import torch
label_desc: Use image node_id 5 for calling a global function with example usage: main_body() and returns: dict