code: def split_sentences(sentence, n=250):
      """
      Splits a sentence by spaces into smaller sentences, each with a maximum length of n characters,
      while preserving whitespace characters like new lines.
      # 250 due to [!] Warning: The text length exceeds the character limit of 250 for language 'en', this might cause truncated audio.
      """
      # Splitting on spaces while preserving all whitespace characters in a list
      words = re.split("(\s+)", sentence)
      sentences = []
      current_sentence = []
      current_length = 0
  
      for word in words:
          # Skip empty strings which can occur due to consecutive whitespace
          if word == "":
              continue
  
          # Check if the word is a whitespace character
          if word.isspace():
              if word == "\n":
                  # If it's a newline, end the current sentence and start a new one
                  sentences.append("".join(current_sentence))
                  current_sentence = []
                  current_length = 0
              else:
                  # For other whitespace characters, add them to the current sentence
                  current_sentence.append(word)
                  current_length += len(word)
          else:
              # Check if adding the next word would exceed the limit
              if current_length + len(word) > n:
                  if current_sentence:
                      sentences.append("".join(current_sentence))
                      current_sentence = [word]
                      current_length = len(word)
                  else:
                      # If the word itself is longer than n and there's no current sentence
                      sentences.append(word)
                      current_length = 0
              else:
                  current_sentence.append(word)
                  current_length += len(word)
  
      # Add the last sentence if it exists
      if current_sentence:
          sentences.append("".join(current_sentence))
  
      return sentences
  
file_path: h2ogpt/src/tts_sentence_parsing.py
imports: import textwrap
  import re
  from src.utils import flatten_list, have_emoji, have_langid
label_desc: Use image node_id 5 for calling a global function with example usage: split_sentences(sentence, n) and returns: sentences