code: def labels_to_segments(labels, window):
      """
      ARGUMENTS:
       - labels:     a sequence of class labels (per time window)
       - window:     window duration (in seconds)
  
      RETURNS:
       - segments:   a sequence of segment's limits: segs[i,0] is start and
                     segs[i,1] are start and end point of segment i
       - classes:    a sequence of class flags: class[i] is the class ID of
                     the i-th segment
      """
  
      if len(labels) == 1:
          segs = [0, window]
          classes = labels
          return segs, classes
  
      num_segs = 0
      index = 0
      classes = []
      segment_list = []
      cur_label = labels[index]
      while index < len(labels) - 1:
          previous_value = cur_label
          while True:
              index += 1
              compare_flag = labels[index]
              if (compare_flag != cur_label) | (
                  index == len(labels) - 1
              ):
                  num_segs += 1
                  cur_label = labels[index]
                  segment_list.append((index * window))
                  classes.append(previous_value)
                  break
      segments = np.zeros((len(segment_list), 2))
  
      for i in range(len(segment_list)):
          if i > 0:
              segments[i, 0] = segment_list[i - 1]
          segments[i, 1] = segment_list[i]
      return segments, classes
  
imports: from __future__ import print_function
  import os
  import csv
  import glob
  import scipy
  import sklearn
  import numpy
  import hmmlearn.hmm
  import sklearn.cluster
  import pickle
  import matplotlib.pyplot
  from scipy.spatial import distance
  import sklearn.discriminant_analysis
  from sklearn.preprocessing import StandardScaler
  import sys
  import pyAudioAnalysis.audioBasicIO
  import pyAudioAnalysis.audioTrainTest
  import pyAudioAnalysis.MidTermFeatures
  import pyAudioAnalysis.ShortTermFeatures
label_desc: Use image node_id 3 for calling a global function with example usage: labels_to_segments(labels, window) and returns: segments,  classes, segs,  classes