Spaces:
Sleeping
Sleeping
File size: 2,464 Bytes
1b5bab7 8e4d19f 1b5bab7 5f8b366 930e37b 1b5bab7 930e37b 8e4d19f 930e37b 8e4d19f 930e37b 1b5bab7 930e37b 1b5bab7 930e37b 478eb01 930e37b 478eb01 930e37b 1b5bab7 5f8b366 1b5bab7 5f8b366 1b5bab7 930e37b 1b5bab7 40725f0 2ace022 5f8b366 1b5bab7 5f8b366 1b5bab7 5f8b366 1b5bab7 930e37b 1b5bab7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# app.py
import gradio as gr
from pydub import AudioSegment
from pydub.effects import compress_dynamic_range
from pydub.silence import split_on_silence
def remove_silence(audio_file, silence_thresh, min_silence_len, compression_threshold, amplification):
# Load the audio file
audio = AudioSegment.from_file(audio_file)
# Apply compression to the audio file
compressed_audio = compress_dynamic_range(audio, threshold=compression_threshold)
# Split the audio into parts without silence
chunks = split_on_silence(compressed_audio,
# Minimum silence length (in milliseconds)
min_silence_len=min_silence_len,
# Silence threshold (in dBFS)
silence_thresh=silence_thresh
)
# Check if any chunks were found
if not chunks:
return audio_file # Return the original file if no silence chunks were found
# Combine chunks without silence
audio_without_silence = sum(chunks)
# Amplify the audio
amplified_audio = audio_without_silence + amplification
# Export the amplified audio file
output_file = "audio_without_silence.wav"
amplified_audio.export(output_file, format="wav")
return output_file
# Create Gradio interface
iface = gr.Interface(
fn=remove_silence,
inputs=[
gr.Audio(sources=["upload", "microphone"], type="filepath", label="Upload or Record Audio File"),
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."),
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."),
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."),
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.")
],
outputs=gr.Audio(type="filepath", label="Processed Audio Without Silence"),
title="Remove Silence from Audio",
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."
)
# Run the app
if __name__ == "__main__":
iface.launch()
|