docstr: Computes segments for each song of the dataset.
  
  Parameters:
      dataset (Any):
          Dataset to compute segments for.
      n_chunks_per_song (int):
          Number of segment per song to compute.
  
  Returns:
      Any:
          Segmented dataset.
docstr_tok: ["Computes","segments","for","each","song","of","the","dataset",".","Parameters",":","dataset","(","Any",")",":","Dataset","to","compute","segments","for",".","n_chunks_per_song","(","int",")",":","Number","of","segment","per","song","to","compute",".","Returns",":","Any",":","Segmented","dataset","."]
code: def compute_segments(
      self, dataset: Any, n_chunks_per_song: int
  ) -> Any:
      """
      Computes segments for each song of the dataset.
  
      Parameters:
          dataset (Any):
              Dataset to compute segments for.
          n_chunks_per_song (int):
              Number of segment per song to compute.
  
      Returns:
          Any:
              Segmented dataset.
      """
      if n_chunks_per_song <= 0:
          raise ValueError("n_chunks_per_song must be positif")
      datasets = []
      for k in range(n_chunks_per_song):
          if n_chunks_per_song > 1:
              datasets.append(
                  dataset.map(
                      lambda sample: dict(
                          sample,
                          start=tf.maximum(
                              k
                              * (
                                  sample["duration"]
                                  - self._chunk_duration
                                  - 2 * self.MARGIN
                              )
                              / (n_chunks_per_song - 1)
                              + self.MARGIN,
                              0,
                          ),
                      )
                  )
              )
          elif n_chunks_per_song == 1:  # Take central segment.
              datasets.append(
                  dataset.map(
                      lambda sample: dict(
                          sample,
                          start=tf.maximum(
                              sample["duration"] / 2
                              - self._chunk_duration / 2,
                              0,
                          ),
                      )
                  )
              )
      dataset = datasets[-1]
      for d in datasets[:-1]:
          dataset = dataset.concatenate(d)
      return dataset
  
imports: import os
  import time
  from os.path import exists
  from os.path import sep
  from typing import Any, Dict, List, Optional, Tuple
  import tensorflow
  from .audio.adapter import AudioAdapter
  from .audio.convertor import db_uint_spectrogram_to_gain, spectrogram_to_db_uint
  from .audio.spectrogram import compute_spectrogram_tf, random_pitch_shift, random_time_stretch
  from .utils.logging import logger
  from .utils.tensor import check_tensor_shape, dataset_from_csv, set_tensor_shape, sync_apply
label_desc: Use image node_id 12 for calling the DatasetBuilder obj's underlying member method code with example usage: obj.compute_segments(dataset, n_chunks_per_song) and returns: dataset