code: def create_asr_csv(
      orig_tsv_file, csv_file, data_folder, accented_letters=False
  ):
      """
      Creates the csv file given a list of wav files.
  
      Arguments
      ---------
      orig_tsv_file : str
          Path to the RescueSpeech tsv file (standard file).
      csv_file: str
          Path to csv file that will be saved.
      data_folder : str
          Path of the RescueSpeech domain dataset (clean, noisy, noise).
      accented_letters : bool, optional
          Defines if accented letters will be kept as individual letters or
          transformed to the closest non-accented letters.
  
      Returns
      -------
      None
      """
  
      # Check if the given files exists
      if not os.path.isfile(orig_tsv_file):
          msg = "\t%s doesn't exist, verify your dataset!" % (
              orig_tsv_file
          )
          logger.info(msg)
          raise FileNotFoundError(msg)
  
      # We load and skip the header
      loaded_csv = open(orig_tsv_file, "r").readlines()[1:]
      nb_samples = str(len(loaded_csv))
  
      msg = "Preparing CSV files for %s samples ..." % (str(nb_samples))
      logger.info(msg)
  
      # Adding some Prints
      msg = "Creating csv lists in %s ..." % (csv_file)
      logger.info(msg)
  
      csv_lines = [
          [
              "ID",
              "duration",
              "clean_wav",
              "noisy_wav",
              "clean_noisy_mix",
              "noise_wav",
              "noise_type",
              "snr_level",
              "spk_id",
              "wrd",
          ]
      ]
  
      # Noise types
      noise_types = [
          "Breathing-noise",
          "Emergency-vehicle-and-siren-noise",
          "Engine-noise",
          "Chopper-noise",
          "Static-radio-noise",
      ]
  
      idx = 0
  
      # Start processing lines
      total_duration = 0.0
      for line in tzip(loaded_csv):
          line = line[0]
  
          clean_data_fp = os.path.join(data_folder, "audio_files/clean")
          noisy_data_fp = os.path.join(data_folder, "audio_files/noisy")
          noise_data_fp = os.path.join(data_folder, "audio_files/noise")
  
          clean_fp = os.path.join(clean_data_fp, line.split("\t")[1])
          file_name = ".".join(clean_fp.split(".")).split("/")[-1]
          spk_id = line.split("\t")[0]
          snt_id = file_name
  
          # Retrieive the corresponding noisy file from noisy data file path
          clean_wav_bname = os.path.splitext(file_name)[0] + "_"
          noisy_file = [
              filename
              for filename in os.listdir(noisy_data_fp)
              if filename.startswith(clean_wav_bname)
          ]
  
          noisy_file = noisy_file[0]
          noisy_fp = os.path.join(noisy_data_fp, noisy_file)
  
          # alternate between clean and noisy wav
          idx += 1
          if idx % 2 == 0:
              clean_noisy_mix = clean_fp
          else:
              clean_noisy_mix = noisy_fp
  
          # Get corresponding noise file
          fields = os.path.splitext(noisy_file)[0].split("_")
          fileid = fields[fields.index("fileid") + 1]
          noise_file = "noise_fileid_" + str(fileid) + ".wav"
          # clean_file = "clean_fileid_" + str(fileid) + ".wav"
          noise_fp = os.path.join(noise_data_fp, noise_file)
  
          # Get noise type
          for item in noise_types:
              if item in noisy_file:
                  noise_type = item
                  break
  
          # Get SNR level
          for item in fields:
              if "snr" in item:
                  snr_level = item.replace("snr", "")
                  break
  
          # Setting torchaudio backend to sox-io (needed to read mp3 files)
          if torchaudio.get_audio_backend() != "sox_io":
              logger.warning(
                  "This recipe needs the sox-io backend of torchaudio"
              )
              logger.warning(
                  "The torchaudio backend is changed to sox_io"
              )
              torchaudio.set_audio_backend("sox_io")
  
          # Reading the signal (to retrieve duration in seconds)
          if os.path.isfile(clean_fp):
              info = torchaudio.info(clean_fp)
              info_noisy = torchaudio.info(noisy_fp)
          else:
              msg = "\tError loading: %s" % (str(len(file_name)))
              logger.info(msg)
              idx += 1
              continue
  
          duration = info.num_frames / info.sample_rate
  
          # Do some sanity check duration of clean, and noisy must be same
          duration_noisy = (
              info_noisy.num_frames / info_noisy.sample_rate
          )
          if round(duration, 3) != round(duration_noisy, 3):
              print("Length mismatch detected")
  
          total_duration += duration
  
          # Getting transcript
          words = line.split("\t")[2]
  
          # Unicode Normalization
          words = unicode_normalisation(words)
  
          # Perform data cleaning
          words = data_cleaning(words)
  
          # Remove accents if specified
          if not accented_letters:
              words = strip_accents(words)
              words = words.replace("'", " ")
              words = words.replace("’", " ")
  
          # Remove multiple spaces
          words = re.sub(" +", " ", words)
  
          # Remove spaces at the beginning and the end of the sentence
          words = words.lstrip().rstrip()
  
          # Getting chars
          chars = words.replace(" ", "_")
          chars = " ".join([char for char in chars][:])
  
          # Remove too short sentences (or empty):
          if len(words.split(" ")) < 3:
              idx += 1
              continue
  
          # Composition of the csv_line
          csv_line = [
              snt_id,
              str(duration),
              clean_fp,
              noisy_fp,
              clean_noisy_mix,
              noise_fp,
              noise_type,
              str(snr_level),
              spk_id,
              str(words),
          ]
  
          # Adding this line to the csv_lines list
          csv_lines.append(csv_line)
  
      # Writing the csv lines
      with open(csv_file, mode="w", encoding="utf-8") as csv_f:
          csv_writer = csv.writer(
              csv_f,
              delimiter=",",
              quotechar='"',
              quoting=csv.QUOTE_MINIMAL,
          )
  
          for line in csv_lines:
              csv_writer.writerow(line)
  
      # Final prints
      msg = "%s successfully created!" % (csv_file)
      logger.info(msg)
      msg = "Number of samples: %s " % (str(len(loaded_csv)))
      logger.info(msg)
      msg = "Total duration: %s Hours" % (
          str(round(total_duration / 3600, 2))
      )
      logger.info(msg)
  
file_path: speechbrain/recipes/RescueSpeech/rescuespeech_prepare.py
imports: import os
  import re
  import csv
  import glob
  import logging
  import torchaudio
  import unicodedata
  from tqdm import tqdm
  from tqdm.contrib import tzip
  from speechbrain.dataio.dataio import read_audio
label_desc: Use image node_id 3 for calling a global function with example usage: create_asr_csv(orig_tsv_file, csv_file, data_folder, accented_letters) without return types