Spaces:
Runtime error
Runtime error
Add application file
Browse files- app.py +130 -0
- asset/model/model_three.bin +3 -0
- asset/test/mix_clean/Audio0.wav +0 -0
- asset/test/mix_clean/Audio1.wav +0 -0
- asset/test/mix_clean/Audio2.wav +0 -0
- asset/test/s1/Audio0.wav +0 -0
- asset/test/s1/Audio1.wav +0 -0
- asset/test/s1/Audio2.wav +0 -0
- asset/test/s2/Audio0.wav +0 -0
- asset/test/s2/Audio1.wav +0 -0
- asset/test/s2/Audio2.wav +0 -0
- asset/test/s3/Audio0.wav +0 -0
- asset/test/s3/Audio1.wav +0 -0
- asset/test/s3/Audio2.wav +0 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
# Importing libraries
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
from asteroid.models import ConvTasNet, DPRNNTasNet
|
6 |
+
import torch
|
7 |
+
import os
|
8 |
+
import shutil
|
9 |
+
|
10 |
+
|
11 |
+
# ------------------ #
|
12 |
+
|
13 |
+
class tester():
|
14 |
+
def __init__(self, model):
|
15 |
+
# Modeling
|
16 |
+
self.model = model
|
17 |
+
# Test Directory will also contain output after files
|
18 |
+
self.test_dir = 'asset/test_subject/'
|
19 |
+
def prepare_test(self):
|
20 |
+
# Removing older test and their results
|
21 |
+
if os.path.exists(self.test_dir):
|
22 |
+
shutil.rmtree(self.test_dir)
|
23 |
+
|
24 |
+
if not os.path.exists(self.test_dir):
|
25 |
+
os.mkdir(self.test_dir)
|
26 |
+
def test(self, path):
|
27 |
+
self.prepare_test()
|
28 |
+
|
29 |
+
test_subject = self.test_dir + 'test.wav'
|
30 |
+
shutil.copyfile(path, test_subject)
|
31 |
+
|
32 |
+
self.model.separate(test_subject,force_overwrite=True, resample=True)
|
33 |
+
|
34 |
+
def load_model():
|
35 |
+
model = torch.load('asset/model/model_three.bin')
|
36 |
+
return model
|
37 |
+
|
38 |
+
def separator(original_audio, path):
|
39 |
+
Test = tester(load_model())
|
40 |
+
Test.prepare_test()
|
41 |
+
Test.test(path)
|
42 |
+
|
43 |
+
separated_audios = list()
|
44 |
+
separated_audios.append('asset/test_subject/test.wav')
|
45 |
+
separated_audios.append('asset/test_subject/test_est1.wav')
|
46 |
+
separated_audios.append('asset/test_subject/test_est2.wav')
|
47 |
+
separated_audios.append('asset/test_subject/test_est3.wav')
|
48 |
+
|
49 |
+
return separated_audios
|
50 |
+
|
51 |
+
demo = gr.Blocks(theme=gr.themes.Soft())
|
52 |
+
with demo:
|
53 |
+
|
54 |
+
gr.Markdown('''
|
55 |
+
<center>
|
56 |
+
<h1>Speech Separation</h1>
|
57 |
+
<div style="display:flex;align-items:center;justify-content:center;">
|
58 |
+
<iframe src="https://streamable.com/e/uribry?autoplay=1&nocontrols=1" frameborder="0" allow="autoplay">
|
59 |
+
</iframe>
|
60 |
+
</div>
|
61 |
+
<div></div>
|
62 |
+
<p>
|
63 |
+
It is a shareable demonstration window which can be used to view result on any device by setting 'share' a launch parameter 'True'.
|
64 |
+
It displays original audio for mixture of speaker, seperated audio by our model and original individual speaker audio.
|
65 |
+
</p>
|
66 |
+
</center>
|
67 |
+
''')
|
68 |
+
|
69 |
+
with gr.Row():
|
70 |
+
pass
|
71 |
+
with gr.Row():
|
72 |
+
pass
|
73 |
+
gr.Markdown('''
|
74 |
+
<h2> Original Audio</h2>
|
75 |
+
|
76 |
+
''')
|
77 |
+
with gr.Row():
|
78 |
+
output_text1 = gr.Text("Original Speech signal ", label='Original Audio', interactive=False)
|
79 |
+
original_audio = gr.Audio(label='Original Audio', interactive=False)
|
80 |
+
|
81 |
+
with gr.Row():
|
82 |
+
pass
|
83 |
+
with gr.Row():
|
84 |
+
pass
|
85 |
+
gr.Markdown('''
|
86 |
+
<h2> Separated Audio</h2>
|
87 |
+
|
88 |
+
''')
|
89 |
+
|
90 |
+
with gr.Row():
|
91 |
+
output_text1 = gr.Text("Separated Speech signal Speaker 1 ", label='Speaker 1', interactive=False)
|
92 |
+
output_audio1 = gr.Audio(label='Speaker 1', interactive=False)
|
93 |
+
with gr.Row():
|
94 |
+
output_text2 = gr.Text("Separated Speech signal Speaker 2 ", label='Speaker 2', interactive=False)
|
95 |
+
output_audio2 = gr.Audio(label='Speaker 2', interactive=False)
|
96 |
+
with gr.Row():
|
97 |
+
output_text3 = gr.Text("Separated Speech signal Speaker 3 ", label='Speaker 3', interactive=False)
|
98 |
+
output_audio3 = gr.Audio(label='Speaker 3', interactive=False)
|
99 |
+
|
100 |
+
|
101 |
+
outputs_audio = [original_audio, output_audio1, output_audio2, output_audio3]
|
102 |
+
button = gr.Button("Separate")
|
103 |
+
examples = [
|
104 |
+
"asset/test/mix_clean/Audio0.wav",
|
105 |
+
"asset/test/mix_clean/Audio1.wav",
|
106 |
+
"asset/test/mix_clean/Audio2.wav",
|
107 |
+
]
|
108 |
+
|
109 |
+
example_selector = gr.inputs.Radio(examples, label="Example Audio")
|
110 |
+
button.click(separator, inputs=[original_audio, example_selector], outputs=outputs_audio)
|
111 |
+
|
112 |
+
gr.Markdown('''
|
113 |
+
<center>
|
114 |
+
<div style="display:flex;align-items:center;justify-content:center;">
|
115 |
+
<a href="https://www.linkedin.com/in/dhruv73/" target="blank">
|
116 |
+
<img src="https://raw.githubusercontent.com/devicons/devicon/1119b9f84c0290e0f0b38982099a2bd027a48bf1/icons/linkedin/linkedin-original.svg" alt="LinkedIN: /dhruv_73" width="100" height="100"/>
|
117 |
+
</a>
|
118 |
+
 
|
119 |
+
<a href="https://github.com/DS-73" target="_blank">
|
120 |
+
<img src="https://raw.githubusercontent.com/devicons/devicon/1119b9f84c0290e0f0b38982099a2bd027a48bf1/icons/github/github-original.svg" alt="Github: /DS-73" width="100" height="100"/>
|
121 |
+
</a>
|
122 |
+
</div>
|
123 |
+
</center>
|
124 |
+
''')
|
125 |
+
|
126 |
+
demo.launch()
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
# ------------------ #
|
asset/model/model_three.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:40f33bdab1b33b1971e49fb7beda1965b8a95fb6af611b37b3eacd92191a8395
|
3 |
+
size 20630011
|
asset/test/mix_clean/Audio0.wav
ADDED
Binary file (377 kB). View file
|
|
asset/test/mix_clean/Audio1.wav
ADDED
Binary file (345 kB). View file
|
|
asset/test/mix_clean/Audio2.wav
ADDED
Binary file (416 kB). View file
|
|
asset/test/s1/Audio0.wav
ADDED
Binary file (377 kB). View file
|
|
asset/test/s1/Audio1.wav
ADDED
Binary file (345 kB). View file
|
|
asset/test/s1/Audio2.wav
ADDED
Binary file (416 kB). View file
|
|
asset/test/s2/Audio0.wav
ADDED
Binary file (377 kB). View file
|
|
asset/test/s2/Audio1.wav
ADDED
Binary file (345 kB). View file
|
|
asset/test/s2/Audio2.wav
ADDED
Binary file (416 kB). View file
|
|
asset/test/s3/Audio0.wav
ADDED
Binary file (377 kB). View file
|
|
asset/test/s3/Audio1.wav
ADDED
Binary file (345 kB). View file
|
|
asset/test/s3/Audio2.wav
ADDED
Binary file (416 kB). View file
|
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.34.0
|
2 |
+
gradio_client==0.2.6
|
3 |
+
torch==2.0.1
|
4 |
+
asteroid==0.6.0
|