code: def load_midi(root_path):
      """
      Loads MIDI files from subdirectories in the given root path and extracts tempo
      information.
      """
      midis = {}
  
      for subdir in os.listdir(root_path):
          if subdir == "segments" or "-unseg" in subdir:
              continue
  
          full_subdir_path = os.path.join(root_path, subdir)
          if os.path.isdir(full_subdir_path):
              midi_files = glob.glob(
                  os.path.join(full_subdir_path, "*.mid")
              )
              if not midi_files:
                  print(f"No MIDI files found in {full_subdir_path}")
                  continue
  
              midi_file = midi_files[0]
              try:
                  midi_obj = miditoolkit.midi.parser.MidiFile(midi_file)
                  tempos = midi_obj.tempo_changes
                  tempos.sort(key=lambda x: (x.time, x.tempo))
  
                  if tempos:
                      tempo = int(tempos[0].tempo + 0.5)
                      midis[subdir] = tempo
                  else:
                      print(
                          f"No tempo information found in {midi_file}"
                      )
              except Exception as e:
                  print(f"Error processing {midi_file}: {e}")
  
      return midis
  
imports: import argparse
  import glob
  import logging
  import os
  import re
  import shutil
  import subprocess
  import wave
  from typing import List, TextIO, Tuple
  import miditoolkit
  import numpy
  from local.pinyin_dict import PINYIN_DICT
  from tqdm import tqdm
  from espnet2.fileio.score_scp import SingingScoreWriter
label_desc: Use image node_id 3 for calling a global function with example usage: load_midi(root_path) and returns: midis