Spaces:
Runtime error
Runtime error
fix bug
Browse files
app.py
CHANGED
@@ -38,7 +38,7 @@ with open(CONFIG) as f:
|
|
38 |
global trainset_config
|
39 |
trainset_config = config["trainset_config"] # to read trainset configurations
|
40 |
|
41 |
-
def denoise(
|
42 |
"""
|
43 |
Denoise audio
|
44 |
Parameters:
|
@@ -68,25 +68,23 @@ def denoise(files, ckpt_path = CHECKPOINT):
|
|
68 |
|
69 |
# inference
|
70 |
batch_size = 1000000
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
print("saved to:", save_file)
|
89 |
-
wavwrite(save_file, 32000, all_audio.squeeze())
|
90 |
|
91 |
|
92 |
audio = gr.inputs.Audio(label = "Audio to denoise", type = 'filepath')
|
|
|
38 |
global trainset_config
|
39 |
trainset_config = config["trainset_config"] # to read trainset configurations
|
40 |
|
41 |
+
def denoise(filename, ckpt_path = CHECKPOINT):
|
42 |
"""
|
43 |
Denoise audio
|
44 |
Parameters:
|
|
|
68 |
|
69 |
# inference
|
70 |
batch_size = 1000000
|
71 |
+
new_file_name = filename + "_denoised.wav"
|
72 |
+
noisy_audio = load_simple(filename)
|
73 |
+
LENGTH = len(noisy_audio[0].squeeze())
|
74 |
+
noisy_audio = torch.chunk(noisy_audio, LENGTH // batch_size + 1, dim=1)
|
75 |
+
all_audio = []
|
76 |
+
|
77 |
+
for batch in tqdm(noisy_audio):
|
78 |
+
with torch.no_grad():
|
79 |
+
generated_audio = sampling(net, batch)
|
80 |
+
generated_audio = generated_audio.cpu().numpy().squeeze()
|
81 |
+
all_audio.append(generated_audio)
|
82 |
+
|
83 |
+
all_audio = np.concatenate(all_audio, axis=0)
|
84 |
+
print("saved to:", new_file_name)
|
85 |
+
wavwrite(new_file_name, 32000, all_audio.squeeze())
|
86 |
+
|
87 |
+
return new_file_name
|
|
|
|
|
88 |
|
89 |
|
90 |
audio = gr.inputs.Audio(label = "Audio to denoise", type = 'filepath')
|