code: def add_environment_noise(wave_tensor, snr, noise_db):
      """Adds random environment noise deterministically chosen from `noise_db`.
  
      Args:
        wave_tensor: The input waveform signals to add noise to.
        snr: The signal to noise ratio for controlling the power of the noise.
        noise_db: A two dimensional tensor where the first dimension corresponds to
          the number of noise on which we sample the random noise.
  
      Returns:
        Noise injected waveform signals.
      """
  
      positive_sum = tf.cast(
          tf.reduce_sum(tf.maximum(wave_tensor, 0)), tf.int32
      )
      negative_sum = tf.cast(
          tf.reduce_sum(tf.maximum(-wave_tensor, 0)), tf.int32
      )
  
      snr = tf.cast(snr, wave_tensor.dtype)
  
      noise_idx = tf.random.stateless_uniform(
          [],
          [positive_sum, negative_sum],
          0,
          tf.shape(noise_db)[0],
          tf.int32,
      )
      target_noise = tf.cast(noise_db[noise_idx], wave_tensor.dtype)
  
      pos = tf.reduce_mean(tf.square(wave_tensor))
      if tf.size(target_noise) >= tf.size(wave_tensor):
          start_idx = tf.random.stateless_uniform(
              [],
              [positive_sum + 1, negative_sum + 1],
              0,
              tf.size(target_noise) - tf.size(wave_tensor) + 1,
              tf.int32,
          )
          target_noise = target_noise[
              start_idx : start_idx + tf.size(wave_tensor)
          ]
          nos = tf.reduce_mean(tf.square(target_noise))
      else:
          start_idx = tf.random.stateless_uniform(
              [],
              [positive_sum + 1, negative_sum + 1],
              0,
              tf.size(wave_tensor) - tf.size(target_noise) + 1,
              tf.int32,
          )
          nos = tf.reduce_mean(tf.square(target_noise))
          target_noise = tf.pad(
              target_noise,
              [
                  [
                      start_idx,
                      tf.size(wave_tensor)
                      - (start_idx + tf.size(target_noise)),
                  ]
              ],
          )
  
      multiplier = tf.math.divide_no_nan(
          1.0, tf.sqrt(tf.math.divide_no_nan(nos * snr, pos))
      )
      wave_tensor = wave_tensor + target_noise * multiplier
  
      return wave_tensor
  
imports: import functools
  from typing import Any, Dict, Optional, Sequence
  from absl import logging
  from dmvr import builders
  from dmvr import processors
  from dmvr import tokenizers
  import numpy
  from scenic.projects.mbt.datasets.dataset_utils import _decode_spectrogram
  from scenic.projects.mbt.datasets.dataset_utils import apply_specaugment
  import tensorflow
label_desc: Use image node_id 10 for calling a global function with example usage: add_environment_noise(wave_tensor, snr, noise_db) and returns: wave_tensor