code: def test_add_noise(tmpdir, device):
      from speechbrain.augment.time_domain import AddNoise
  
      # Test concatenation of batches
      wav_a = torch.sin(torch.arange(8000.0, device=device)).unsqueeze(
          0
      )
      a_len = torch.ones(1, device=device)
      wav_b = (
          torch.cos(torch.arange(10000.0, device=device))
          .unsqueeze(0)
          .repeat(2, 1)
      )
      b_len = torch.ones(2, device=device)
      concat, lens = AddNoise._concat_batch(wav_a, a_len, wav_b, b_len)
      assert concat.shape == (3, 10000)
      assert lens.allclose(torch.Tensor([0.8, 1, 1]).to(device))
      concat, lens = AddNoise._concat_batch(wav_b, b_len, wav_a, a_len)
      assert concat.shape == (3, 10000)
      expected = torch.Tensor([1, 1, 0.8]).to(device)
      assert lens.allclose(expected)
  
      test_waveform = torch.sin(
          torch.arange(16000.0, device=device)
      ).unsqueeze(0)
      test_noise = torch.cos(
          torch.arange(16000.0, device=device)
      ).unsqueeze(0)
      wav_lens = torch.ones(1, device=device)
  
      # Put noise waveform into temporary file
      noisefile = os.path.join(tmpdir, "noise.wav")
      write_audio(noisefile, test_noise.transpose(0, 1).cpu(), 16000)
  
      csv = os.path.join(tmpdir, "noise.csv")
      with open(csv, "w") as w:
          w.write("ID, duration, wav, wav_format, wav_opts\n")
          w.write(f"1, 1.0, {noisefile}, wav,\n")
  
      # Edge cases
      no_noise = AddNoise(snr_low=1000, snr_high=1000)
      assert no_noise(test_waveform, wav_lens).allclose(test_waveform)
      all_noise = AddNoise(csv_file=csv, snr_low=-1000, snr_high=-1000)
      assert all_noise(test_waveform, wav_lens).allclose(
          test_noise, atol=1e-4
      )
  
      # Basic 0dB case
      add_noise = AddNoise(csv_file=csv).to(device)
      expected = (test_waveform + test_noise) / 2
      assert add_noise(test_waveform, wav_lens).allclose(
          expected, atol=1e-4
      )
  
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 1 for calling a global function with example usage: test_add_noise(tmpdir, device) without return types