Ivan000 commited on
Commit
5f8b366
·
verified ·
1 Parent(s): 2ace022

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -4,7 +4,7 @@ from pydub import AudioSegment
4
  from pydub.effects import compress_dynamic_range
5
  from pydub.silence import split_on_silence
6
 
7
- def remove_silence(audio_file, silence_thresh, min_silence_len, compression_threshold):
8
  # Load the audio file
9
  audio = AudioSegment.from_file(audio_file)
10
 
@@ -27,9 +27,12 @@ def remove_silence(audio_file, silence_thresh, min_silence_len, compression_thre
27
  # Combine chunks without silence
28
  audio_without_silence = sum(chunks)
29
 
30
- # Export the audio file without silence
 
 
 
31
  output_file = "audio_without_silence.wav"
32
- audio_without_silence.export(output_file, format="wav")
33
 
34
  return output_file
35
 
@@ -40,11 +43,12 @@ iface = gr.Interface(
40
  gr.Audio(sources=["upload", "microphone"], type="filepath", label="Upload or Record Audio File"),
41
  gr.Slider(minimum=-100, maximum=0, step=1, value=-16, label="Silence Threshold (dBFS): The threshold in decibels (dBFS) below which audio is considered silence."),
42
  gr.Slider(minimum=10, maximum=5000, step=10, value=500, label="Minimum Silence Length (ms): The minimum length of silence (in milliseconds) to be detected."),
43
- gr.Slider(minimum=-100, maximum=0, step=1, value=-20, label="Compression Threshold (dBFS): The threshold in decibels (dBFS) for audio compression. Lower values compress more.")
 
44
  ],
45
- outputs=gr.Audio(type="filepath", label="Audio Without Silence"),
46
  title="Remove Silence from Audio",
47
- description="Upload an audio file or record audio and get the audio with silence removed. Adjust the silence threshold, minimum silence length, and compression threshold."
48
  )
49
 
50
  # Run the app
 
4
  from pydub.effects import compress_dynamic_range
5
  from pydub.silence import split_on_silence
6
 
7
+ def remove_silence(audio_file, silence_thresh, min_silence_len, compression_threshold, amplification):
8
  # Load the audio file
9
  audio = AudioSegment.from_file(audio_file)
10
 
 
27
  # Combine chunks without silence
28
  audio_without_silence = sum(chunks)
29
 
30
+ # Amplify the audio
31
+ amplified_audio = audio_without_silence + amplification
32
+
33
+ # Export the amplified audio file
34
  output_file = "audio_without_silence.wav"
35
+ amplified_audio.export(output_file, format="wav")
36
 
37
  return output_file
38
 
 
43
  gr.Audio(sources=["upload", "microphone"], type="filepath", label="Upload or Record Audio File"),
44
  gr.Slider(minimum=-100, maximum=0, step=1, value=-16, label="Silence Threshold (dBFS): The threshold in decibels (dBFS) below which audio is considered silence."),
45
  gr.Slider(minimum=10, maximum=5000, step=10, value=500, label="Minimum Silence Length (ms): The minimum length of silence (in milliseconds) to be detected."),
46
+ gr.Slider(minimum=-100, maximum=0, step=1, value=-20, label="Compression Threshold (dBFS): The threshold in decibels (dBFS) for audio compression. Lower values compress more."),
47
+ gr.Slider(minimum=0, maximum=30, step=1, value=0, label="Amplification (dB): Amplify the volume of the processed audio. Range from 0 dB (no change) to 30 dB.")
48
  ],
49
+ outputs=gr.Audio(type="filepath", label="Processed Audio Without Silence"),
50
  title="Remove Silence from Audio",
51
+ description="Upload an audio file or record audio and get the audio with silence removed. Adjust the silence threshold, minimum silence length, compression threshold, and amplification."
52
  )
53
 
54
  # Run the app