Spaces:
Runtime error
Runtime error
Hendrik Schroeter
commited on
update
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ def mix_at_snr(clean, noise, snr, eps=1e-10):
|
|
| 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))
|
|
@@ -47,9 +47,13 @@ def as_gradio_audio(x):
|
|
| 47 |
return sr, (x / 0x7FFF).to(torch.int16).cpu().numpy()
|
| 48 |
|
| 49 |
|
| 50 |
-
def mix_and_denoise(speech, noise, snr):
|
| 51 |
if noise is None:
|
| 52 |
noise = "samples/dkitchen.wav"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
print(speech, noise, snr)
|
| 54 |
sr = config("sr", 48000, int, section="df")
|
| 55 |
speech, _ = load_audio(speech, sr)
|
|
@@ -64,10 +68,13 @@ def mix_and_denoise(speech, noise, snr):
|
|
| 64 |
|
| 65 |
inputs = [
|
| 66 |
gradio.inputs.Audio(
|
| 67 |
-
source="microphone
|
| 68 |
),
|
| 69 |
-
gradio.inputs.Audio(
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
]
|
| 72 |
examples = [
|
| 73 |
["samples/p232_013_clean.wav", "samples/dkitchen.wav", 10],
|
|
|
|
| 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, ()).item()
|
| 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))
|
|
|
|
| 47 |
return sr, (x / 0x7FFF).to(torch.int16).cpu().numpy()
|
| 48 |
|
| 49 |
|
| 50 |
+
def mix_and_denoise(speech, speech_alt, noise, snr):
|
| 51 |
if noise is None:
|
| 52 |
noise = "samples/dkitchen.wav"
|
| 53 |
+
if speech is None:
|
| 54 |
+
if speech_alt is None:
|
| 55 |
+
speech = "samples/p232_013_clean.wav"
|
| 56 |
+
speech = speech_alt
|
| 57 |
print(speech, noise, snr)
|
| 58 |
sr = config("sr", 48000, int, section="df")
|
| 59 |
speech, _ = load_audio(speech, sr)
|
|
|
|
| 68 |
|
| 69 |
inputs = [
|
| 70 |
gradio.inputs.Audio(
|
| 71 |
+
source="microphone", type="filepath", optional=True, label="Record your own voice"
|
| 72 |
),
|
| 73 |
+
gradio.inputs.Audio(
|
| 74 |
+
source="upload", type="filepath", optional=True, label="Alternative: Upload speech sample"
|
| 75 |
+
),
|
| 76 |
+
gradio.inputs.Audio(source="upload", type="filepath", optional=True, label="Upload noise sample"),
|
| 77 |
+
gradio.inputs.Slider(minimum=-20, maximum=40, step=5, default=10),
|
| 78 |
]
|
| 79 |
examples = [
|
| 80 |
["samples/p232_013_clean.wav", "samples/dkitchen.wav", 10],
|