Spaces:
Runtime error
Runtime error
Hendrik Schroeter
commited on
add random noise start
Browse files
app.py
CHANGED
|
@@ -30,7 +30,9 @@ def mix_at_snr(clean, noise, snr, eps=1e-10):
|
|
| 30 |
noise = torch.as_tensor(noise).mean(0, keepdim=True)
|
| 31 |
if noise.shape[1] < clean.shape[1]:
|
| 32 |
noise = noise.repeat((1, int(math.ceil(clean.shape[1] / noise.shape[1]))))
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
E_speech = torch.mean(clean.pow(2)) + eps
|
| 35 |
E_noise = torch.mean(noise.pow(2))
|
| 36 |
K = torch.sqrt((E_noise / E_speech) * 10 ** (snr / 10) + eps)
|
|
@@ -64,9 +66,7 @@ inputs = [
|
|
| 64 |
gradio.inputs.Audio(
|
| 65 |
source="microphone,upload", type="filepath", optional=True, label="Speech"
|
| 66 |
),
|
| 67 |
-
gradio.inputs.Audio(
|
| 68 |
-
source="upload", type="filepath", optional=True, label="Noise"
|
| 69 |
-
),
|
| 70 |
gradio.inputs.Slider(minimum=-10, maximum=40, step=5, default=10),
|
| 71 |
]
|
| 72 |
examples = [
|
|
|
|
| 30 |
noise = torch.as_tensor(noise).mean(0, keepdim=True)
|
| 31 |
if noise.shape[1] < clean.shape[1]:
|
| 32 |
noise = noise.repeat((1, int(math.ceil(clean.shape[1] / noise.shape[1]))))
|
| 33 |
+
max_start = int(noise.shape[1] - clean.shape[1])
|
| 34 |
+
start = torch.randint(0, max_start)
|
| 35 |
+
noise = noise[:, start : start + clean.shape[1]]
|
| 36 |
E_speech = torch.mean(clean.pow(2)) + eps
|
| 37 |
E_noise = torch.mean(noise.pow(2))
|
| 38 |
K = torch.sqrt((E_noise / E_speech) * 10 ** (snr / 10) + eps)
|
|
|
|
| 66 |
gradio.inputs.Audio(
|
| 67 |
source="microphone,upload", type="filepath", optional=True, label="Speech"
|
| 68 |
),
|
| 69 |
+
gradio.inputs.Audio(source="upload", type="filepath", optional=True, label="Noise"),
|
|
|
|
|
|
|
| 70 |
gradio.inputs.Slider(minimum=-10, maximum=40, step=5, default=10),
|
| 71 |
]
|
| 72 |
examples = [
|