code: def get_alignment(
      tier, sampling_rate, hop_length, last_phoneme_flags
  ):
      """
      Returns phonemes, phoneme durations (in frames), start time (in seconds), end time (in seconds).
      This function is adopted from https://github.com/ming024/FastSpeech2/blob/master/preprocessor/preprocessor.py
  
      Arguments
      ---------
      tier : tgt.core.IntervalTier
          For an utterance, contains Interval objects for phonemes and their start time and end time in seconds
      sampling_rate : int
          Sample rate if audio signal
      hop_length : int
          Hop length for duration computation
      last_phoneme_flags : list
          List of (phoneme, flag) tuples with flag=1 if the phoneme is the last phoneme else flag=0
  
  
      Returns
      -------
      (phones, durations, start_time, end_time) : tuple
          The phonemes, durations, start time, and end time for an utterance
      """
  
      sil_phones = ["sil", "sp", "spn", ""]
  
      phonemes = []
      durations = []
      start_time = 0
      end_time = 0
      end_idx = 0
      trimmed_last_phoneme_flags = []
  
      flag_iter = iter(last_phoneme_flags)
  
      for t in tier._objects:
          s, e, p = t.start_time, t.end_time, t.text
          current_flag = next(flag_iter)
  
          # Trims leading silences
          if phonemes == []:
              if p in sil_phones:
                  continue
              else:
                  start_time = s
  
          if p not in sil_phones:
              # For ordinary phones
              # Removes stress indicators
              if p[-1].isdigit():
                  phonemes.append(p[:-1])
              else:
                  phonemes.append(p)
              trimmed_last_phoneme_flags.append(current_flag[1])
              end_time = e
              end_idx = len(phonemes)
          else:
              # Uses a unique token for all silent phones
              phonemes.append("spn")
              trimmed_last_phoneme_flags.append(current_flag[1])
  
          durations.append(
              int(
                  np.round(e * sampling_rate / hop_length)
                  - np.round(s * sampling_rate / hop_length)
              )
          )
  
      # Trims tailing silences
      phonemes = phonemes[:end_idx]
      durations = durations[:end_idx]
  
      return (
          phonemes,
          durations,
          start_time,
          end_time,
          trimmed_last_phoneme_flags,
      )
  
imports: import os
  import csv
  import json
  import random
  import logging
  import torch
  import torchaudio
  import numpy
  from tqdm import tqdm
  from speechbrain.utils.data_utils import download_file
  from speechbrain.dataio.dataio import load_pkl, save_pkl
  import tgt
  from speechbrain.inference.text import GraphemeToPhoneme
  import re
  from unidecode import unidecode
  from speechbrain.utils.text_to_sequence import _g2p_keep_punctuations
label_desc: Use image node_id 5 for calling a global function with example usage: get_alignment(tier, sampling_rate, hop_length, last_phoneme_flags) and returns: phonemes,  durations,  start_time,  end_time,  trimmed_last_phoneme_flags