Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import torchaudio
|
4 |
-
from speechbrain.inference.enhancement import SpectralMaskEnhancement
|
5 |
from speechbrain.inference.separation import SepformerSeparation as separator
|
|
|
6 |
|
7 |
# Load the enhancement model
|
8 |
model = separator.from_hparams(
|
@@ -12,16 +12,23 @@ model = separator.from_hparams(
|
|
12 |
|
13 |
# Define the enhancement function
|
14 |
def enhance_audio(noisy_audio):
|
|
|
|
|
|
|
|
|
15 |
# Load and add a batch dimension to the audio tensor
|
16 |
-
noisy = model.load_audio(
|
17 |
|
18 |
# Enhance the audio
|
19 |
enhanced = model.enhance_batch(noisy, lengths=torch.tensor([1.0]))
|
20 |
|
21 |
-
# Save enhanced audio to a
|
22 |
enhanced_path = "enhanced.wav"
|
23 |
torchaudio.save(enhanced_path, enhanced.cpu(), 16000)
|
24 |
|
|
|
|
|
|
|
25 |
return enhanced_path
|
26 |
|
27 |
# Create the Gradio interface
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
import torchaudio
|
|
|
4 |
from speechbrain.inference.separation import SepformerSeparation as separator
|
5 |
+
import os
|
6 |
|
7 |
# Load the enhancement model
|
8 |
model = separator.from_hparams(
|
|
|
12 |
|
13 |
# Define the enhancement function
|
14 |
def enhance_audio(noisy_audio):
|
15 |
+
# Convert MP3 to WAV
|
16 |
+
wav_audio = "temp_audio.wav"
|
17 |
+
torchaudio.save(wav_audio, *torchaudio.load(noisy_audio))
|
18 |
+
|
19 |
# Load and add a batch dimension to the audio tensor
|
20 |
+
noisy = model.load_audio(wav_audio).unsqueeze(0)
|
21 |
|
22 |
# Enhance the audio
|
23 |
enhanced = model.enhance_batch(noisy, lengths=torch.tensor([1.0]))
|
24 |
|
25 |
+
# Save enhanced audio to a file
|
26 |
enhanced_path = "enhanced.wav"
|
27 |
torchaudio.save(enhanced_path, enhanced.cpu(), 16000)
|
28 |
|
29 |
+
# Clean up the temporary audio file
|
30 |
+
os.remove(wav_audio)
|
31 |
+
|
32 |
return enhanced_path
|
33 |
|
34 |
# Create the Gradio interface
|