code: def segment_audio(
      audio,
      total_durations,
      total_pitches,
      midi_mapping,
      midi_notes,
      midis,
      output_temp,
  ):
      start_time = 0  # Initialize the current time marker in the audio
      last_end_time = 0  # Initialize end time marker for last segment
      note_idx = 0
      utterance_idx = 0
      total_durations_keys = list(total_durations.keys())
      while utterance_idx < len(total_durations):
          name = total_durations_keys[utterance_idx]
          duration = total_durations[name]
          if note_idx >= len(midi_notes):
              break
          if note_idx == 0:
              start_time = midi_notes[note_idx][0]
              note_idx += 1
              last_end_time = start_time + duration
              utterance_idx += 1
              previous_note_idx = 0
          else:
              if midi_notes[note_idx][0] - last_end_time < -100:
                  note_idx += 1
                  continue
              pitch_trans = total_pitches[name][0]
              if midis[note_idx] != midi_mapping[pitch_trans]:
                  orginal_note_idx = note_idx
                  target_midi = midi_mapping[pitch_trans]
                  min_distance = float("inf")
                  nearest_note_idx = None
                  # Search backwards within -5 index range
                  for i in range(note_idx, max(note_idx - 5, -1), -1):
                      distance = abs(midis[i] - target_midi)
                      if distance == 0:
                          return i  # Exact match found
                      if distance < min_distance:
                          min_distance = distance
                          nearest_note_idx = i
  
                  # Search within +5 index range and should > previous note index
                  for i in range(
                      note_idx, min(note_idx + 5, len(midis))
                  ):
                      if i <= previous_note_idx:
                          continue
                      distance = abs(midis[i] - target_midi)
                      if distance == 0:
                          return i  # Exact match found
                      if distance < min_distance:
                          min_distance = distance
                          nearest_note_idx = i
                  if nearest_note_idx is not None:
                      note_idx = nearest_note_idx
                  else:
                      note_idx = orginal_note_idx
              previous_note_idx = note_idx
              start_time = midi_notes[note_idx][0]
              note_idx += 1
              last_end_time = start_time + duration
              utterance_idx += 1
          segment = audio[
              start_time:last_end_time
          ]  # Extract the segment
          output_name = output_temp + f"#{name}"
          if os.path.exists(f"{output_name}.wav"):
              print(f"{output_name}.wav already exists. Skipping.")
              continue
          segment.export(
              f"{output_name}.wav", format="wav"
          )  # Export it as a wav file in the output folder
      return None
  
imports: import argparse
  import logging
  import os
  import re
  import shutil
  import librosa
  import miditoolkit
  import numpy
  from tqdm import tqdm
  from espnet2.fileio.score_scp import SingingScoreWriter
label_desc: Use image node_id 6 for calling a global function with example usage: segment_audio(audio, total_durations, total_pitches, midi_mapping, midi_notes, midis, output_temp) and returns: None, i, i