Spaces:
Running
Running
update
Browse files
main.py
CHANGED
@@ -30,9 +30,13 @@ def get_args():
|
|
30 |
args = parser.parse_args()
|
31 |
return args
|
32 |
|
33 |
-
def process_uploaded_file(filename: str, silence_time: float = 0.3, longest_activate: float = 3.0) -> str:
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def run_nx_vad(filename: str, silence_time: float = 0.3, longest_activate: float = 3.0) -> str:
|
38 |
filename = Path(filename).as_posix()
|
@@ -48,7 +52,7 @@ def run_nx_vad(filename: str, silence_time: float = 0.3, longest_activate: float
|
|
48 |
|
49 |
vad_timestamps = re.findall(pattern, vad_result, flags=re.DOTALL)
|
50 |
|
51 |
-
vad_timestamps: str = json.dumps(vad_timestamps, ensure_ascii=False)
|
52 |
|
53 |
return vad_timestamps
|
54 |
|
@@ -69,6 +73,7 @@ def main():
|
|
69 |
for filename in example_wav_dir.glob("*.wav"):
|
70 |
examples.append(
|
71 |
[
|
|
|
72 |
filename.as_posix(),
|
73 |
0.3, 3.0,
|
74 |
]
|
@@ -85,6 +90,7 @@ def main():
|
|
85 |
type="filepath",
|
86 |
label="Upload from disk",
|
87 |
)
|
|
|
88 |
uploaded_silence_time = gr.Slider(minimum=0.0, maximum=1.0, value=0.3, step=0.01, label="silence time")
|
89 |
uploaded_longest_activate = gr.Slider(minimum=0.0, maximum=20.0, value=3.0, step=0.1, label="longest activate")
|
90 |
upload_button = gr.Button("Run VAD")
|
@@ -93,6 +99,7 @@ def main():
|
|
93 |
gr.Examples(
|
94 |
examples=examples,
|
95 |
inputs=[
|
|
|
96 |
uploaded_file,
|
97 |
uploaded_silence_time,
|
98 |
uploaded_longest_activate,
|
@@ -106,6 +113,7 @@ def main():
|
|
106 |
upload_button.click(
|
107 |
process_uploaded_file,
|
108 |
inputs=[
|
|
|
109 |
uploaded_file,
|
110 |
uploaded_silence_time,
|
111 |
uploaded_longest_activate,
|
|
|
30 |
args = parser.parse_args()
|
31 |
return args
|
32 |
|
33 |
+
def process_uploaded_file(vad_engine: str, filename: str, silence_time: float = 0.3, longest_activate: float = 3.0) -> str:
|
34 |
+
if vad_engine == "nx_vad":
|
35 |
+
return run_nx_vad(filename, silence_time, longest_activate)
|
36 |
+
elif vad_engine == "silero-vad":
|
37 |
+
return "silero-vad"
|
38 |
+
else:
|
39 |
+
return f"vad engine invalid: {vad_engine}"
|
40 |
|
41 |
def run_nx_vad(filename: str, silence_time: float = 0.3, longest_activate: float = 3.0) -> str:
|
42 |
filename = Path(filename).as_posix()
|
|
|
52 |
|
53 |
vad_timestamps = re.findall(pattern, vad_result, flags=re.DOTALL)
|
54 |
|
55 |
+
vad_timestamps: str = json.dumps(vad_timestamps, ensure_ascii=False, indent=2)
|
56 |
|
57 |
return vad_timestamps
|
58 |
|
|
|
73 |
for filename in example_wav_dir.glob("*.wav"):
|
74 |
examples.append(
|
75 |
[
|
76 |
+
"nx_vad",
|
77 |
filename.as_posix(),
|
78 |
0.3, 3.0,
|
79 |
]
|
|
|
90 |
type="filepath",
|
91 |
label="Upload from disk",
|
92 |
)
|
93 |
+
uploaded_vad_engine = gr.Dropdown(choices=["nx_vad", "silero-vad"], value="nx_vad", label="vad_engine")
|
94 |
uploaded_silence_time = gr.Slider(minimum=0.0, maximum=1.0, value=0.3, step=0.01, label="silence time")
|
95 |
uploaded_longest_activate = gr.Slider(minimum=0.0, maximum=20.0, value=3.0, step=0.1, label="longest activate")
|
96 |
upload_button = gr.Button("Run VAD")
|
|
|
99 |
gr.Examples(
|
100 |
examples=examples,
|
101 |
inputs=[
|
102 |
+
uploaded_vad_engine,
|
103 |
uploaded_file,
|
104 |
uploaded_silence_time,
|
105 |
uploaded_longest_activate,
|
|
|
113 |
upload_button.click(
|
114 |
process_uploaded_file,
|
115 |
inputs=[
|
116 |
+
uploaded_vad_engine,
|
117 |
uploaded_file,
|
118 |
uploaded_silence_time,
|
119 |
uploaded_longest_activate,
|