File size: 2,263 Bytes
dc7123b
 
 
 
 
 
5017efb
 
dc7123b
 
 
 
 
c5d5c61
 
 
 
 
 
 
dc7123b
c5d5c61
 
 
 
 
 
dc7123b
 
 
 
c5d5c61
dc7123b
 
c5d5c61
 
 
 
 
 
dc7123b
 
c5d5c61
dc7123b
 
 
 
 
 
5017efb
dc7123b
 
5017efb
 
dc7123b
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import torch
import gradio as gr
import torchaudio
from transformers import AutoModel
import spaces


checkpoint_path = "./"
model = AutoModel.from_pretrained(checkpoint_path, trust_remote_code=True)


@spaces.GPU()
def restore_audio(input_audio):
    # Load the audio file
    waveform, sample_rate = torchaudio.load(input_audio)
    
    # Calculate the duration of the audio (in seconds)
    duration = waveform.shape[1] / sample_rate

    # Output file path
    output_path = "restored_output.wav"
    
    if duration > 10:
        model(input_audio, output_path, short=False)
    else:
        model(input_audio, output_path) # short=True by default

    return output_path


with gr.Blocks() as demo:
    gr.Markdown("# πŸ”Š Voice Restoration with Transformer-based Model")
    gr.Markdown(
        """
        Upload a degraded audio file or select an example, and the space will restore it using the **VoiceRestore** model!

        Based on this [repo](https://github.com/skirdey/voicerestore) by [@Stan Kirdey](https://github.com/skirdey),
        and the HF Transformers πŸ€— [Model](https://huggingface.co/jadechoghari/VoiceRestore) by [@jadechoghari](https://github.com/jadechoghari).

        The model returns optimized results for audio less than 10 seconds, however, it supports unlimited duration!
        """
    )

    
    with gr.Row():
        with gr.Column():
            gr.Markdown("### 🎧 Select an Example or Upload Your Audio:")
            input_audio = gr.Audio(label="Upload Degraded Audio", type="filepath")
            gr.Examples(
                examples=["example_input.wav", "example_16khz.wav", "example-distort-16khz.wav", "example-full-degrad.wav", "example-reverb-16khz.wav"],
                inputs=input_audio,
                label="Sample Degraded Audios"
            ),
            cache_examples="lazy"
        
        with gr.Column():
            gr.Markdown("### 🎢 Restored Audio Output:")
            output_audio = gr.Audio(label="Restored Audio", type="filepath")

    with gr.Row():
        restore_btn = gr.Button("✨ Restore Audio")

    # Connect the button to the function
    restore_btn.click(restore_audio, inputs=input_audio, outputs=output_audio)

# Launch the demo
demo.launch(debug=True)