Upload augment.py with huggingface_hub
Browse files- augment.py +2 -20
augment.py
CHANGED
|
@@ -1,22 +1,4 @@
|
|
| 1 |
import torch
|
| 2 |
|
| 3 |
-
def apply_white_noise(
|
| 4 |
-
|
| 5 |
-
noise = torch.randn_like(waveform) * noise_level
|
| 6 |
-
return waveform + noise
|
| 7 |
-
|
| 8 |
-
def apply_room_echo(waveform, sample_rate=16000, delay_ms=60, decay=0.4):
|
| 9 |
-
"""Emulates indoor wall reflection dynamics via frame delay buffers."""
|
| 10 |
-
delay_samples = int(sample_rate * (delay_ms / 1000.0))
|
| 11 |
-
if waveform.shape[-1] <= delay_samples:
|
| 12 |
-
return waveform
|
| 13 |
-
echo_signal = torch.zeros_like(waveform)
|
| 14 |
-
echo_signal[..., delay_samples:] = waveform[..., :-delay_samples] * decay
|
| 15 |
-
return waveform + echo_signal
|
| 16 |
-
|
| 17 |
-
def apply_low_pass_filter(waveform, alpha=0.5):
|
| 18 |
-
"""Clips high frequencies to stress-test against low-end mobile hardware."""
|
| 19 |
-
perturbed = waveform.clone()
|
| 20 |
-
for i in range(1, waveform.shape[-1]):
|
| 21 |
-
perturbed[..., i] = alpha * waveform[..., i] + (1 - alpha) * perturbed[..., i-1]
|
| 22 |
-
return perturbed
|
|
|
|
| 1 |
import torch
|
| 2 |
|
| 3 |
+
def apply_white_noise(x):
|
| 4 |
+
return x + 0.005 * torch.randn_like(x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|