Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import librosa
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
import subprocess
|
| 6 |
+
import uuid
|
| 7 |
+
|
| 8 |
+
OUTPUT_DIR = "segments"
|
| 9 |
+
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 10 |
+
|
| 11 |
+
def process_vocal(file):
|
| 12 |
+
filename = file.name
|
| 13 |
+
y, sr = librosa.load(filename, sr=32000, mono=True)
|
| 14 |
+
intervals = librosa.effects.split(y, top_db=25)
|
| 15 |
+
|
| 16 |
+
segment_paths = []
|
| 17 |
+
for i, (start, end) in enumerate(intervals):
|
| 18 |
+
clip = y[start:end]
|
| 19 |
+
if len(clip) / sr < 0.5 or len(clip) / sr > 6.0:
|
| 20 |
+
continue
|
| 21 |
+
out_path = os.path.join(OUTPUT_DIR, f"clip_{i}.wav")
|
| 22 |
+
sf.write(out_path, clip, sr)
|
| 23 |
+
segment_paths.append(out_path)
|
| 24 |
+
|
| 25 |
+
zipname = f"vocals_{uuid.uuid4().hex[:8]}.zip"
|
| 26 |
+
subprocess.run(["zip", "-j", zipname] + segment_paths)
|
| 27 |
+
return zipname
|
| 28 |
+
|
| 29 |
+
gr.Interface(
|
| 30 |
+
fn=process_vocal,
|
| 31 |
+
inputs=gr.Audio(type="file"),
|
| 32 |
+
outputs=gr.File(label="Download ZIP"),
|
| 33 |
+
title="VocalPrep AI",
|
| 34 |
+
description="Upload a vocal-only WAV file. This tool removes silence, splits usable clips, and gives you a training-ready ZIP."
|
| 35 |
+
).launch()
|