Spaces:

File size: 1,260 Bytes
740a68f
 
 
8a51868
 
740a68f
 
8a51868
740a68f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import torch
import torchaudio
from sgmse.model import ScoreModel
import gradio as gr

# Load the pre-trained model
model = ScoreModel.load_from_checkpoint("path/to/your/checkpoint.ckpt")

def enhance_speech(audio_file):
    # Load and process the audio file
    noisy, sr = torchaudio.load(audio_file)
    noisy = noisy.unsqueeze(0)  # Add fake batch dimension if needed
    
    # Run the speech enhancement model
    enhanced = model.predict(noisy)
    
    # Save the enhanced audio
    output_file = 'enhanced_output.wav'
    torchaudio.save(output_file, enhanced.cpu().squeeze(0), sr)
    
    return output_file

# Gradio interface setup
inputs = gr.Audio(label="Input Audio", type="filepath")
outputs = gr.Audio(label="Output Audio", type="filepath")
title = "Speech Enhancement using SGMSE"
description = "This Gradio demo uses the SGMSE model for speech enhancement. Upload your audio file to enhance it."
article = "<p style='text-align: center'><a href='https://huggingface.co/SP-UHH/speech-enhancement-sgmse' target='_blank'>Model Card</a></p>"
examples = [
    ['samples/your_example_audio.wav']
]

gr.Interface(fn=enhance_speech, inputs=inputs, outputs=outputs, title=title, description=description, article=article, examples=examples).launch()