class_docstr: Helper object for computing loudness metrics.
class_docstr_tok: ["Helper","object","for","computing","loudness","metrics","."]
docstr: Update metrics based on a batch of audio.
  
  Args:
    batch: Dictionary of input features.
    audio_gen: Batch of generated audio.
docstr_tok: ["Update","metrics","based","on","a","batch","of","audio",".","Args",":","batch",":","Dictionary","of","input","features",".","audio_gen",":","Batch","of","generated","audio","."]
code: def update_state(self, batch, audio_gen):
      """Update metrics based on a batch of audio.
  
      Args:
        batch: Dictionary of input features.
        audio_gen: Batch of generated audio.
      """
      if "loudness_db" in batch:
          loudness_original = batch["loudness_db"]
      else:
          loudness_original = ddsp.spectral_ops.compute_loudness(
              batch["audio"],
              sample_rate=self._sample_rate,
              frame_rate=self._frame_rate,
          )
  
      # Compute loudness across entire batch
      loudness_gen = ddsp.spectral_ops.compute_loudness(
          audio_gen,
          sample_rate=self._sample_rate,
          frame_rate=self._frame_rate,
      )
  
      batch_size = int(audio_gen.shape[0])
      for i in range(batch_size):
          ld_dist = np.mean(
              l1_distance(loudness_original[i], loudness_gen[i])
          )
          self.metrics["loudness_db"].update_state(ld_dist)
          log_str = (
              f"{self._name} | sample {i} | ld_dist(db): {ld_dist:.3f}"
          )
          logging.info(log_str)
  
imports: import dataclasses
  from absl import logging
  import ddsp
  import librosa
  import mir_eval
  import note_seq
  from note_seq import sequences_lib
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 3 for calling the LoudnessMetrics obj's underlying member method code with example usage: obj.update_state(batch, audio_gen) without return types