azamat commited on
Commit
96c45a5
1 Parent(s): 0ead0b4
Files changed (1) hide show
  1. app.py +18 -20
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(files, ckpt_path = CHECKPOINT):
42
  """
43
  Denoise audio
44
  Parameters:
@@ -68,25 +68,23 @@ def denoise(files, ckpt_path = CHECKPOINT):
68
 
69
  # inference
70
  batch_size = 1000000
71
- for file_path in tqdm(files):
72
- file_name = os.path.basename(file_path)
73
- file_dir = os.path.dirname(file_name)
74
- new_file_name = file_name + "_denoised.wav"
75
- noisy_audio = load_simple(file_path)
76
- LENGTH = len(noisy_audio[0].squeeze())
77
- noisy_audio = torch.chunk(noisy_audio, LENGTH // batch_size + 1, dim=1)
78
- all_audio = []
79
-
80
- for batch in tqdm(noisy_audio):
81
- with torch.no_grad():
82
- generated_audio = sampling(net, batch)
83
- generated_audio = generated_audio.cpu().numpy().squeeze()
84
- all_audio.append(generated_audio)
85
-
86
- all_audio = np.concatenate(all_audio, axis=0)
87
- save_file = os.path.join(file_dir, new_file_name)
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')