code: def read_textgrid_from_file(filepath):
      with codecs.open(filepath, "r", encoding="utf-8") as handle:
          lines = handle.readlines()
      if lines[-1] == "\r\n":
          lines = lines[:-1]
  
      assert "File type" in lines[0], "error line 0, {}".format(
          lines[0]
      )
      file_type = (
          lines[0]
          .split("=")[1]
          .replace(" ", "")
          .replace('"', "")
          .replace("\r", "")
          .replace("\n", "")
      )
  
      assert "Object class" in lines[1], "error line 1, {}".format(
          lines[1]
      )
      object_class = (
          lines[1]
          .split("=")[1]
          .replace(" ", "")
          .replace('"', "")
          .replace("\r", "")
          .replace("\n", "")
      )
  
      assert lines[2] == "\r\n", "error line 2, {}".format(lines[2])
  
      assert "xmin" in lines[3], "error line 3, {}".format(lines[3])
      xmin = float(
          lines[3]
          .split("=")[1]
          .replace(" ", "")
          .replace("\r", "")
          .replace("\n", "")
      )
  
      assert "xmax" in lines[4], "error line 4, {}".format(lines[4])
      xmax = float(
          lines[4]
          .split("=")[1]
          .replace(" ", "")
          .replace("\r", "")
          .replace("\n", "")
      )
  
      assert "tiers?" in lines[5], "error line 5, {}".format(lines[5])
      tiers_status = (
          lines[5]
          .split("?")[1]
          .replace(" ", "")
          .replace("\r", "")
          .replace("\n", "")
      )
  
      assert "size" in lines[6], "error line 6, {}".format(lines[6])
      size = int(
          lines[6]
          .split("=")[1]
          .replace(" ", "")
          .replace("\r", "")
          .replace("\n", "")
      )
  
      assert lines[7] == "item []:\r\n", "error line 7, {}".format(
          lines[7]
      )
  
      tier_start = []
      for item_idx in range(size):
          tier_start.append(
              lines.index(
                  " " * 4 + "item [{}]:\r\n".format(item_idx + 1)
              )
          )
  
      tier_end = tier_start[1:] + [len(lines)]
  
      tiers = []
      for tier_idx in range(size):
          tiers.append(
              read_tier_from_lines(
                  tier_lines=lines[
                      tier_start[tier_idx] + 1 : tier_end[tier_idx]
                  ]
              )
          )
  
      return TextGrid(
          file_type=file_type,
          object_class=object_class,
          xmin=xmin,
          xmax=xmax,
          tiers_status=tiers_status,
          tiers=tiers,
      )
  
imports: import argparse
  import codecs
  import glob
  import os
  import sys
  from multiprocessing import Pool
label_desc: Use image node_id 2 for calling a global function with example usage: read_textgrid_from_file(filepath) and returns: TextGrid