code: def concat_wavs(data_folder, save_json):
      """
      Concatenate audios from the same speaker
      The concatenation is produced with a probability for each modality
      The amplitude of the sub-sentences are made equal during concatenation
      """
      data_json = {}
      for repo in repos:
          emotion_wavs = []
          neutral_wavs = []
  
          paths = Path(os.path.join(data_folder, "processed", repo))
          angry_files = paths.rglob("*angry*.wav")
          happy_files = paths.rglob("*happy*.wav")
          excited_files = paths.rglob("*excited*.wav")
          sad_files = paths.rglob("*sad*.wav")
          neutral_files = paths.rglob("*neutral*.wav")
  
          for file in angry_files:
              emotion_wavs.append(str(file))
          for file in happy_files:
              emotion_wavs.append(str(file))
          for file in excited_files:
              emotion_wavs.append(str(file))
          for file in sad_files:
              emotion_wavs.append(str(file))
          for file in neutral_files:
              neutral_wavs.append(str(file))
  
          random.shuffle(emotion_wavs)
          random.shuffle(neutral_wavs)
          neutral_wavs = neutral_wavs * 10
  
          combine_path = os.path.join(data_folder, "combined", repo)
          if not os.path.exists(combine_path):
              os.makedirs(combine_path)
  
          while len(emotion_wavs) > 0:
              combination = np.random.choice(
                  combinations, p=probabilities.ravel()
              )
              if combination == "neu_emo":
                  neutral_sample = neutral_wavs[0]
                  emo_sample = emotion_wavs[0]
  
                  neutral_input = AudioSegment.from_wav(neutral_sample)
                  emotion_input = AudioSegment.from_wav(emo_sample)
  
                  emotion_input += (
                      neutral_input.dBFS - emotion_input.dBFS
                  )
                  combined_input = neutral_input + emotion_input
  
                  out_name = os.path.join(
                      combine_path,
                      neutral_sample.split("/")[-1][:-4]
                      + "_"
                      + emo_sample.split("/")[-1],
                  )
                  combined_input.export(out_name, format="wav")
  
                  id = repo + "_" + out_name.split("/")[-1][:-4]
                  data_json[id] = {
                      "wav": out_name,
                      "duration": len(combined_input) / 1000,
                      "emotion": [
                          {
                              "emo": get_emotion(emo_sample),
                              "start": len(neutral_input) / 1000,
                              "end": len(combined_input) / 1000,
                          }
                      ],
                  }
  
                  neutral_wavs = neutral_wavs[1:]
                  emotion_wavs = emotion_wavs[1:]
  
              elif combination == "emo_neu":
                  neutral_sample = neutral_wavs[0]
                  emo_sample = emotion_wavs[0]
  
                  neutral_input = AudioSegment.from_wav(neutral_sample)
                  emotion_input = AudioSegment.from_wav(emo_sample)
  
                  neutral_input += (
                      emotion_input.dBFS - neutral_input.dBFS
                  )
                  combined_input = emotion_input + neutral_input
  
                  out_name = os.path.join(
                      combine_path,
                      emo_sample.split("/")[-1][:-4]
                      + "_"
                      + neutral_sample.split("/")[-1],
                  )
                  combined_input.export(out_name, format="wav")
  
                  id = repo + "_" + out_name.split("/")[-1][:-4]
                  data_json[id] = {
                      "wav": out_name,
                      "duration": len(combined_input) / 1000,
                      "emotion": [
                          {
                              "emo": get_emotion(emo_sample),
                              "start": 0,
                              "end": len(emotion_input) / 1000,
                          }
                      ],
                  }
  
                  emotion_wavs = emotion_wavs[1:]
                  neutral_wavs = neutral_wavs[1:]
  
              elif combination == "neu_emo_neu":
                  neutral_sample_1 = neutral_wavs[0]
                  neutral_sample_2 = neutral_wavs[1]
                  emo_sample = emotion_wavs[0]
  
                  neutral_input_1 = AudioSegment.from_wav(
                      neutral_sample_1
                  )
                  neutral_input_2 = AudioSegment.from_wav(
                      neutral_sample_2
                  )
                  emotion_input = AudioSegment.from_wav(emo_sample)
  
                  emotion_input += (
                      neutral_input_1.dBFS - emotion_input.dBFS
                  )
                  neutral_input_2 += (
                      neutral_input_1.dBFS - neutral_input_2.dBFS
                  )
                  combined_input = (
                      neutral_input_1 + emotion_input + neutral_input_2
                  )
  
                  out_name = os.path.join(
                      combine_path,
                      neutral_sample_1.split("/")[-1][:-4]
                      + "_"
                      + emo_sample.split("/")[-1][:-4]
                      + "_"
                      + neutral_sample_2.split("/")[-1],
                  )
                  combined_input.export(out_name, format="wav")
  
                  id = repo + "_" + out_name.split("/")[-1][:-4]
                  data_json[id] = {
                      "wav": out_name,
                      "duration": len(combined_input) / 1000,
                      "emotion": [
                          {
                              "emo": get_emotion(emo_sample),
                              "start": len(neutral_input_1) / 1000,
                              "end": len(neutral_input_1) / 1000
                              + len(emotion_input) / 1000,
                          }
                      ],
                  }
  
                  emotion_wavs = emotion_wavs[1:]
                  neutral_wavs = neutral_wavs[2:]
  
              else:
                  emo_sample_1 = emotion_wavs[0]
  
                  emotion_input_1 = AudioSegment.from_wav(emo_sample_1)
  
                  out_name = os.path.join(
                      combine_path, emo_sample_1.split("/")[-1]
                  )
                  emotion_input_1.export(out_name, format="wav")
  
                  id = repo + "_" + out_name.split("/")[-1][:-4]
                  data_json[id] = {
                      "wav": out_name,
                      "duration": len(emotion_input_1) / 1000,
                      "emotion": [
                          {
                              "emo": get_emotion(emo_sample_1),
                              "start": 0,
                              "end": len(emotion_input_1) / 1000,
                          }
                      ],
                  }
  
                  emotion_wavs = emotion_wavs[1:]
  
      with open(save_json, "w") as outfile:
          json.dump(data_json, outfile)
      return data_json
  
file_path: speechbrain/recipes/ZaionEmotionDataset/emotion_diarization/datasets/prepare_JLCORPUS.py
imports: import numpy
  import os
  import random
  from pydub import AudioSegment
  import json
  from datasets.vad import vad_for_folder
  from pathlib import Path
  import shutil
  import logging
label_desc: Use image node_id 4 for calling a global function with example usage: concat_wavs(data_folder, save_json) and returns: data_json