class_docstr: Class for sampling speech samples for Multispeaker Audio Session Simulator 
  
  Args:
      cfg: OmegaConf configuration loaded from yaml file.
  
  Variables for sampling speech:
      self.running_speech_len_samples (int): Running total of speech samples in the current audio session.
      self.running_silence_len_samples (int): Running total of silence samples in the current audio session.
      self.running_overlap_len_samples (int): Running total of overlap samples in the current audio session.
  
      self.sess_silence_mean (int) : Targeted mean number of silence samples in the current audio session.
      self.per_silence_min_len (int): Minimum number of silence samples in the silence segment.
      self.per_silence_max_len (int): Maximum number of silence samples in the silence segment.
  
      self.sess_overlap_mean (int): Targeted mean number of overlap samples in the current audio session.
      self.per_overlap_min_len (int): Minimum number of overlap samples in the overlap segment.
      self.per_overlap_max_len (int): Maximum number of overlap samples in the overlap segment.
  
  data_simulator: 
      session_params: 
          mean_silence (float): Mean proportion of silence to speaking time in the audio session. Should be in range [0, 1).
          mean_silence_var (float): Variance for mean silence in all audio sessions. 
                                  This value should be 0 <= mean_silence_var < mean_silence * (1 - mean_silence).
          per_silence_var (float):  Variance for each silence in an audio session, set large values (e.g., 20) for de-correlation.
          per_silence_min (float): Minimum duration for each silence, default to 0.
          per_silence_max (float): Maximum duration for each silence, default to -1 for no maximum.
          
          mean_overlap (float): Mean proportion of overlap in the overall non-silence duration. Should be in range [0, 1) and 
                              recommend [0, 0.15] range for accurate results.
          mean_overlap_var (float): Variance for mean overlap in all audio sessions. 
                                  This value should be 0 <= mean_overlap_var < mean_overlap * (1 - mean_overlap).
          per_overlap_var (float): Variance for per overlap in each session, set large values to de-correlate silence lengths 
                                  with the latest speech segment lengths
          per_overlap_min (float): Minimum per overlap duration in seconds
          per_overlap_max (float): Maximum per overlap duration in seconds, set -1 for no maximum 
class_docstr_tok: ["Class","for","sampling","speech","samples","for","Multispeaker","Audio","Session","Simulator","Args",":","cfg",":","OmegaConf","configuration","loaded","from","yaml","file",".","Variables","for","sampling","speech",":","self.running_speech_len_samples","(","int",")",":","Running","total","of","speech","samples","in","the","current","audio","session",".","self.running_silence_len_samples","(","int",")",":","Running","total","of","silence","samples","in","the","current","audio","session",".","self.running_overlap_len_samples","(","int",")",":","Running","total","of","overlap","samples","in","the","current","audio","session",".","self.sess_silence_mean","(","int",")",":","Targeted","mean","number","of","silence","samples","in","the","current","audio","session",".","self.per_silence_min_len","(","int",")",":","Minimum","number","of","silence","samples","in","the","silence","segment",".","self.per_silence_max_len","(","int",")",":","Maximum","number","of","silence","samples","in","the","silence","segment",".","self.sess_overlap_mean","(","int",")",":","Targeted","mean","number","of","overlap","samples","in","the","current","audio","session",".","self.per_overlap_min_len","(","int",")",":","Minimum","number","of","overlap","samples","in","the","overlap","segment",".","self.per_overlap_max_len","(","int",")",":","Maximum","number","of","overlap","samples","in","the","overlap","segment",".","data_simulator",":","session_params",":","mean_silence","(","float",")",":","Mean","proportion","of","silence","to","speaking","time","in","the","audio","session",".","Should","be","in","range","[","0",",","1",")",".","mean_silence_var","(","float",")",":","Variance","for","mean","silence","in","all","audio","sessions",".","This","value","should","be","0","<","=","mean_silence_var","<","mean_silence","*","(","1","-","mean_silence",")",".","per_silence_var","(","float",")",":","Variance","for","each","silence","in","an","audio","session",",","set","large","values","(","e.g.",",","20",")","for","de-correlation",".","per_silence_min","(","float",")",":","Minimum","duration","for","each","silence",",","default","to","0.","per_silence_max","(","float",")",":","Maximum","duration","for","each","silence",",","default","to","-1","for","no","maximum",".","mean_overlap","(","float",")",":","Mean","proportion","of","overlap","in","the","overall","non-silence","duration",".","Should","be","in","range","[","0",",","1",")","and","recommend","[","0",",","0.15","]","range","for","accurate","results",".","mean_overlap_var","(","float",")",":","Variance","for","mean","overlap","in","all","audio","sessions",".","This","value","should","be","0","<","=","mean_overlap_var","<","mean_overlap","*","(","1","-","mean_overlap",")",".","per_overlap_var","(","float",")",":","Variance","for","per","overlap","in","each","session",",","set","large","values","to","de-correlate","silence","lengths","with","the","latest","speech","segment","lengths","per_overlap_min","(","float",")",":","Minimum","per","overlap","duration","in","seconds","per_overlap_max","(","float",")",":","Maximum","per","overlap","duration","in","seconds",",","set","-1","for","no","maximum"]
docstr: Sample from the overlap model to determine the amount of overlap between segments.
  Gamma distribution is employed for modeling  the highly skewed distribution of overlap length distribution.
  When we add an overlap occurrence, we want to meet the desired overlap ratio defined by `self.sess_overlap_mean`.
  Thus, [Session Overlap Mean] = [Total Running Overlap Speech Time] / [Total Running Non-Silence Speech Time].
  Let `overlap_mean` be the desired overlap amount, then the mean and variance of the gamma distribution is given by:
  
      self.sess_overlap_mean = (overlap_mean + self.running_overlap_len_samples) / (non_silence_len_samples - overlap_mean)
  
  The above equation is setting `overlap_mean` to yield the desired overlap ratio `self.sess_overlap_mean`. 
  We use the above `overlap_mean` value to sample overlap-length for each overlap occurrence.
  
  Args:
      non_silence_len_samples (int): 
          The total amount of non-silence (speech) region regardless of overlap status
  
  Returns:
      desired_overlap_amount (int): 
          Amount of overlap between segments (in terms of number of samples).
docstr_tok: ["Sample","from","the","overlap","model","to","determine","the","amount","of","overlap","between","segments",".","Gamma","distribution","is","employed","for","modeling","the","highly","skewed","distribution","of","overlap","length","distribution",".","When","we","add","an","overlap","occurrence",",","we","want","to","meet","the","desired","overlap","ratio","defined","by","`","self.sess_overlap_mean","`",".","Thus",",","[","Session","Overlap","Mean","]","=","[","Total","Running","Overlap","Speech","Time","]","\/","[","Total","Running","Non-Silence","Speech","Time","]",".","Let","`","overlap_mean","`","be","the","desired","overlap","amount",",","then","the","mean","and","variance","of","the","gamma","distribution","is","given","by",":","self.sess_overlap_mean","=","(","overlap_mean","+","self.running_overlap_len_samples",")","\/","(","non_silence_len_samples","-","overlap_mean",")","The","above","equation","is","setting","`","overlap_mean","`","to","yield","the","desired","overlap","ratio","`","self.sess_overlap_mean","`",".","We","use","the","above","`","overlap_mean","`","value","to","sample","overlap-length","for","each","overlap","occurrence",".","Args",":","non_silence_len_samples","(","int",")",":","The","total","amount","of","non-silence","(","speech",")","region","regardless","of","overlap","status","Returns",":","desired_overlap_amount","(","int",")",":","Amount","of","overlap","between","segments","(","in","terms","of","number","of","samples",")","."]
code: def sample_from_overlap_model(self, non_silence_len_samples: int):
      """
      Sample from the overlap model to determine the amount of overlap between segments.
      Gamma distribution is employed for modeling  the highly skewed distribution of overlap length distribution.
      When we add an overlap occurrence, we want to meet the desired overlap ratio defined by `self.sess_overlap_mean`.
      Thus, [Session Overlap Mean] = [Total Running Overlap Speech Time] / [Total Running Non-Silence Speech Time].
      Let `overlap_mean` be the desired overlap amount, then the mean and variance of the gamma distribution is given by:
  
          self.sess_overlap_mean = (overlap_mean + self.running_overlap_len_samples) / (non_silence_len_samples - overlap_mean)
  
      The above equation is setting `overlap_mean` to yield the desired overlap ratio `self.sess_overlap_mean`.
      We use the above `overlap_mean` value to sample overlap-length for each overlap occurrence.
  
      Args:
          non_silence_len_samples (int):
              The total amount of non-silence (speech) region regardless of overlap status
  
      Returns:
          desired_overlap_amount (int):
              Amount of overlap between segments (in terms of number of samples).
      """
      overlap_mean = (
          (self.sess_overlap_mean * non_silence_len_samples)
          - self.running_overlap_len_samples
      ) / (1 + self.sess_overlap_mean)
      overlap_mean = max(
          self.per_overlap_min_len,
          min(max(0, overlap_mean), self.per_overlap_max_len),
      )
  
      if overlap_mean > 0:
          desired_overlap_amount = (
              int(
                  gamma(
                      a=overlap_mean**2 / self.per_overlap_var,
                      scale=self.per_overlap_var / overlap_mean,
                  ).rvs()
              )
              if self.per_overlap_var > 0
              else int(overlap_mean)
          )
          desired_overlap_amount = max(
              self.per_overlap_min_len,
              min(desired_overlap_amount, self.per_overlap_max_len),
          )
      else:
          desired_overlap_amount = 0
      return desired_overlap_amount
  
imports: import copy
  import os
  import shutil
  from collections import defaultdict
  from typing import IO, Dict, List, Optional, Tuple
  import numpy
  import torch
  from scipy.stats import beta, gamma
  from tqdm import tqdm
  from nemo.collections.asr.parts.preprocessing.perturb import AudioAugmentor
  from nemo.collections.asr.parts.preprocessing.segment import AudioSegment
  from nemo.collections.asr.parts.utils.manifest_utils import get_ctm_line, read_manifest, write_ctm, write_manifest, write_text
  from nemo.collections.asr.parts.utils.speaker_utils import labels_to_rttmfile
  from nemo.utils import logging
label_desc: Use image node_id 9 for calling the SpeechSampler obj's underlying member method code with example usage: obj.sample_from_overlap_model(non_silence_len_samples) and returns: desired_overlap_amount