code: def swbd1_data_prep(
      data_folder,
      save_folder,
      splits,
      split_ratio,
      add_fisher_corpus=False,
      max_utt=9999999999,
  ):
      """
      Prepare the Switchboard Phase 1 training data (LDC97S62).
  
      Parameters
      ----------
      data_folder : str
          Path to the data. Expects the LDC97S62 directory to be located there.
      save_folder :
          Path where the file output will be stored
      splits : list
          A list of data splits you want to obtain from the Switchboard dataset (usually ["train", "dev"])
      split_ratio : list
          List containing the portions you want to allocate to each of your data splits e.g. [90, 10]
      add_fisher_corpus : bool
          If True, a separate csv file called "train_lm.csv" will be createdm which contains
          the Switchboard training data and the Fisher corpus transcripts.
      max_utt
          Exclude utterances once they appear more than a specified number of times
  
      Returns
      -------
      A list containing the prepared data for further processing
      """
  
      logger.info(
          "Starting data preparation for main Switchboard corpus"
      )
  
      train_data_folder = os.path.join(data_folder, "LDC97S62")
      check_data_folder(train_data_folder)
  
      if not os.path.exists(save_folder):
          os.makedirs(save_folder)
  
      download_transcripts(save_folder)
  
      # Make a mapping from Switchboard acronyms to Fisher convention
      logger.info("Preparing acronym mappings")
      lexicon_input_file = os.path.join(
          save_folder, "swb_ms98_transcriptions", "sw-ms98-dict.text"
      )
      acronym_map_output_file = os.path.join(
          save_folder, "acronyms.map"
      )
      dict_acronym, dict_acronym_noi = make_acronym_map(
          save_folder, lexicon_input_file, acronym_map_output_file
      )
  
      assert len(splits) == len(split_ratio)
      if sum(split_ratio) != 100 and sum(split_ratio) != 1:
          error_msg = "Implausible split ratios! Make sure they equal to 1 (or 100)."
          raise ValueError(error_msg)
      if sum(split_ratio) == 100:
          split_ratio = [i / 100 for i in split_ratio]
  
      # collect all files containing transcriptions
      transcript_files = get_all_files(
          os.path.join(save_folder, "swb_ms98_transcriptions"),
          match_and=["trans.text"],
      )
      split_lens = [int(i * len(transcript_files)) for i in split_ratio]
  
      name2disk = make_name_to_disk_dict(
          os.path.join(train_data_folder, "docs/swb1_all.dvd.tbl")
      )
      logger.info(
          f"Made name2disk mapping dict containing {len(name2disk)} conversations."
      )
  
      start = 0
      stop = 0
      # We save all lines from the swbd train split, in case we want to combine them
      # with the Fisher corpus for LM and Tokenizer training later
      swbd_train_lines = []
      for i, split in enumerate(splits):
          stop += split_lens[i]
          transcript_files_split = transcript_files[start:stop]
          logger.info(
              f"Preparing data for {split} split. "
              f"Split will contain {len(transcript_files_split)} "
              f"conversations separated by channel."
          )
  
          start += split_lens[i]
  
          csv_lines = [
              [
                  "ID",
                  "duration",
                  "start",
                  "stop",
                  "channel",
                  "wav",
                  "words",
                  "spk_id",
              ]
          ]
          # Open each transcription file and extract information
          for filename in transcript_files_split:
              with open(filename) as file:
                  for line in file:
                      str_split = line.split()
                      id = str_split[0].strip()
                      channel = id.split("-")[0][-1]
                      wav_name = id.split("-")[0][:6] + ".sph"
                      spk_id = wav_name.replace(".sph", channel)
                      wav_name = wav_name.replace(wav_name[0:2], "sw0")
                      disk = name2disk[wav_name]
  
                      wav_path = os.path.join(
                          train_data_folder, disk, "data", wav_name
                      )
                      # We want the segment start and end times in samples,
                      # so we can slice the segment from the tensor
                      seg_start = int(
                          float(str_split[1].strip()) * SAMPLERATE
                      )
                      seg_end = int(
                          float(str_split[2].strip()) * SAMPLERATE
                      )
                      audio_duration = (
                          seg_end - seg_start
                      ) / SAMPLERATE
  
                      transcription = " ".join(str_split[3:])
                      cleaned_transcription = filter_text(
                          transcription,
                          dataset="train",
                          acronyms=dict_acronym,
                          acronyms_noi=dict_acronym_noi,
                      )
  
                      # Skip empty transcriptions
                      if len(cleaned_transcription) > 0:
                          csv_lines.append(
                              [
                                  id,
                                  audio_duration,
                                  seg_start,
                                  seg_end,
                                  channel,
                                  wav_path,
                                  cleaned_transcription,
                                  spk_id,
                              ]
                          )
  
                          # We store the lines from the first split
                          # (assuming this is the training data) in a separate list
                          # so we can easily merge it with the Fisher data later
                          if add_fisher_corpus and i == 0:
                              swbd_train_lines.append(
                                  [id, cleaned_transcription]
                              )
          # Setting path for the csv file
          csv_file = os.path.join(save_folder, str(split + ".csv"))
          logger.info(f"Creating csv file {csv_file}")
  
          write_csv(csv_file, csv_lines, utt_id_idx=6, max_utt=max_utt)
      return swbd_train_lines
  
imports: import re
  import csv
  import logging
  import os
  from collections import defaultdict
  from speechbrain.dataio.dataio import merge_csvs
  from speechbrain.utils.data_utils import download_file, get_all_files
label_desc: Use image node_id 16 for calling a global function with example usage: swbd1_data_prep(data_folder, save_folder, splits, split_ratio, add_fisher_corpus, max_utt) and returns: swbd_train_lines