Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| import librosa | |
| import soundfile as sf | |
| import uuid | |
| import zipfile | |
| OUTPUT_DIR = "segments" | |
| os.makedirs(OUTPUT_DIR, exist_ok=True) | |
| def process_vocal(file): | |
| # file is already a string path because of type="filepath" | |
| y, sr = librosa.load(file, 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" | |
| with zipfile.ZipFile(zipname, 'w') as zipf: | |
| for path in segment_paths: | |
| zipf.write(path, os.path.basename(path)) | |
| return zipname | |
| gr.Interface( | |
| fn=process_vocal, | |
| inputs=gr.Audio(type="filepath"), | |
| 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() |