code: def resegment_utt_obj(utt_obj, ass_file_config):
      # get list of just all words and tokens
      all_words_and_tokens = []
      for segment_or_token in utt_obj.segments_and_tokens:
          if type(segment_or_token) is Segment:
              all_words_and_tokens.extend(
                  segment_or_token.words_and_tokens
              )
          else:
              all_words_and_tokens.append(segment_or_token)
  
      # figure out how many chars will fit into one 'slide' and thus should be the max
      # size of a segment
      approx_chars_per_line = (PLAYERRESX - MARGINL - MARGINR) / (
          ass_file_config.fontsize * 0.6
      )  # assume chars 0.6 as wide as they are tall
      approx_lines_per_segment = (PLAYERRESY - MARGINV) / (
          ass_file_config.fontsize * 1.15
      )  # assume line spacing is 1.15
      if (
          approx_lines_per_segment
          > ass_file_config.max_lines_per_segment
      ):
          approx_lines_per_segment = (
              ass_file_config.max_lines_per_segment
          )
  
      max_chars_per_segment = int(
          approx_chars_per_line * approx_lines_per_segment
      )
  
      new_segments_and_tokens = []
      all_words_and_tokens_pointer = 0
      for word_or_token in all_words_and_tokens:
          if type(word_or_token) is Token:
              new_segments_and_tokens.append(word_or_token)
              all_words_and_tokens_pointer += 1
          else:
              break
  
      new_segments_and_tokens.append(Segment())
  
      while all_words_and_tokens_pointer < len(all_words_and_tokens):
          word_or_token = all_words_and_tokens[
              all_words_and_tokens_pointer
          ]
          if type(word_or_token) is Word:
              # if this is going to be the first word in the segment, we definitely want
              # to add it to the segment
              if not new_segments_and_tokens[-1].words_and_tokens:
                  new_segments_and_tokens[-1].words_and_tokens.append(
                      word_or_token
                  )
  
              else:
                  # if not the first word, check what the new length of the segment will be
                  # if short enough - add this word to this segment;
                  # if too long - add to a new segment
                  this_word_n_chars = _get_word_n_chars(word_or_token)
                  segment_so_far_n_chars = _get_segment_n_chars(
                      new_segments_and_tokens[-1]
                  )
                  if (
                      this_word_n_chars + segment_so_far_n_chars
                      < max_chars_per_segment
                  ):
                      new_segments_and_tokens[
                          -1
                      ].words_and_tokens.append(word_or_token)
                  else:
                      new_segments_and_tokens.append(Segment())
                      new_segments_and_tokens[
                          -1
                      ].words_and_tokens.append(word_or_token)
  
          else:  # i.e. word_or_token is a token
              # currently this breaks the convention of tokens at the end/beginning
              # of segments being listed as separate tokens in segment.word_and_tokens
              # TODO: change code so we follow this convention
              new_segments_and_tokens[-1].words_and_tokens.append(
                  word_or_token
              )
  
          all_words_and_tokens_pointer += 1
  
      utt_obj.segments_and_tokens = new_segments_and_tokens
  
      return utt_obj
  
file_path: NeMo/tools/nemo_forced_aligner/utils/make_ass_files.py
imports: import math
  import os
  import soundfile
  from utils.constants import BLANK_TOKEN, SPACE_TOKEN
  from utils.data_prep import Segment, Token, Word
label_desc: Use image node_id 6 for calling a global function with example usage: resegment_utt_obj(utt_obj, ass_file_config) and returns: utt_obj