code: def TraverseData(
      sound_dir,
      annotation_dir,
      target_dir,
      mode,
      speaker_info,
      new_data_dir,
      speaker_details,
      text_format,
  ):
      if not os.path.exists(target_dir):
          os.makedirs(target_dir)
  
      segments = open(
          os.path.join(target_dir, "segments"), "w", encoding="utf-8"
      )
      wavscp = open(
          os.path.join(target_dir, "wav.scp"), "w", encoding="utf-8"
      )
      utt2spk = open(
          os.path.join(target_dir, "utt2spk"), "w", encoding="utf-8"
      )
      spk2utt = open(
          os.path.join(target_dir, "spk2utt"), "w", encoding="utf-8"
      )
      text = open(
          os.path.join(target_dir, "text"), "w", encoding="utf-8"
      )
      name2spk = open(
          os.path.join(target_dir, "name2spk"), "w", encoding="utf-8"
      )
      remix_script = open(
          os.path.join(target_dir, "remix_script.sh"),
          "w",
          encoding="utf-8",
      )
  
      # get relationship
      sound_files = {}
      annotation_files = {}
      spk_id = 1
      spk2utt_prep = {}
      name2spk_prep = {}
  
      if mode == "trs":
          if not os.path.exists(os.path.join(target_dir, "temp")):
              os.mkdir(os.path.join(target_dir, "temp"))
          audio_set = set()
          for root, dirs, files in os.walk(sound_dir):
              for file in files:
                  if file[-4:] == ".wav":
                      sound_files[ExtractAudioID(file)] = os.path.join(
                          root, file
                      )
          for root, dirs, files in os.walk(annotation_dir):
              for file in files:
                  if file[-4:] == ".trs":
                      XMLRefine(
                          os.path.join(root, file),
                          os.path.join(target_dir, "temp", file),
                      )
                      annotation_files[file] = os.path.join(
                          target_dir, "temp", file
                      )
          for afile in annotation_files.keys():
              if afile == "error":
                  continue
              try:
                  audio_name, speakers, segment_info = XMLProcessing(
                      annotation_files[afile]
                  )
              except Exception:
                  print("error process %s" % annotation_files[afile])
              audio_name = audio_name.replace(" ", "")
              audio_name = ExtractAudioID(audio_name)
              if audio_name in audio_set:
                  continue
              audio_set.add(audio_name)
              if "%s.wav" % audio_name not in sound_files.keys():
                  print("no audio found for annotation: %s" % afile)
                  continue
                  # write wav.scp & segments & text files
              print(
                  "%s sox -t wavpcm %s -c 1 -r 16000 -t wavpcm - |"
                  % (audio_name, sound_files["%s.wav" % audio_name]),
                  file=wavscp,
              )
              segment_number = 1
              temp_speaker_id = {}
              for speaker in speakers.keys():
                  name2spk_prep[
                      speakers[speaker]["name"]
                  ] = name2spk_prep.get(
                      speakers[speaker]["name"], spk_id
                  )
                  temp_speaker_id[speaker] = name2spk_prep[
                      speakers[speaker]["name"]
                  ]
                  if name2spk_prep[speakers[speaker]["name"]] == spk_id:
                      print(
                          "%s %s"
                          % (
                              speakers[speaker]["name"],
                              PackZero(spk_id),
                          ),
                          file=name2spk,
                      )
                      spk_id += 1
              for segment in segment_info:
                  # segment: [spk, text, start_time, end_time]
                  if segment[0] == "None":
                      spk = spk_id
                      spk_id += 1
                  else:
                      spk = temp_speaker_id[segment[0]]
                  segment_id = "%s_%s_%s" % (
                      PackZero(spk),
                      audio_name,
                      PackZero(segment_number),
                  )
  
                  # skip data error
                  skip = False
                  for seg in segment:
                      if len(seg) < 1:
                          print(
                              "warning segment %s in %s"
                              % (segment_id, audio_name)
                          )
                          skip = True
                  if skip:
                      continue
  
                  print(
                      "%s %s %s %s"
                      % (
                          segment_id,
                          audio_name,
                          segment[2],
                          segment[3],
                      ),
                      file=segments,
                  )
                  print(
                      "%s %s" % (segment_id, PackZero(spk)),
                      file=utt2spk,
                  )
                  print("%s %s" % (segment_id, segment[1]), file=text)
  
                  spk2utt_prep[spk] = spk2utt_prep.get(
                      spk, ""
                  ) + " %s" % (segment_id)
                  segment_number += 1
              for spk in spk2utt_prep.keys():
                  print(
                      "%s %s" % (spk, spk2utt_prep[spk]), file=spk2utt
                  )
              print("successfully processing %s" % afile)
          shutil.rmtree(os.path.join(target_dir, "temp"))
      else:
          wav_spk_info = LoadWavSpeakerInfo(speaker_info)
          spk_details = LoadSpeakerDetails(speaker_details)
          for root, dirs, files in os.walk(sound_dir):
              for file in files:
                  if file[-4:] == ".wav":
                      sound_files[
                          ExtractAudioID(file, wav_spk_info)
                      ] = os.path.join(root, file)
          for root, dirs, files in os.walk(annotation_dir):
              for file in files:
                  if file[-4:] == ".eaf":
                      annotation_files[
                          ExtractAudioID(file, wav_spk_info)
                      ] = os.path.join(root, file)
  
          for afile in annotation_files.keys():
              afile_path = annotation_files[afile]
              if afile == "error":
                  continue
              spk_info = wav_spk_info[afile]
              segment_info = ELANProcess(
                  afile_path, spk_info, spk_details, text_format
              )
              if segment_info is None:
                  continue
              (
                  left_channel_segments,
                  right_channel_segments,
              ) = segment_info
  
              print(
                  'sox -t wavpcm "%s" -c 1 -r 16000 -t wavpcm %s-L.wav remix 1'
                  % (
                      sound_files[afile],
                      os.path.join(new_data_dir, afile),
                  ),
                  file=remix_script,
              )
  
              print(
                  "%s-L %s-L.wav"
                  % (afile, os.path.join(new_data_dir, afile)),
                  file=wavscp,
              )
              segment_number = 0
              for segment in left_channel_segments:
                  # segments: start end text
                  segment_id = "%s_%s-L_%s" % (
                      spk_info[0],
                      afile,
                      PackZero(segment_number),
                  )
                  print(
                      "%s %s-L %s %s"
                      % (segment_id, afile, segment[0], segment[1]),
                      file=segments,
                  )
                  print(
                      "%s %s" % (segment_id, spk_info[0]), file=utt2spk
                  )
                  print("%s %s" % (segment_id, segment[2]), file=text)
                  spk2utt_prep[spk_info[0]] = spk2utt_prep.get(
                      spk_info[0], ""
                  ) + " %s" % (segment_id)
                  segment_number += 1
  
              if len(right_channel_segments) > 0:
                  print(
                      'sox -t wavpcm "%s" -c 1 -r 16000 -t wavpcm %s-R.wav remix 2'
                      % (
                          sound_files[afile],
                          os.path.join(new_data_dir, afile),
                      ),
                      file=remix_script,
                  )
                  print(
                      "%s-R %s-R.wav"
                      % (afile, os.path.join(new_data_dir, afile)),
                      file=wavscp,
                  )
                  for segment in right_channel_segments:
                      # segments: start end text
                      segment_id = "%s_%s-R_%s" % (
                          spk_info[1],
                          afile,
                          PackZero(segment_number),
                      )
                      print(
                          "%s %s-R %s %s"
                          % (segment_id, afile, segment[0], segment[1]),
                          file=segments,
                      )
                      print(
                          "%s %s" % (segment_id, spk_info[1]),
                          file=utt2spk,
                      )
                      print(
                          "%s %s" % (segment_id, segment[2]), file=text
                      )
                      spk2utt_prep[spk_info[1]] = spk2utt_prep.get(
                          spk_info[1], ""
                      ) + " %s" % (segment_id)
                      segment_number += 1
              print(
                  "successfully processing %s " % afile
                  + "-- be aware to remix the signal by remix script"
              )
          for spk in spk2utt_prep.keys():
              print("%s %s" % (spk, spk2utt_prep[spk]), file=spk2utt)
      segments.close()
      wavscp.close()
      utt2spk.close()
      spk2utt.close()
      text.close()
  
file_path: espnet/egs2/puebla_nahuatl/asr1/local/data_prep.py
imports: import os
  import re
  import shutil
  import string
  import sys
  from argparse import ArgumentParser
  from xml.dom.minidom import parse
label_desc: Use image node_id 10 for calling a global function with example usage: TraverseData(sound_dir, annotation_dir, target_dir, mode, speaker_info, new_data_dir, speaker_details, text_format) without return types