class_docstr: Online Segmentor for online (streaming) diarizer.
  - The class instances created by this class takes time-series signal from the audio buffer and
    creates subsegments for embedding extraction.
  - Since online segmentation is based on a short audio buffer, the methods in this class extracts
    a few subsegments from the given intervals for the raw time-series signal.
  
  Attributes:
      frame_start (float):
          Start of the middle chunk
      buffer_start (float):
          Start of the entire buffer
      buffer_end (float):
          End of the entire buffer
      sample_rate (int):
          Sampling rate of the input time-series signal
      cumulative_speech_labels (Tensor):
          Torch tensor matrix containing culmulative VAD (speech activity) timestamps
class_docstr_tok: ["Online","Segmentor","for","online","(","streaming",")","diarizer",".","-","The","class","instances","created","by","this","class","takes","time-series","signal","from","the","audio","buffer","and","creates","subsegments","for","embedding","extraction",".","-","Since","online","segmentation","is","based","on","a","short","audio","buffer",",","the","methods","in","this","class","extracts","a","few","subsegments","from","the","given","intervals","for","the","raw","time-series","signal",".","Attributes",":","frame_start","(","float",")",":","Start","of","the","middle","chunk","buffer_start","(","float",")",":","Start","of","the","entire","buffer","buffer_end","(","float",")",":","End","of","the","entire","buffer","sample_rate","(","int",")",":","Sampling","rate","of","the","input","time-series","signal","cumulative_speech_labels","(","Tensor",")",":","Torch","tensor","matrix","containing","culmulative","VAD","(","speech","activity",")","timestamps"]
docstr: Remove the old segments that overlap with the new frame (self.frame_start)
  cursor_for_old_segments is pointing at the onset of the t_range popped most recently.
  
  Frame is in the middle of the buffer.
  
  |___Buffer___[___________]____________|
  |____________[   Frame   ]____________|
  
  | <- buffer start
  |____________| <- frame start
  
  
  Args:
      audio_buffer (Tensor):
          Tensor containing raw time-series signal
      vad_timestamps (Tensor):
          Tensor containing VAD intervals (start and end timestamps)
      segment_raw_audio (list):
          List containing the previously added tensors of the raw time-series signal segments
      segment_range_ts (list):
          List containing the previously added intervals (start and end timestamps) of each segment
      segment_indexes (list):
          List containing the previously added global integer indicies of the segments from
          start to current cursor
      window (float):
          Window length in second
      shift (float):
          Shift length in second
  
  Returns:
      segment_raw_audio (list):
          List containing the newly added tensors of the raw time-series signal
      segment_range_ts (list):
          List containing the newly added interval (start and end timestamps) of each segment
      segment_indexes (list):
          List containing the newly added global integer indicies of the segments from
          start to current cursor
docstr_tok: ["Remove","the","old","segments","that","overlap","with","the","new","frame","(","self.frame_start",")","cursor_for_old_segments","is","pointing","at","the","onset","of","the","t_range","popped","most","recently",".","Frame","is","in","the","middle","of","the","buffer",".","|___Buffer___","[","___________","]","____________|","|____________","[","Frame","]","____________|","|","<","-","buffer","start","|____________|","<","-","frame","start","Args",":","audio_buffer","(","Tensor",")",":","Tensor","containing","raw","time-series","signal","vad_timestamps","(","Tensor",")",":","Tensor","containing","VAD","intervals","(","start","and","end","timestamps",")","segment_raw_audio","(","list",")",":","List","containing","the","previously","added","tensors","of","the","raw","time-series","signal","segments","segment_range_ts","(","list",")",":","List","containing","the","previously","added","intervals","(","start","and","end","timestamps",")","of","each","segment","segment_indexes","(","list",")",":","List","containing","the","previously","added","global","integer","indicies","of","the","segments","from","start","to","current","cursor","window","(","float",")",":","Window","length","in","second","shift","(","float",")",":","Shift","length","in","second","Returns",":","segment_raw_audio","(","list",")",":","List","containing","the","newly","added","tensors","of","the","raw","time-series","signal","segment_range_ts","(","list",")",":","List","containing","the","newly","added","interval","(","start","and","end","timestamps",")","of","each","segment","segment_indexes","(","list",")",":","List","containing","the","newly","added","global","integer","indicies","of","the","segments","from","start","to","current","cursor"]
code: def run_online_segmentation(
      self,
      audio_buffer: torch.Tensor,
      vad_timestamps: torch.Tensor,
      segment_raw_audio: List[torch.Tensor],
      segment_range_ts: List[List[float]],
      segment_indexes: List[int],
      window: float,
      shift: float,
  ):
      """
      Remove the old segments that overlap with the new frame (self.frame_start)
      cursor_for_old_segments is pointing at the onset of the t_range popped most recently.
  
      Frame is in the middle of the buffer.
  
      |___Buffer___[___________]____________|
      |____________[   Frame   ]____________|
  
      | <- buffer start
      |____________| <- frame start
  
  
      Args:
          audio_buffer (Tensor):
              Tensor containing raw time-series signal
          vad_timestamps (Tensor):
              Tensor containing VAD intervals (start and end timestamps)
          segment_raw_audio (list):
              List containing the previously added tensors of the raw time-series signal segments
          segment_range_ts (list):
              List containing the previously added intervals (start and end timestamps) of each segment
          segment_indexes (list):
              List containing the previously added global integer indicies of the segments from
              start to current cursor
          window (float):
              Window length in second
          shift (float):
              Shift length in second
  
      Returns:
          segment_raw_audio (list):
              List containing the newly added tensors of the raw time-series signal
          segment_range_ts (list):
              List containing the newly added interval (start and end timestamps) of each segment
          segment_indexes (list):
              List containing the newly added global integer indicies of the segments from
              start to current cursor
      """
      if self.buffer_start >= 0:
          # Check if this is the very first step
          if (
              len(segment_raw_audio) == 0
              and vad_timestamps.shape[0] > 0
          ):
              vad_timestamps[0][0] = max(vad_timestamps[0][0], 0.0)
              speech_labels_for_update = vad_timestamps
              self.cumulative_speech_labels = speech_labels_for_update
          else:
              # Calculate a cursor for the update point
              (
                  cursor_for_old_segments,
                  cursor_index,
              ) = get_new_cursor_for_update(
                  self.frame_start, segment_range_ts
              )
  
              segment_range_ts = segment_range_ts[:cursor_index]
              segment_raw_audio = segment_raw_audio[:cursor_index]
              segment_indexes = segment_indexes[:cursor_index]
  
              if (
                  not len(segment_raw_audio)
                  == len(segment_range_ts)
                  == len(segment_indexes)
              ):
                  raise ValueError(
                      "Scale-wise segment information has a mismatch in length."
                  )
  
              (
                  speech_labels_for_update,
                  self.cumulative_speech_labels,
              ) = get_speech_labels_for_update(
                  self.frame_start,
                  self.buffer_end,
                  self.cumulative_speech_labels,
                  vad_timestamps,
                  cursor_for_old_segments,
              )
  
          # Collect the timeseries signal from the buffer
          (
              sigs_list,
              sig_rangel_list,
              sig_indexes,
          ) = get_online_subsegments_from_buffer(
              buffer_start=self.buffer_start,
              buffer_end=self.buffer_end,
              sample_rate=self.sample_rate,
              speech_labels_for_update=speech_labels_for_update,
              audio_buffer=audio_buffer,
              segment_indexes=segment_indexes,
              window=window,
              shift=shift,
          )
  
          segment_raw_audio.extend(sigs_list)
          segment_range_ts.extend(sig_rangel_list)
          segment_indexes.extend(sig_indexes)
  
      if (
          not len(segment_raw_audio)
          == len(segment_range_ts)
          == len(segment_indexes)
      ):
          raise ValueError(
              "Segment information has a mismatch in length."
          )
      return segment_raw_audio, segment_range_ts, segment_indexes
  
imports: import gc
  import json
  import math
  import os
  import shutil
  from copy import deepcopy
  from typing import Dict, List, Tuple, Union
  import numpy
  import omegaconf
  import soundfile
  import torch
  from pyannote.core import Annotation, Segment
  from tqdm import tqdm
  from nemo.collections.asr.data.audio_to_label import repeat_signal
  from nemo.collections.asr.parts.utils.longform_clustering import LongFormSpeakerClustering
  from nemo.collections.asr.parts.utils.offline_clustering import SpeakerClustering, get_argmin_mat, split_input_data
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling the OnlineSegmentor obj's underlying member method code with example usage: obj.run_online_segmentation(audio_buffer, vad_timestamps, segment_raw_audio, segment_range_ts, segment_indexes, window, shift) and returns: segment_raw_audio,  segment_range_ts,  segment_indexes