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: Load a file supported by librosa and return as an AudioSegment.
  :param audio_file: path of file to load.
                     Alternatively, a list of paths of single-channel files can be provided
                     to form a multichannel signal.
  :param target_sr: the desired sample rate
  :param int_values: if true, load samples as 32-bit integers
  :param offset: offset in seconds when loading audio
  :param duration: duration in seconds when loading audio
  :param trim: if true, trim leading and trailing silence from an audio signal
  :param trim_ref: the reference amplitude. By default, it uses `np.max` and compares to the peak amplitude in
                   the signal
  :param trim_top_db: the threshold (in decibels) below reference to consider as silence
  :param trim_frame_length: the number of samples per analysis frame
  :param trim_hop_length: the number of samples between analysis frames
  :param orig_sr: the original sample rate
  :param channel selector: string denoting the downmix mode, an integer denoting the channel to be selected, or an iterable
                           of integers denoting a subset of channels. Channel selector is using zero-based indexing.
                           If set to `None`, the original signal will be used.
  :param normalize_db (Optional[float]): if not None, normalize the audio signal to a target RMS value
  :param ref_channel (Optional[int]): channel to use as reference for normalizing multi-channel audio, set None to use max RMS across channels
  :return: AudioSegment instance
docstr_tok: ["Load","a","file","supported","by","librosa","and","return","as","an","AudioSegment",".",":","param","audio_file",":","path","of","file","to","load",".","Alternatively",",","a","list","of","paths","of","single-channel","files","can","be","provided","to","form","a","multichannel","signal",".",":","param","target_sr",":","the","desired","sample","rate",":","param","int_values",":","if","true",",","load","samples","as","32-bit","integers",":","param","offset",":","offset","in","seconds","when","loading","audio",":","param","duration",":","duration","in","seconds","when","loading","audio",":","param","trim",":","if","true",",","trim","leading","and","trailing","silence","from","an","audio","signal",":","param","trim_ref",":","the","reference","amplitude",".","By","default",",","it","uses","`","np.max","`","and","compares","to","the","peak","amplitude","in","the","signal",":","param","trim_top_db",":","the","threshold","(","in","decibels",")","below","reference","to","consider","as","silence",":","param","trim_frame_length",":","the","number","of","samples","per","analysis","frame",":","param","trim_hop_length",":","the","number","of","samples","between","analysis","frames",":","param","orig_sr",":","the","original","sample","rate",":","param","channel","selector",":","string","denoting","the","downmix","mode",",","an","integer","denoting","the","channel","to","be","selected",",","or","an","iterable","of","integers","denoting","a","subset","of","channels",".","Channel","selector","is","using","zero-based","indexing",".","If","set","to","`","None","`",",","the","original","signal","will","be","used",".",":","param","normalize_db","(","Optional","[","float","]",")",":","if","not","None",",","normalize","the","audio","signal","to","a","target","RMS","value",":","param","ref_channel","(","Optional","[","int","]",")",":","channel","to","use","as","reference","for","normalizing","multi-channel","audio",",","set","None","to","use","max","RMS","across","channels",":","return",":","AudioSegment","instance"]
code: def from_file(
      cls,
      audio_file,
      target_sr=None,
      int_values=False,
      offset=0,
      duration=0,
      trim=False,
      trim_ref=np.max,
      trim_top_db=60,
      trim_frame_length=2048,
      trim_hop_length=512,
      orig_sr=None,
      channel_selector=None,
      normalize_db=None,
      ref_channel=None,
  ):
      """
      Load a file supported by librosa and return as an AudioSegment.
      :param audio_file: path of file to load.
                         Alternatively, a list of paths of single-channel files can be provided
                         to form a multichannel signal.
      :param target_sr: the desired sample rate
      :param int_values: if true, load samples as 32-bit integers
      :param offset: offset in seconds when loading audio
      :param duration: duration in seconds when loading audio
      :param trim: if true, trim leading and trailing silence from an audio signal
      :param trim_ref: the reference amplitude. By default, it uses `np.max` and compares to the peak amplitude in
                       the signal
      :param trim_top_db: the threshold (in decibels) below reference to consider as silence
      :param trim_frame_length: the number of samples per analysis frame
      :param trim_hop_length: the number of samples between analysis frames
      :param orig_sr: the original sample rate
      :param channel selector: string denoting the downmix mode, an integer denoting the channel to be selected, or an iterable
                               of integers denoting a subset of channels. Channel selector is using zero-based indexing.
                               If set to `None`, the original signal will be used.
      :param normalize_db (Optional[float]): if not None, normalize the audio signal to a target RMS value
      :param ref_channel (Optional[int]): channel to use as reference for normalizing multi-channel audio, set None to use max RMS across channels
      :return: AudioSegment instance
      """
      samples = None
      if isinstance(audio_file, list):
          return cls.from_file_list(
              audio_file_list=audio_file,
              target_sr=target_sr,
              int_values=int_values,
              offset=offset,
              duration=duration,
              trim=trim,
              trim_ref=trim_ref,
              trim_top_db=trim_top_db,
              trim_frame_length=trim_frame_length,
              trim_hop_length=trim_hop_length,
              orig_sr=orig_sr,
              channel_selector=channel_selector,
              normalize_db=normalize_db,
              ref_channel=ref_channel,
          )
  
      if (
          not isinstance(audio_file, str)
          or os.path.splitext(audio_file)[-1] in sf_supported_formats
      ):
          try:
              with sf.SoundFile(audio_file, "r") as f:
                  dtype = "int32" if int_values else "float32"
                  sample_rate = f.samplerate
                  if offset > 0:
                      f.seek(int(offset * sample_rate))
                  if duration > 0:
                      samples = f.read(
                          int(duration * sample_rate), dtype=dtype
                      )
                  else:
                      samples = f.read(dtype=dtype)
          except RuntimeError as e:
              logging.error(
                  f"Loading {audio_file} via SoundFile raised RuntimeError: `{e}`. "
                  f"NeMo will fallback to loading via pydub."
              )
  
              if hasattr(audio_file, "seek"):
                  audio_file.seek(0)
  
      if HAVE_PYDUB and samples is None:
          try:
              samples = Audio.from_file(audio_file)
              sample_rate = samples.frame_rate
              num_channels = samples.channels
              if offset > 0:
                  # pydub does things in milliseconds
                  seconds = offset * 1000
                  samples = samples[int(seconds) :]
              if duration > 0:
                  seconds = duration * 1000
                  samples = samples[: int(seconds)]
              samples = np.array(samples.get_array_of_samples())
              # For multi-channel signals, channels are stacked in a one-dimensional vector
              if num_channels > 1:
                  samples = np.reshape(samples, (-1, num_channels))
          except CouldntDecodeError as err:
              logging.error(
                  f"Loading {audio_file} via pydub raised CouldntDecodeError: `{err}`."
              )
  
      if samples is None:
          libs = "soundfile, and pydub" if HAVE_PYDUB else "soundfile"
          raise Exception(
              f"Your audio file {audio_file} could not be decoded. We tried using {libs}."
          )
  
      return cls(
          samples,
          sample_rate,
          target_sr=target_sr,
          trim=trim,
          trim_ref=trim_ref,
          trim_top_db=trim_top_db,
          trim_frame_length=trim_frame_length,
          trim_hop_length=trim_hop_length,
          orig_sr=orig_sr,
          channel_selector=channel_selector,
          normalize_db=normalize_db,
          ref_channel=ref_channel,
      )
  
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 6 for calling the AudioSegment obj's underlying member method code with example usage: obj.from_file(cls, audio_file, target_sr, int_values, offset, duration, trim, trim_ref, trim_top_db, trim_frame_length, trim_hop_length, orig_sr, channel_selector, normalize_db, ref_channel) and returns: cls, cls