code: def disambiguate_dataset(
      aligner,
      manifest_path,
      out_path,
      sr,
      heteronyms,
      confidence,
      device,
      verbose,
      heteronyms_only=True,
  ):
      """Disambiguates the phonemes for all words with ambiguous pronunciations in the given manifest."""
      log_file = (
          open("disambiguation_logs.txt", "w") if verbose else None
      )
  
      with open(out_path, "w") as f_out:
          with open(manifest_path, "r") as f_in:
              count = 0
  
              for line in f_in:
                  # Retrieve entry and base G2P conversion for full text
                  entry = json.loads(line)
                  # Set punct_post_process=True in order to preserve words with apostrophes
                  text = aligner.normalizer.normalize(
                      entry["text"], punct_post_process=True
                  )
                  text = aligner.tokenizer.text_preprocessing_func(text)
  
                  # Load and preprocess audio
                  audio_path = entry["audio_filepath"]
                  spec, spec_len = load_and_prepare_audio(
                      aligner, audio_path, sr, device
                  )
  
                  # Get pronunciation candidates and disambiguate
                  (
                      disambiguated_text,
                      has_heteronym,
                  ) = disambiguate_candidates(
                      aligner,
                      text,
                      spec,
                      spec_len,
                      confidence,
                      device,
                      heteronyms,
                      log_file,
                  )
  
                  # Skip writing entry if user only wants samples with heteronyms
                  if heteronyms_only and not has_heteronym:
                      continue
  
                  # Save entry with disambiguation
                  entry["disambiguated_text"] = "".join(
                      disambiguated_text
                  )
                  f_out.write(f"{json.dumps(entry)}\n")
  
                  count += 1
                  if count % 100 == 0:
                      print(f"Finished {count} entries.")
  
      print(f"Finished all entries, with a total of {count}.")
      if log_file:
          log_file.close()
  
file_path: NeMo/examples/tts/aligner_heteronym_disambiguation.py
imports: import argparse
  import json
  import os
  import re
  import librosa
  import soundfile
  import torch
  from nemo.collections.tts.models import AlignerModel
  from nemo.collections.tts.parts.utils.tts_dataset_utils import general_padding
label_desc: Use image node_id 4 for calling a global function with example usage: disambiguate_dataset(aligner, manifest_path, out_path, sr, heteronyms, confidence, device, verbose, heteronyms_only) without return types