code: def convert_arp_to_ipa(
      arp_to_ipa_dict: Dict[str, str],
      arp_input: str,
      remove_space: bool = False,
  ) -> str:
      """
      Converts ARPABET phoneme to IPA based on arp_to_ipa_dict mapping
  
      Args:
          arp_to_ipa_dict: ARPABET to IPA phonemes mapping
          arp_input: ARPABET input
          remove_space: set to TRUE to remove spaces between IPA phonemes
  
      Returns:
          input word in IPA form
      """
  
      primary_stress = "ˈ"
      secondary_stress = "ˌ"
      stress_dict = {
          "0": "",
          "1": primary_stress,
          "2": secondary_stress,
      }
  
      word_ipa = ""
      phonemes = arp_input.split()
  
      # split ARPABET phoneme input into syllables,
      # e.g. syllabify(["HH", "AH0", "L", "OW1"]) -> [(['HH'], ['AH0'], []), (['L'], ['OW1'], [])]
      syllables = syllabify(phonemes)
  
      for syl_idx, syll in enumerate(syllables):
          syll_stress = ""
          syll_ipa = ""
  
          # syll is a tuple of lists of phonemes, here we flatten it and get rid of empty entries,
          # e.g. (['HH'], ['AH0'], []) -> ['HH', 'AH0']
          syll = [x for x in itertools.chain.from_iterable(syll)]
          for phon_idx, phon in enumerate(syll):
              if phon[-1].isdigit():
                  syll_stress = phon[-1]
                  if syll_stress not in stress_dict:
                      raise ValueError(f"{syll_stress} unknown")
                  syll_stress = stress_dict[syll_stress]
  
              # some phonemes are followed by a digit that represents stress, e.g., `AH0`
              if phon not in arp_to_ipa_dict and phon[-1].isdigit():
                  phon = phon[:-1]
  
              if phon not in arp_to_ipa_dict:
                  raise ValueError(
                      f"|{phon}| phoneme not found in |{arp_input}|"
                  )
              else:
                  ipa_phone = arp_to_ipa_dict[phon]
                  syll_ipa += ipa_phone + " "
  
          word_ipa += " " + syll_stress + syll_ipa.strip()
  
      word_ipa = word_ipa.strip()
      if remove_space:
          word_ipa = word_ipa.replace(" ", "")
      return word_ipa
  
file_path: NeMo/scripts/dataset_processing/g2p/convert_cmu_arpabet_to_ipa.py
imports: import itertools
  import os
  from argparse import ArgumentParser
  from typing import Dict
  from syllabify import syllabify
label_desc: Use image node_id 2 for calling a global function with example usage: convert_arp_to_ipa(arp_to_ipa_dict, arp_input, remove_space) and returns: word_ipa