class_docstr: Audio segment abstraction.
  :param samples: Audio samples [num_samples x num_channels].
  :type samples: ndarray.float32
  :param sample_rate: Audio sample rate.
  :type sample_rate: int
  :raises TypeError: If the sample data type is not float or int.
docstr: Grabs n_segments number of samples from audio_file.
  If offset is not provided, n_segments are selected randomly.
  If offset is provided, it is used to calculate the starting sample.
  
  Note that audio_file can be either the file path, or a file-like object.
  
  :param audio_file: path to a file or a file-like object
  :param target_sr: sample rate for the output samples
  :param n_segments: desired number of samples
  :param trim: if true, trim leading and trailing silence from an audio signal
  :param orig_sr: the original sample rate
  :param channel selector: select a subset of channels. If set to `None`, the original signal will be used.
  :param offset: fixed offset in seconds
  :param dtype: data type to load audio as.
  :return: numpy array of samples
docstr_tok: ["Grabs","n_segments","number","of","samples","from","audio_file",".","If","offset","is","not","provided",",","n_segments","are","selected","randomly",".","If","offset","is","provided",",","it","is","used","to","calculate","the","starting","sample",".","Note","that","audio_file","can","be","either","the","file","path",",","or","a","file-like","object",".",":","param","audio_file",":","path","to","a","file","or","a","file-like","object",":","param","target_sr",":","sample","rate","for","the","output","samples",":","param","n_segments",":","desired","number","of","samples",":","param","trim",":","if","true",",","trim","leading","and","trailing","silence","from","an","audio","signal",":","param","orig_sr",":","the","original","sample","rate",":","param","channel","selector",":","select","a","subset","of","channels",".","If","set","to","`","None","`",",","the","original","signal","will","be","used",".",":","param","offset",":","fixed","offset","in","seconds",":","param","dtype",":","data","type","to","load","audio","as",".",":","return",":","numpy","array","of","samples"]
code: def segment_from_file(
      cls,
      audio_file,
      target_sr=None,
      n_segments=0,
      trim=False,
      orig_sr=None,
      channel_selector=None,
      offset=None,
      dtype="float32",
  ):
      """Grabs n_segments number of samples from audio_file.
      If offset is not provided, n_segments are selected randomly.
      If offset is provided, it is used to calculate the starting sample.
  
      Note that audio_file can be either the file path, or a file-like object.
  
      :param audio_file: path to a file or a file-like object
      :param target_sr: sample rate for the output samples
      :param n_segments: desired number of samples
      :param trim: if true, trim leading and trailing silence from an audio signal
      :param orig_sr: the original sample rate
      :param channel selector: select a subset of channels. If set to `None`, the original signal will be used.
      :param offset: fixed offset in seconds
      :param dtype: data type to load audio as.
      :return: numpy array of samples
      """
      is_segmented = False
      try:
          with sf.SoundFile(audio_file, "r") as f:
              sample_rate = f.samplerate
              if target_sr is not None:
                  n_segments_at_original_sr = math.ceil(
                      n_segments * sample_rate / target_sr
                  )
              else:
                  n_segments_at_original_sr = n_segments
  
              if 0 < n_segments_at_original_sr < len(f):
                  max_audio_start = len(f) - n_segments_at_original_sr
                  if offset is None:
                      audio_start = random.randint(0, max_audio_start)
                  else:
                      audio_start = math.floor(offset * sample_rate)
                      if audio_start > max_audio_start:
                          raise RuntimeError(
                              f"Provided audio start ({audio_start}) is larger than the maximum possible ({max_audio_start})"
                          )
                  f.seek(audio_start)
                  samples = f.read(
                      n_segments_at_original_sr, dtype=dtype
                  )
                  is_segmented = True
              elif n_segments_at_original_sr > len(f):
                  logging.warning(
                      f"Number of segments ({n_segments_at_original_sr}) is greater than the length ({len(f)}) of the audio file {audio_file}. This may lead to shape mismatch errors."
                  )
                  samples = f.read(dtype=dtype)
              else:
                  samples = f.read(dtype=dtype)
      except RuntimeError as e:
          logging.error(
              f"Loading {audio_file} via SoundFile raised RuntimeError: `{e}`."
          )
          raise e
  
      features = cls(
          samples,
          sample_rate,
          target_sr=target_sr,
          trim=trim,
          orig_sr=orig_sr,
          channel_selector=channel_selector,
      )
  
      if is_segmented:
          features._samples = features._samples[:n_segments]
  
      return features
  
imports: import math
  import os
  import random
  from typing import Optional
  import librosa
  import numpy
  import soundfile
  from nemo.collections.asr.parts.utils.audio_utils import select_channels
  from nemo.utils import logging
label_desc: Use image node_id 8 for calling the AudioSegment obj's underlying member method code with example usage: obj.segment_from_file(cls, audio_file, target_sr, n_segments, trim, orig_sr, channel_selector, offset, dtype) and returns: features