code: def quantize_f0(speaker_to_f0, f0_stats, nbins, normalize, log):
      f0_all = []
      for speaker, f0 in speaker_to_f0.items():
          f0 = f0.raw_data
          if log:
              f0 = f0.log()
          mean = (
              f0_stats[speaker]["logf0_mean"]
              if log
              else f0_stats[speaker]["f0_mean"]
          )
          std = (
              f0_stats[speaker]["logf0_std"]
              if log
              else f0_stats[speaker]["f0_std"]
          )
          if normalize == "mean":
              f0 = f0 - mean
          elif normalize == "meanstd":
              f0 = (f0 - mean) / std
          f0_all.extend(f0.tolist())
  
      hist, bin_x = np.histogram(f0_all, 100000)
      cum_hist = np.cumsum(hist) / len(f0_all) * 100
  
      f0_bin = {}
      for num_bin in nbins:
          bin_offset = []
          bin_size = 100 / num_bin
          threshold = bin_size
          for i in range(num_bin - 1):
              index = (np.abs(cum_hist - threshold)).argmin()
              bin_offset.append(bin_x[index])
              threshold += bin_size
          f0_bin[num_bin] = np.array(bin_offset)
  
      return f0_bin
  
file_path: fairseq/examples/textless_nlp/pgslm/quantize_f0.py
imports: from collections import defaultdict
  from functools import partial
  import numpy
  import torch
  from tqdm import tqdm
  from data_utils import dump_speaker_f0_stat, F0Stat, load_audio_path, load_f0
label_desc: Use image node_id 2 for calling a global function with example usage: quantize_f0(speaker_to_f0, f0_stats, nbins, normalize, log) and returns: f0_bin