code: def text2phone(text, language):
      """
      Convert graphemes to phonemes.
      """
      seperator = phonemizer.separator.Separator(" |", "", "|")
      # try:
      punctuations = re.findall(PHONEME_PUNCTUATION_PATTERN, text)
      if version.parse(phonemizer.__version__) < version.parse("2.1"):
          ph = phonemize(
              text,
              separator=seperator,
              strip=False,
              njobs=1,
              backend="espeak",
              language=language,
          )
          ph = ph[:-1].strip()  # skip the last empty character
          # phonemizer does not tackle punctuations. Here we do.
          # Replace \n with matching punctuations.
          if punctuations:
              # if text ends with a punctuation.
              if text[-1] == punctuations[-1]:
                  for punct in punctuations[:-1]:
                      ph = ph.replace("| |\n", "|" + punct + "| |", 1)
                      ph = ph + punctuations[-1]
              else:
                  for punct in punctuations:
                      ph = ph.replace("| |\n", "|" + punct + "| |", 1)
      elif version.parse(phonemizer.__version__) >= version.parse(
          "2.1"
      ):
          ph = phonemize(
              text,
              separator=seperator,
              strip=False,
              njobs=1,
              backend="espeak",
              language=language,
              preserve_punctuation=True,
              language_switch="remove-flags",
          )
          # this is a simple fix for phonemizer.
          # https://github.com/bootphon/phonemizer/issues/32
          if punctuations:
              for punctuation in punctuations:
                  ph = ph.replace(
                      f"| |{punctuation} ", f"|{punctuation}| |"
                  ).replace(f"| |{punctuation}", f"|{punctuation}| |")
              ph = ph[:-3]
      else:
          raise RuntimeError(
              " [!] Use 'phonemizer' version 2.1 or older."
          )
  
      return ph
  
file_path: TTS/TTS/tts/utils/text/__init__.py
imports: import re
  from packaging import version
  import phonemizer
  from phonemizer.phonemize import phonemize
  from TTS.tts.utils.text import cleaners
  from TTS.tts.utils.text.symbols import make_symbols, symbols, phonemes, _phoneme_punctuations, _bos, _eos
label_desc: Use image node_id 1 for calling a global function with example usage: text2phone(text, language) and returns: ph