add audio and video blocks
Browse files
app.py
CHANGED
@@ -1,32 +1,63 @@
|
|
|
|
1 |
from speechbrain.inference.separation import SepformerSeparation as separator
|
2 |
import torchaudio
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
def speechbrain(
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2010.13154' target='_blank'>Attention is All You Need in Speech Separation</a> | <a href='https://github.com/speechbrain/speechbrain/tree/develop/templates/enhancement' '_blank'>Github Repo</a></p>"
|
16 |
-
examples = [
|
17 |
-
['samples_audio_samples_test_mixture.wav']
|
18 |
-
]
|
19 |
-
|
20 |
-
demo = gr.Interface(
|
21 |
-
fn=speechbrain,
|
22 |
-
inputs=gr.Audio(type="filepath"),
|
23 |
-
outputs=[
|
24 |
-
gr.Audio(label="Output Audio", type="filepath")
|
25 |
-
],
|
26 |
-
title=title,
|
27 |
-
description=description,
|
28 |
-
article=article,
|
29 |
-
examples=examples
|
30 |
-
)
|
31 |
-
demo.launch()
|
32 |
-
|
|
|
1 |
+
import os
|
2 |
from speechbrain.inference.separation import SepformerSeparation as separator
|
3 |
import torchaudio
|
4 |
import gradio as gr
|
5 |
+
from moviepy.editor import VideoFileClip
|
6 |
|
7 |
+
def convert_video_to_audio(video_input):
|
8 |
+
video_clip = VideoFileClip(video_input)
|
9 |
+
audio_clip = video_clip.audio
|
10 |
+
audio_clip_filepath = os.path.normpath(f"{video_input.split('.')[0]}.m4a")
|
11 |
+
audio_clip.write_audiofile(audio_clip_filepath, codec='aac')
|
12 |
+
audio_clip.close()
|
13 |
+
video_clip.close()
|
14 |
+
return audio_clip_filepath
|
15 |
|
16 |
+
def speechbrain(input_obj, input_obj_type):
|
17 |
+
|
18 |
+
if input_obj_type == "video":
|
19 |
+
aud = convert_video_to_audio(input_obj)
|
20 |
+
est_sources = model.separate_file(path=aud)
|
21 |
+
torchaudio.save("clean_audio_file.wav", est_sources[:, :, 0].detach().cpu(), 8000)
|
22 |
+
return "clean_audio_file.wav"
|
23 |
|
24 |
+
def main():
|
25 |
+
with gr.Blocks(title="Speech Enhancement", delete_cache=(86400, 86400), theme=gr.themes.Base()) as demo:
|
26 |
+
description = "Gradio demo for Speech Enhancement by SpeechBrain. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below."
|
27 |
+
article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2010.13154' target='_blank'>Attention is All You Need in Speech Separation</a> | <a href='https://github.com/speechbrain/speechbrain/tree/develop/templates/enhancement' '_blank'>Github Repo</a></p>"
|
28 |
+
examples = [
|
29 |
+
['samples_audio_samples_test_mixture.wav']
|
30 |
+
]
|
31 |
+
with gr.Tabs(selected="video") as tabs:
|
32 |
+
with gr.Tab("Video", id="video"):
|
33 |
+
gr.Interface(
|
34 |
+
fn=speechbrain,
|
35 |
+
inputs=[
|
36 |
+
gr.Video(type="filepath"),
|
37 |
+
gr.Radio(choices=["video"], value="video", label="File Type")
|
38 |
+
]
|
39 |
+
outputs=[
|
40 |
+
gr.Audio(label="Output Audio", type="filepath")
|
41 |
+
],
|
42 |
+
description=description,
|
43 |
+
article=article,
|
44 |
+
examples=examples
|
45 |
+
)
|
46 |
+
with gr.Tab("Audio", id="audio"):
|
47 |
+
gr.Interface(
|
48 |
+
fn=speechbrain,
|
49 |
+
inputs=[
|
50 |
+
gr.Audio(type="filepath"),
|
51 |
+
gr.Radio(choices=["audio"], value="audio", label="File Type")
|
52 |
+
]
|
53 |
+
outputs=[
|
54 |
+
gr.Audio(label="Output Audio", type="filepath"),
|
55 |
+
],
|
56 |
+
description=description,
|
57 |
+
article=article,
|
58 |
+
examples=examples
|
59 |
+
)
|
60 |
+
demo.launch()
|
61 |
|
62 |
+
if __name__ == '__main__':
|
63 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|