code: def load_textgrid(fn: Path):
      """load textgrid file"""
      import textgrid
  
      tg = textgrid.TextGrid.fromFile(str(fn.resolve()))
      data = []
      words = list(tg[0])
      widx = 0
      assert (
          tg[1][0].minTime == 0
      ), "The first phoneme has to start at time 0"
      for p in tg[1]:
          if not p in words[widx]:
              widx = widx + 1
              if len(words[widx - 1].mark) > 0:
                  data.append(
                      (
                          FLAGS.special_phonemes[FLAGS.word_end_index],
                          0.0,
                      )
                  )
              if widx >= len(words):
                  break
              assert p in words[widx], "mismatched word vs phoneme"
          mark = p.mark.strip().lower()
          if len(mark) == 0:
              mark = "sil"
          data.append((mark, p.duration()))
      return data
  
file_path: underthesea/underthesea/pipeline/say/viettts_/nat/data_loader.py
imports: import random
  from pathlib import Path
  import numpy
  from scipy.io import wavfile
  from .config import FLAGS, AcousticInput, DurationInput
label_desc: Use image node_id 4 for calling a global function with example usage: load_textgrid(fn) and returns: data