Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,40 +4,40 @@ from pydub import AudioSegment
|
|
4 |
from pydub.silence import split_on_silence
|
5 |
|
6 |
def remove_silence(audio_file, silence_thresh, min_silence_len):
|
7 |
-
#
|
8 |
audio = AudioSegment.from_file(audio_file)
|
9 |
|
10 |
-
#
|
11 |
chunks = split_on_silence(audio,
|
12 |
-
#
|
13 |
min_silence_len=min_silence_len,
|
14 |
|
15 |
-
#
|
16 |
silence_thresh=silence_thresh
|
17 |
)
|
18 |
|
19 |
-
#
|
20 |
audio_without_silence = sum(chunks)
|
21 |
|
22 |
-
#
|
23 |
output_file = "audio_without_silence.wav"
|
24 |
audio_without_silence.export(output_file, format="wav")
|
25 |
|
26 |
return output_file
|
27 |
|
28 |
-
#
|
29 |
iface = gr.Interface(
|
30 |
fn=remove_silence,
|
31 |
inputs=[
|
32 |
gr.Audio(sources=["upload"], type="filepath", label="Upload Audio File"),
|
33 |
-
gr.Slider(minimum=-100, maximum=0, step=1,
|
34 |
-
gr.Slider(minimum=100, maximum=5000, step=100,
|
35 |
],
|
36 |
outputs=gr.Audio(type="filepath", label="Audio Without Silence"),
|
37 |
title="Remove Silence from Audio",
|
38 |
description="Upload an audio file and get the audio with silence removed. Adjust the silence threshold and minimum silence length."
|
39 |
)
|
40 |
|
41 |
-
#
|
42 |
if __name__ == "__main__":
|
43 |
iface.launch()
|
|
|
4 |
from pydub.silence import split_on_silence
|
5 |
|
6 |
def remove_silence(audio_file, silence_thresh, min_silence_len):
|
7 |
+
# Load audio file
|
8 |
audio = AudioSegment.from_file(audio_file)
|
9 |
|
10 |
+
# Split audio into chunks without silence
|
11 |
chunks = split_on_silence(audio,
|
12 |
+
# Minimum silence length (in milliseconds)
|
13 |
min_silence_len=min_silence_len,
|
14 |
|
15 |
+
# Silence threshold (in dBFS)
|
16 |
silence_thresh=silence_thresh
|
17 |
)
|
18 |
|
19 |
+
# Combine chunks without silence
|
20 |
audio_without_silence = sum(chunks)
|
21 |
|
22 |
+
# Export audio file without silence
|
23 |
output_file = "audio_without_silence.wav"
|
24 |
audio_without_silence.export(output_file, format="wav")
|
25 |
|
26 |
return output_file
|
27 |
|
28 |
+
# Create Gradio interface
|
29 |
iface = gr.Interface(
|
30 |
fn=remove_silence,
|
31 |
inputs=[
|
32 |
gr.Audio(sources=["upload"], type="filepath", label="Upload Audio File"),
|
33 |
+
gr.Slider(minimum=-100, maximum=0, step=1, value=-16, label="Silence Threshold (dBFS)"),
|
34 |
+
gr.Slider(minimum=100, maximum=5000, step=100, value=500, label="Minimum Silence Length (ms)")
|
35 |
],
|
36 |
outputs=gr.Audio(type="filepath", label="Audio Without Silence"),
|
37 |
title="Remove Silence from Audio",
|
38 |
description="Upload an audio file and get the audio with silence removed. Adjust the silence threshold and minimum silence length."
|
39 |
)
|
40 |
|
41 |
+
# Run the app
|
42 |
if __name__ == "__main__":
|
43 |
iface.launch()
|