Ivan000 commited on
Commit
4e439de
·
verified ·
1 Parent(s): f2c63b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
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
- # Граница тишины (в dBFS)
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
- # Создание интерфейса Gradio
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, default_value=-16, label="Silence Threshold (dBFS)"),
34
- gr.Slider(minimum=100, maximum=5000, step=100, default_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
- # Запуск приложения
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()