docstr: parse an input IPA dictionary and save it as a dict object.
  
  Args:
      phoneme_dict (Union[str, pathlib.Path, dict]): Path to file in CMUdict format or an IPA dict object with
          CMUdict-like entries. For example,
          a dictionary file: scripts/tts_dataset_files/ipa_cmudict-0.7b_nv22.06.txt;
          a dictionary object: {..., "Wire": [["ˈ", "w", "a", "ɪ", "ɚ"], ["ˈ", "w", "a", "ɪ", "ɹ"]], ...}.
  
  Returns: a dict object (Dict[str, List[List[str]]]).
docstr_tok: ["parse","an","input","IPA","dictionary","and","save","it","as","a","dict","object",".","Args",":","phoneme_dict","(","Union","[","str",",","pathlib.Path",",","dict","]",")",":","Path","to","file","in","CMUdict","format","or","an","IPA","dict","object","with","CMUdict-like","entries",".","For","example",",","a","dictionary","file",":","scripts\/tts_dataset_files\/ipa_cmudict-0.7b_nv22.06.txt",";","a","dictionary","object",":","{","...",",","``","Wire","''",":","[","[","``","\u02c8","''",",","``","w","''",",","``","a","''",",","``","\u026a","''",",","``","\u025a","''","]",",","[","``","\u02c8","''",",","``","w","''",",","``","a","''",",","``","\u026a","''",",","``","\u0279","''","]","]",",","...","}",".","Returns",":","a","dict","object","(","Dict","[","str",",","List","[","List","[","str","]","]","]",")","."]
code: def _parse_phoneme_dict(
      phoneme_dict: Union[str, pathlib.Path, Dict[str, List[List[str]]]]
  ) -> Dict[str, List[List[str]]]:
      """
      parse an input IPA dictionary and save it as a dict object.
  
      Args:
          phoneme_dict (Union[str, pathlib.Path, dict]): Path to file in CMUdict format or an IPA dict object with
              CMUdict-like entries. For example,
              a dictionary file: scripts/tts_dataset_files/ipa_cmudict-0.7b_nv22.06.txt;
              a dictionary object: {..., "Wire": [["ˈ", "w", "a", "ɪ", "ɚ"], ["ˈ", "w", "a", "ɪ", "ɹ"]], ...}.
  
      Returns: a dict object (Dict[str, List[List[str]]]).
      """
      if isinstance(phoneme_dict, str) or isinstance(
          phoneme_dict, pathlib.Path
      ):
          # load the dictionary file where there may exist a digit suffix after a word, e.g. "Word(2)", which
          # represents the pronunciation variant of that word.
          phoneme_dict_obj = defaultdict(list)
          _alt_re = re.compile(r"\([0-9]+\)")
          with open(phoneme_dict, "r", encoding="utf-8") as fdict:
              for line in fdict:
                  # skip the empty lines
                  if len(line) == 0:
                      continue
  
                  # Note that latin character pattern should be consistent with
                  # nemo.collections.tts.g2p.data.data_utils.LATIN_CHARS_ALL. It is advised to extend its character
                  # coverage if adding the support of new languages.
                  # TODO @xueyang: unify hardcoded range of characters with LATIN_CHARS_ALL to avoid duplicates.
                  line = normalize_unicode_text(line)
  
                  if (
                      "A" <= line[0] <= "Z"
                      or "a" <= line[0] <= "z"
                      or "À" <= line[0] <= "Ö"
                      or "Ø" <= line[0] <= "ö"
                      or "ø" <= line[0] <= "ÿ"
                      or line[0] == "'"
                  ):
                      parts = line.strip().split(maxsplit=1)
                      word = re.sub(_alt_re, "", parts[0])
                      prons = re.sub(r"\s+", "", parts[1])
                      phoneme_dict_obj[word].append(list(prons))
      else:
          # Load phoneme_dict as dictionary object
          logging.info(
              "Loading phoneme_dict as a Dict object, and validating its entry format."
          )
  
          phoneme_dict_obj = {}
          for word, prons in phoneme_dict.items():
              # validate dict entry format
              assert isinstance(
                  prons, list
              ), f"Pronunciation type <{type(prons)}> is not supported. Please convert to <list>."
  
              # normalize word with NFC form
              word = normalize_unicode_text(word)
  
              # normalize phonemes with NFC form
              prons = [
                  [normalize_unicode_text(p) for p in pron]
                  for pron in prons
              ]
  
              phoneme_dict_obj.update({word: prons})
  
      return phoneme_dict_obj
  
imports: import pathlib
  import random
  import re
  from collections import defaultdict
  from typing import Callable, Dict, List, Optional, Set, Tuple, Union
  from nemo.collections.common.tokenizers.text_to_speech.ipa_lexicon import validate_locale
  from nemo.collections.common.tokenizers.text_to_speech.tokenizer_utils import LATIN_CHARS_ALL, any_locale_word_tokenize, english_word_tokenize, normalize_unicode_text
  from nemo.collections.tts.g2p.models.base import BaseG2p
  from nemo.collections.tts.g2p.utils import GRAPHEME_CASE_MIXED, GRAPHEME_CASE_UPPER, set_grapheme_case
  from nemo.utils import logging
  from nemo.utils.decorators import experimental
label_desc: Use image node_id 2 for calling the IpaG2p obj's underlying member method code with example usage: obj._parse_phoneme_dict(phoneme_dict) and returns: phoneme_dict_obj