code: def prepare_ljspeech(
      data_folder,
      save_folder,
      splits=["train", "valid"],
      split_ratio=[90, 10],
      model_name=None,
      seed=1234,
      pitch_n_fft=1024,
      pitch_hop_length=256,
      pitch_min_f0=65,
      pitch_max_f0=400,
      skip_prep=False,
      use_custom_cleaner=False,
      device="cpu",
  ):
      """
      Prepares the csv files for the LJspeech datasets.
  
      Arguments
      ---------
      data_folder : str
          Path to the folder where the original LJspeech dataset is stored
      save_folder : str
          The directory where to store the csv/json files
      splits : list
          List of dataset splits to prepare
      split_ratio : list
          Proportion for dataset splits
      model_name : str
          Model name (used to prepare additional model specific data)
      seed : int
          Random seed
      pitch_n_fft : int
          Number of fft points for pitch computation
      pitch_hop_length : int
          Hop length for pitch computation
      pitch_min_f0 : int
          Minimum f0 for pitch compuation
      pitch_max_f0 : int
          Max f0 for pitch computation
      skip_prep : bool
          If True, skip preparation
      use_custom_cleaner : bool
          If True, uses custom cleaner defined for this recipe
      device : str
          Device for to be used for computation (used as required)
  
      Returns
      -------
      None
  
      Example
      -------
      >>> from recipes.LJSpeech.TTS.ljspeech_prepare import prepare_ljspeech
      >>> data_folder = 'data/LJspeech/'
      >>> save_folder = 'save/'
      >>> splits = ['train', 'valid']
      >>> split_ratio = [90, 10]
      >>> seed = 1234
      >>> prepare_ljspeech(data_folder, save_folder, splits, split_ratio, seed)
      """
      # Sets seeds for reproducible code
      random.seed(seed)
  
      if skip_prep:
          return
  
      # Creating configuration for easily skipping data_preparation stage
      conf = {
          "data_folder": data_folder,
          "splits": splits,
          "split_ratio": split_ratio,
          "save_folder": save_folder,
          "seed": seed,
      }
      if not os.path.exists(save_folder):
          os.makedirs(save_folder)
  
      # Setting ouput files
      meta_csv = os.path.join(data_folder, METADATA_CSV)
      wavs_folder = os.path.join(data_folder, WAVS)
  
      save_opt = os.path.join(save_folder, OPT_FILE)
      save_json_train = os.path.join(save_folder, TRAIN_JSON)
      save_json_valid = os.path.join(save_folder, VALID_JSON)
      save_json_test = os.path.join(save_folder, TEST_JSON)
  
      phoneme_alignments_folder = None
      duration_folder = None
      pitch_folder = None
      # Setting up additional folders required for FastSpeech2
      if model_name is not None and "FastSpeech2" in model_name:
          # This step requires phoneme alignements to be present in the data_folder
          # We automatically donwload the alignments from https://www.dropbox.com/s/v28x5ldqqa288pu/LJSpeech.zip
          # Download and unzip LJSpeech phoneme alignments from here: https://drive.google.com/drive/folders/1DBRkALpPd6FL9gjHMmMEdHODmkgNIIK4
          alignment_URL = "https://www.dropbox.com/s/v28x5ldqqa288pu/LJSpeech.zip?dl=1"
          phoneme_alignments_folder = os.path.join(
              data_folder, "TextGrid", "LJSpeech"
          )
          download_file(
              alignment_URL,
              data_folder + "/alligments.zip",
              unpack=True,
          )
  
          duration_folder = os.path.join(data_folder, "durations")
          if not os.path.exists(duration_folder):
              os.makedirs(duration_folder)
  
          # extract pitch for both Fastspeech2 and FastSpeech2WithAligner models
          pitch_folder = os.path.join(data_folder, "pitch")
          if not os.path.exists(pitch_folder):
              os.makedirs(pitch_folder)
  
      # Check if this phase is already done (if so, skip it)
      if skip(splits, save_folder, conf):
          logger.info(
              "Skipping preparation, completed in previous run."
          )
          return
  
      # Additional check to make sure metadata.csv and wavs folder exists
      assert os.path.exists(meta_csv), "metadata.csv does not exist"
      assert os.path.exists(wavs_folder), "wavs/ folder does not exist"
  
      # Prepare data splits
      msg = "Creating json file for ljspeech Dataset.."
      logger.info(msg)
      data_split, meta_csv = split_sets(
          data_folder, splits, split_ratio
      )
  
      if "train" in splits:
          prepare_json(
              model_name,
              data_split["train"],
              save_json_train,
              wavs_folder,
              meta_csv,
              phoneme_alignments_folder,
              duration_folder,
              pitch_folder,
              pitch_n_fft,
              pitch_hop_length,
              pitch_min_f0,
              pitch_max_f0,
              use_custom_cleaner,
              device,
          )
      if "valid" in splits:
          prepare_json(
              model_name,
              data_split["valid"],
              save_json_valid,
              wavs_folder,
              meta_csv,
              phoneme_alignments_folder,
              duration_folder,
              pitch_folder,
              pitch_n_fft,
              pitch_hop_length,
              pitch_min_f0,
              pitch_max_f0,
              use_custom_cleaner,
              device,
          )
      if "test" in splits:
          prepare_json(
              model_name,
              data_split["test"],
              save_json_test,
              wavs_folder,
              meta_csv,
              phoneme_alignments_folder,
              duration_folder,
              pitch_folder,
              pitch_n_fft,
              pitch_hop_length,
              pitch_min_f0,
              pitch_max_f0,
              use_custom_cleaner,
              device,
          )
      save_pkl(conf, save_opt)
  
imports: import os
  import csv
  import json
  import random
  import logging
  import torch
  import torchaudio
  import numpy
  from tqdm import tqdm
  from speechbrain.utils.data_utils import download_file
  from speechbrain.dataio.dataio import load_pkl, save_pkl
  import tgt
  from speechbrain.inference.text import GraphemeToPhoneme
  import re
  from unidecode import unidecode
  from speechbrain.utils.text_to_sequence import _g2p_keep_punctuations
label_desc: Use image node_id 1 for calling a global function with example usage: prepare_ljspeech(data_folder, save_folder, splits, split_ratio, model_name, seed, pitch_n_fft, pitch_hop_length, pitch_min_f0, pitch_max_f0, skip_prep, use_custom_cleaner, device) without return types