File size: 2,675 Bytes
6d72cca
 
 
 
 
 
 
36ee14d
6d72cca
 
 
 
 
 
 
 
 
 
 
 
c91383c
 
 
6d72cca
36ee14d
6d72cca
e65415c
6d72cca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e65415c
6d72cca
 
 
 
 
e65415c
 
 
 
6d72cca
e65415c
 
 
 
 
 
 
 
6d72cca
 
 
429557a
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
import os
import gradio as gr
import subprocess
os.system("git clone https://github.com/doevent/FullSubNet-plus")
os.system("mv FullSubNet-plus/speech_enhance .")
os.system("mv FullSubNet-plus/config .")
os.system("gdown https://drive.google.com/uc?id=1UJSt1G0P_aXry-u79LLU_l9tCnNa2u7C -O best_model.tar")
from speech_enhance.tools.denoise_hf_clone_voice import start


# If the file is too duration to inference
def duration(input_audio) -> int:
    command = f"ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 -i {input_audio}"
    result = subprocess.run(command, shell=True, stdout=subprocess.PIPE)
    data = result.stdout.decode('ascii').rstrip()
    return int(float(data))
    

def inference(audio):
    try:
        if audio.find("audio") < 0:
            if duration(audio) >= 150:
                return "error.wav"
        result = start(to_list_files=[audio])
        return result[0]
    except Exception as e:
        gr.Error(f"Maximum duration 150 sec\n{str(e)}")

        
title = """<h1 id="title">DeNoise Speech Enhancement</h1>"""
description = """
This is an unofficial demo for FullSubNet-plus: DeNoise Speech Enhancement. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below.
Link to GitHub:
- [FullSubNet +](https://github.com/hit-thusz-RookieCJ/FullSubNet-plus)  
"""
twitter_link = "[![](https://img.shields.io/twitter/follow/DoEvent?label=@DoEvent&style=social)](https://twitter.com/DoEvent)"
css = '''
h1#title {
  text-align: center;
}
'''

with gr.Blocks(css=css) as demo:
    gr.Markdown(title)
    gr.Markdown(description)
    gr.Markdown(twitter_link)
    
    
    with gr.Tab("Upload audio"):
        u_audio = gr.Audio(type="filepath", source="upload", label="Input audio")
        u_output = gr.Audio(type="filepath", label="Output audio")
        u_button = gr.Button("Submit")
    
    with gr.Tab("Record your voice"):
        m_audio = gr.Audio(ype="filepath", source="microphone", label="Record yourself reading something out loud")
        m_output = gr.Audio(type="filepath", label="Output audio")
        m_button = gr.Button("Submit")

    gr.Examples(examples=["man.wav", "woman.wav"], inputs=u_audio, outputs=u_output, fn=inference, cache_examples=True)
    u_button.click(inference, inputs=u_audio, outputs=u_output)
    m_button.click(inference, inputs=m_audio, outputs=m_output)
    gr.Markdown("<div><center><img src='https://visitor-badge.glitch.me/badge?page_id=max_skobeev_fullsubnet_plus_public' alt='visitor badge'></center></div>")


demo.queue(concurrency_count=1, api_open=False).launch(show_api=False, show_error=True)