| import gradio as gr |
| import torch |
| import torchaudio |
| import os |
|
|
| |
| model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', |
| model='silero_vad', |
| force_reload=False, |
| trust_repo=True) |
|
|
| (get_speech_timestamps, save_audio, read_audio, VADIterator, collect_chunks) = utils |
|
|
| def remove_silence(audio_path): |
| if audio_path is None: |
| return None |
| |
| wav = read_audio(audio_path, sampling_rate=16000) |
| |
| |
| speech_timestamps = get_speech_timestamps( |
| wav, |
| model, |
| sampling_rate=16000, |
| threshold=0.8, |
| min_silence_duration_ms=10, |
| speech_pad_ms=0, |
| min_speech_duration_ms=50 |
| ) |
|
|
| if not speech_timestamps: |
| return audio_path |
|
|
| |
| output_file = os.path.basename(audio_path) |
| |
| save_audio(output_file, collect_chunks(speech_timestamps, wav), sampling_rate=16000) |
| return output_file |
|
|
| |
| css = """ |
| @keyframes rgb-glow { |
| 0% { color: #ff0000; text-shadow: 0 0 10px #ff0000; } |
| 33% { color: #00ff00; text-shadow: 0 0 10px #00ff00; } |
| 66% { color: #0000ff; text-shadow: 0 0 10px #0000ff; } |
| 100% { color: #ff0000; text-shadow: 0 0 10px #ff0000; } |
| } |
| .deepu-brand { |
| text-align: center; |
| font-size: 28px; |
| font-weight: bold; |
| font-family: 'Comic Sans MS', 'Trebuchet MS', sans-serif; |
| animation: rgb-glow 2.5s linear infinite; |
| padding: 12px; |
| letter-spacing: 2px; |
| margin: 15px 0; |
| border: 2px dashed #ddd; |
| border-radius: 10px; |
| background-color: rgba(0, 0, 0, 0.02); |
| } |
| """ |
|
|
| |
| with gr.Blocks(css=css, title="AI Silence Remover") as iface: |
| |
| gr.HTML('<div class="deepu-brand">✨ Made by Deepu ✨</div>') |
| |
| gr.Markdown("<h1 style='text-align: center;'>🎙️ AI Silence Remover (Extreme Mode 🔥)</h1>") |
| gr.Markdown("<p style='text-align: center;'>Yeh version zero gap chhodega! Ekdum border-to-border sharp cuts ke liye.</p>") |
| |
| with gr.Row(): |
| audio_in = gr.Audio(type="filepath", label="Raw Audio Upload Karein") |
| |
| submit_btn = gr.Button("Cut Silence (Extreme)", variant="primary") |
| |
| with gr.Row(): |
| audio_out = gr.Audio(type="filepath", label="Processed Audio (Zero Gaps)") |
| |
| gr.HTML('<div class="deepu-brand">✨ Made by Deepu ✨</div>') |
| |
| submit_btn.click(fn=remove_silence, inputs=audio_in, outputs=audio_out) |
|
|
| if __name__ == "__main__": |
| iface.launch() |