code: def create_json(wav_list, json_file, sample_rate, model_name=None):
      """
      Creates the json file given a list of wav files.
      Arguments
      ---------
      wav_list : list of str
          The list of wav files.
      json_file : str
          The path of the output json file
      sample_rate : int
          The sample rate to be used for the dataset
      model_name : str
          Model name (used to prepare additional model specific data)
      """
  
      # Downloads and initializes the G2P model to compute the phonemes if data is being prepared for Tacotron2 experiments
      if model_name == "Tacotron2":
          logger.info(
              "Computing phonemes for labels using SpeechBrain G2P. This may take a while."
          )
          g2p = GraphemeToPhoneme.from_hparams(
              "speechbrain/soundchoice-g2p", run_opts={"device": DEVICE}
          )
  
      json_dict = {}
  
      # Processes all the wav files in the list
      for wav_file in tqdm(wav_list):
          # Reads the signal
          signal, sig_sr = torchaudio.load(wav_file)
          duration = signal.shape[1] / sig_sr
          # Manipulates path to get relative path and uttid
          path_parts = wav_file.split(os.path.sep)
          uttid, _ = os.path.splitext(path_parts[-1])
          relative_path = os.path.join("{data_root}", *path_parts[-6:])
  
          # Gets the path for the text files and extracts the input text
          normalized_text_path = os.path.join(
              "/", *path_parts[:-1], uttid + ".normalized.txt"
          )
          with open(normalized_text_path) as f:
              normalized_text = f.read()
              if normalized_text.__contains__("{"):
                  normalized_text = normalized_text.replace("{", "")
              if normalized_text.__contains__("}"):
                  normalized_text = normalized_text.replace("}", "")
  
          # Resamples the audio file if required
          if sig_sr != sample_rate:
              resampled_signal = torchaudio.functional.resample(
                  signal, sig_sr, sample_rate
              )
              os.unlink(wav_file)
              torchaudio.save(
                  wav_file, resampled_signal, sample_rate=sample_rate
              )
  
          # Gets the speaker-id from the utterance-id
          spk_id = uttid.split("_")[0]
  
          # Creates an entry for the utterance
          json_dict[uttid] = {
              "uttid": uttid,
              "wav": relative_path,
              "duration": duration,
              "spk_id": spk_id,
              "label": normalized_text,
              "segment": True if "train" in json_file else False,
          }
  
          # Characters are used for Tacotron2, phonemes may be needed for other models
          if model_name != "Tacotron2":
              # Computes phoneme labels using SpeechBrain G2P and keeps the punctuations
              phonemes = _g2p_keep_punctuations(g2p, normalized_text)
              json_dict[uttid].update({"label_phoneme": phonemes})
  
      # Writes the dictionary to the json file
      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/LibriTTS/TTS/mstacotron2/libritts_prepare.py
imports: from speechbrain.utils.data_utils import get_all_files, download_file
  import json
  import os
  import shutil
  import random
  import logging
  import torchaudio
  import torch
  from tqdm import tqdm
  from speechbrain.inference.txt import GraphemeToPhoneme
  from speechbrain.utils.text_to_sequence import _g2p_keep_punctuations
label_desc: Use image node_id 3 for calling a global function with example usage: create_json(wav_list, json_file, sample_rate, model_name) without return types