code: def test_SpectrogramDrop():
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      mean = spectrogram.mean()
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="zeros",
          dim=1,
      )
      output = drop(spectrogram)
      assert mean > output.mean()
      assert spectrogram.shape == output.shape
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      mean = spectrogram.mean()
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="zeros",
          dim=2,
      )
      output = drop(spectrogram)
      assert mean > output.mean()
      assert spectrogram.shape == output.shape
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="mean",
          dim=1,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="mean",
          dim=2,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="cutcat",
          dim=1,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="cutcat",
          dim=2,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="swap",
          dim=1,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="swap",
          dim=2,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
      assert torch.allclose(spectrogram.mean(), output.mean())
  
      # Important: understand why sometimes with random selection, spectrogram and output are the same....
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="random_selection",
          dim=1,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
  
      from speechbrain.augment.freq_domain import SpectrogramDrop
  
      spectrogram = torch.rand(4, 100, 40)
      drop = SpectrogramDrop(
          drop_length_low=1,
          drop_length_high=15,
          drop_count_low=1,
          drop_count_high=3,
          replace="random_selection",
          dim=2,
      )
      output = drop(spectrogram.clone())
      assert spectrogram.shape == output.shape
      assert not torch.equal(spectrogram, output)
  
      from speechbrain.augment.codec import CodecAugment
  
      if torchaudio.list_audio_backends()[0] == "ffmpeg":
          waveform = torch.rand(4, 16000)
          augmenter = CodecAugment(16000)
          output_waveform = augmenter(waveform)
          assert not torch.allclose(waveform, output_waveform)
  
      from speechbrain.augment.time_domain import DropBitResolution
  
      dropper = DropBitResolution()
      signal = torch.rand(4, 16000)
      signal_dropped = dropper(signal)
      assert not torch.equal(signal, signal_dropped)
      assert signal.shape == signal_dropped.shape
  
      from speechbrain.augment.time_domain import DropBitResolution
  
      dropper = DropBitResolution(target_dtype="int8")
      signal = torch.rand(4, 16000)
      signal_dropped = dropper(signal)
      assert not torch.equal(signal, signal_dropped)
      assert signal.shape == signal_dropped.shape
  
      from speechbrain.augment.time_domain import DropBitResolution
  
      dropper = DropBitResolution(target_dtype="int16")
      signal = torch.rand(4, 16000)
      signal_dropped = dropper(signal)
      assert not torch.equal(signal, signal_dropped)
      assert signal.shape == signal_dropped.shape
  
      from speechbrain.augment.time_domain import DropBitResolution
  
      dropper = DropBitResolution(target_dtype="float16")
      signal = torch.rand(4, 16000)
      signal_dropped = dropper(signal)
      assert not torch.equal(signal, signal_dropped)
      assert signal.shape == signal_dropped.shape
  
file_path: speechbrain/tests/unittests/test_augment.py
imports: import os
  import torch
  import torchaudio
  from speechbrain.dataio.dataio import write_audio
label_desc: Use image node_id 13 for calling a global function with example usage: test_SpectrogramDrop() without return types