import gradio as gr import os import librosa import soundfile as sf import subprocess import uuid OUTPUT_DIR = "segments" os.makedirs(OUTPUT_DIR, exist_ok=True) def process_vocal(file): filename = file.name y, sr = librosa.load(filename, sr=32000, mono=True) intervals = librosa.effects.split(y, top_db=25) segment_paths = [] for i, (start, end) in enumerate(intervals): clip = y[start:end] if len(clip) / sr < 0.5 or len(clip) / sr > 6.0: continue out_path = os.path.join(OUTPUT_DIR, f"clip_{i}.wav") sf.write(out_path, clip, sr) segment_paths.append(out_path) zipname = f"vocals_{uuid.uuid4().hex[:8]}.zip" subprocess.run(["zip", "-j", zipname] + segment_paths) return zipname gr.Interface( fn=process_vocal, inputs=gr.Audio(type="file"), outputs=gr.File(label="Download ZIP"), title="VocalPrep AI", description="Upload a vocal-only WAV file. This tool removes silence, splits usable clips, and gives you a training-ready ZIP." ).launch()