Spaces:
Runtime error
Runtime error
Hendrik Schroeter
commited on
Some more debug prints
Browse files
app.py
CHANGED
@@ -43,6 +43,7 @@ def mix_at_snr(clean, noise, snr, eps=1e-10):
|
|
43 |
K = torch.sqrt((E_noise / E_speech) * 10 ** (snr / 10) + eps)
|
44 |
noise = noise / K
|
45 |
mixture = clean + noise
|
|
|
46 |
assert torch.isfinite(mixture).all()
|
47 |
max_m = mixture.abs().max()
|
48 |
if max_m > 1:
|
@@ -51,25 +52,28 @@ def mix_at_snr(clean, noise, snr, eps=1e-10):
|
|
51 |
return clean, noise, mixture
|
52 |
|
53 |
|
54 |
-
def mix_and_denoise(
|
55 |
sr = config("sr", 48000, int, section="df")
|
56 |
-
print(
|
57 |
if noise is None:
|
58 |
noise = "samples/dkitchen.wav"
|
59 |
sp_kwargs = {}
|
60 |
-
if
|
61 |
speech = "samples/p232_013_clean.wav"
|
62 |
-
if
|
63 |
print("using speech_alt")
|
64 |
-
speech =
|
65 |
else:
|
|
|
66 |
sp_kwargs = {"frame_offset": 4800}
|
67 |
-
speech, _ = load_audio(
|
68 |
print(f"Loaded speech with shape {speech.shape}")
|
69 |
noise, _ = load_audio(noise, sr)
|
70 |
print(f"Loaded noise with shape {noise.shape}")
|
71 |
speech, noise, noisy = mix_at_snr(speech, noise, snr)
|
|
|
72 |
enhanced = enhance(model, df, noisy)
|
|
|
73 |
lim = torch.linspace(0.0, 1.0, int(sr * 0.15)).unsqueeze(0)
|
74 |
lim = torch.cat((lim, torch.ones(1, enhanced.shape[1] - lim.shape[1])), dim=1)
|
75 |
enhanced = enhanced * lim
|
|
|
43 |
K = torch.sqrt((E_noise / E_speech) * 10 ** (snr / 10) + eps)
|
44 |
noise = noise / K
|
45 |
mixture = clean + noise
|
46 |
+
print("mixture:", mixture.shape)
|
47 |
assert torch.isfinite(mixture).all()
|
48 |
max_m = mixture.abs().max()
|
49 |
if max_m > 1:
|
|
|
52 |
return clean, noise, mixture
|
53 |
|
54 |
|
55 |
+
def mix_and_denoise(speech_rec, speech_upl, noise, snr):
|
56 |
sr = config("sr", 48000, int, section="df")
|
57 |
+
print(speech_rec, noise, snr)
|
58 |
if noise is None:
|
59 |
noise = "samples/dkitchen.wav"
|
60 |
sp_kwargs = {}
|
61 |
+
if speech_rec is None or "none" in speech_rec:
|
62 |
speech = "samples/p232_013_clean.wav"
|
63 |
+
if speech_upl is not None and "none" not in speech_upl:
|
64 |
print("using speech_alt")
|
65 |
+
speech = speech_upl
|
66 |
else:
|
67 |
+
speech = speech_rec
|
68 |
sp_kwargs = {"frame_offset": 4800}
|
69 |
+
speech, _ = load_audio(speech_rec, sr, **sp_kwargs)
|
70 |
print(f"Loaded speech with shape {speech.shape}")
|
71 |
noise, _ = load_audio(noise, sr)
|
72 |
print(f"Loaded noise with shape {noise.shape}")
|
73 |
speech, noise, noisy = mix_at_snr(speech, noise, snr)
|
74 |
+
print("Start denoising audio")
|
75 |
enhanced = enhance(model, df, noisy)
|
76 |
+
print("Denoising finished")
|
77 |
lim = torch.linspace(0.0, 1.0, int(sr * 0.15)).unsqueeze(0)
|
78 |
lim = torch.cat((lim, torch.ones(1, enhanced.shape[1] - lim.shape[1])), dim=1)
|
79 |
enhanced = enhanced * lim
|