Ivan000 commited on
Commit
478eb01
·
verified ·
1 Parent(s): 40725f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -4,28 +4,32 @@ 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=[
@@ -38,6 +42,6 @@ iface = gr.Interface(
38
  description="Upload an audio file or record audio 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
+ # Check if any chunks were found
20
+ if not chunks:
21
+ return audio_file # Return the original file if no silence chunks were found
22
+
23
+ # Combine chunks without silence
24
  audio_without_silence = sum(chunks)
25
 
26
+ # Export audio file without silence
27
  output_file = "audio_without_silence.wav"
28
  audio_without_silence.export(output_file, format="wav")
29
 
30
  return output_file
31
 
32
+ # Create Gradio interface
33
  iface = gr.Interface(
34
  fn=remove_silence,
35
  inputs=[
 
42
  description="Upload an audio file or record audio and get the audio with silence removed. Adjust the silence threshold and minimum silence length."
43
  )
44
 
45
+ # Run the app
46
  if __name__ == "__main__":
47
  iface.launch()