Update app.py
Browse files
app.py
CHANGED
|
@@ -20,8 +20,11 @@ args = {
|
|
| 20 |
model = ScoreModel.load_from_checkpoint(args["ckpt"])
|
| 21 |
|
| 22 |
def enhance_speech(audio_file):
|
|
|
|
|
|
|
| 23 |
# Load and process the audio file
|
| 24 |
y, sr = torchaudio.load(audio_file)
|
|
|
|
| 25 |
T_orig = y.size(1)
|
| 26 |
|
| 27 |
# Normalize
|
|
@@ -30,6 +33,8 @@ def enhance_speech(audio_file):
|
|
| 30 |
|
| 31 |
# Prepare DNN input
|
| 32 |
Y = torch.unsqueeze(model._forward_transform(model._stft(y.to(args["device"]))), 0)
|
|
|
|
|
|
|
| 33 |
Y = pad_spec(Y, mode="zero_pad") # Use "zero_pad" mode for padding
|
| 34 |
|
| 35 |
# Reverse sampling
|
|
@@ -48,9 +53,11 @@ def enhance_speech(audio_file):
|
|
| 48 |
# Save the enhanced audio
|
| 49 |
output_file = 'enhanced_output.wav'
|
| 50 |
torchaudio.save(output_file, x_hat.cpu(), sr)
|
| 51 |
-
|
|
|
|
| 52 |
return output_file
|
| 53 |
|
|
|
|
| 54 |
# Gradio interface setup
|
| 55 |
inputs = gr.Audio(label="Input Audio", type="filepath")
|
| 56 |
outputs = gr.Audio(label="Output Audio", type="filepath")
|
|
|
|
| 20 |
model = ScoreModel.load_from_checkpoint(args["ckpt"])
|
| 21 |
|
| 22 |
def enhance_speech(audio_file):
|
| 23 |
+
start_time = time.time()
|
| 24 |
+
|
| 25 |
# Load and process the audio file
|
| 26 |
y, sr = torchaudio.load(audio_file)
|
| 27 |
+
print(f"Loaded audio in {time.time() - start_time:.2f}s")
|
| 28 |
T_orig = y.size(1)
|
| 29 |
|
| 30 |
# Normalize
|
|
|
|
| 33 |
|
| 34 |
# Prepare DNN input
|
| 35 |
Y = torch.unsqueeze(model._forward_transform(model._stft(y.to(args["device"]))), 0)
|
| 36 |
+
print(f"Transformed input in {time.time() - start_time:.2f}s")
|
| 37 |
+
|
| 38 |
Y = pad_spec(Y, mode="zero_pad") # Use "zero_pad" mode for padding
|
| 39 |
|
| 40 |
# Reverse sampling
|
|
|
|
| 53 |
# Save the enhanced audio
|
| 54 |
output_file = 'enhanced_output.wav'
|
| 55 |
torchaudio.save(output_file, x_hat.cpu(), sr)
|
| 56 |
+
|
| 57 |
+
print(f"Processed audio in {time.time() - start_time:.2f}s")
|
| 58 |
return output_file
|
| 59 |
|
| 60 |
+
|
| 61 |
# Gradio interface setup
|
| 62 |
inputs = gr.Audio(label="Input Audio", type="filepath")
|
| 63 |
outputs = gr.Audio(label="Output Audio", type="filepath")
|