class_docstr: MediaPipe Tasks' audio container.
class_docstr_tok: ["MediaPipe","Tasks","'","audio","container","."]
docstr: Loads the audio data from a NumPy array.
  
  Args:
    src: A NumPy source array contains the input audio.
    offset: An optional offset for loading a slice of the `src` array to the
      buffer.
    size: An optional size parameter denoting the number of samples to load
      from the `src` array.
  
  Raises:
    ValueError: If the input array has an incorrect shape or if
      `offset` + `size` exceeds the length of the `src` array.
docstr_tok: ["Loads","the","audio","data","from","a","NumPy","array",".","Args",":","src",":","A","NumPy","source","array","contains","the","input","audio",".","offset",":","An","optional","offset","for","loading","a","slice","of","the","`","src","`","array","to","the","buffer",".","size",":","An","optional","size","parameter","denoting","the","number","of","samples","to","load","from","the","`","src","`","array",".","Raises",":","ValueError",":","If","the","input","array","has","an","incorrect","shape","or","if","`","offset","`","+","`","size","`","exceeds","the","length","of","the","`","src","`","array","."]
code: def load_from_array(
      self, src: np.ndarray, offset: int = 0, size: int = -1
  ) -> None:
      """Loads the audio data from a NumPy array.
  
      Args:
        src: A NumPy source array contains the input audio.
        offset: An optional offset for loading a slice of the `src` array to the
          buffer.
        size: An optional size parameter denoting the number of samples to load
          from the `src` array.
  
      Raises:
        ValueError: If the input array has an incorrect shape or if
          `offset` + `size` exceeds the length of the `src` array.
      """
      if len(src.shape) == 1:
          if self._audio_format.num_channels != 1:
              raise ValueError(
                  f"Input audio is mono, but the audio data is expected "
                  f"to have {self._audio_format.num_channels} channels."
              )
      elif src.shape[1] != self._audio_format.num_channels:
          raise ValueError(
              f"Input audio contains an invalid number of channels. "
              f"Expect {self._audio_format.num_channels}."
          )
  
      if size < 0:
          size = len(src)
  
      if offset + size > len(src):
          raise ValueError(
              f"Index out of range. offset {offset} + size {size} should be <= "
              f"src's length: {len(src)}"
          )
  
      if len(src) >= len(self._buffer):
          # If the internal buffer is shorter than the load target (src), copy
          # values from the end of the src array to the internal buffer.
          new_offset = offset + size - len(self._buffer)
          new_size = len(self._buffer)
          self._buffer = src[new_offset : new_offset + new_size].copy()
      else:
          # Shift the internal buffer backward and add the incoming data to the end
          # of the buffer.
          shift = size
          self._buffer = np.roll(self._buffer, -shift, axis=0)
          self._buffer[-shift:, :] = src[offset : offset + size].copy()
  
file_path: mediapipe/mediapipe/tasks/python/components/containers/audio_data.py
imports: import dataclasses
  from typing import Optional
  import numpy
label_desc: Use image node_id 3 for calling the AudioData obj's underlying member method code with example usage: obj.load_from_array(src, offset, size) without return types