code: def _load_audio_as_array(audio_path, sample_rate):
      """Load audio file at specified sample rate and return an array.
  
      When `sample_rate` > original SR of audio file, Pydub may miss samples when
      reading file defined in `audio_path`. Must manually zero-pad missing samples.
  
      Args:
        audio_path: path to audio file
        sample_rate: desired sample rate (can be different from original SR)
  
      Returns:
        audio: audio in np.float32
      """
      with tf.io.gfile.GFile(audio_path, "rb") as f:
          # Load audio at original SR
          audio_segment = pydub.AudioSegment.from_file(f).set_channels(
              1
          )
          # Compute expected length at given `sample_rate`
          expected_len = int(
              audio_segment.duration_seconds * sample_rate
          )
          # Resample to `sample_rate`
          audio_segment = audio_segment.set_frame_rate(sample_rate)
          sample_arr = audio_segment.get_array_of_samples()
          audio = np.array(sample_arr).astype(np.float32)
          # Zero pad missing samples, if any
          audio = spectral_ops.pad_or_trim_to_expected_length(
              audio, expected_len
          )
      # Convert from int to float representation.
      audio /= np.iinfo(sample_arr.typecode).max
      return audio
  
file_path: ddsp/ddsp/training/data_preparation/prepare_tfrecord_lib.py
imports: from absl import logging
  import apache_beam
  from ddsp import spectral_ops
  import numpy
  import pydub
  import tensorflow.compat.v2
label_desc: Use image node_id 1 for calling a global function with example usage: _load_audio_as_array(audio_path, sample_rate) and returns: audio