Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pip install gradio librosa
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import librosa
|
| 5 |
+
import numpy as np
|
| 6 |
+
from pydub import AudioSegment
|
| 7 |
+
|
| 8 |
+
# Function to synchronize vocal and beat
|
| 9 |
+
def synchronize_audio(vocal_file, beat_file):
|
| 10 |
+
# Load audio files
|
| 11 |
+
vocal_audio = AudioSegment.from_file(vocal_file, format="mp3")
|
| 12 |
+
beat_audio, sr = librosa.load(beat_file, sr=None)
|
| 13 |
+
|
| 14 |
+
# Convert vocal audio to numpy array
|
| 15 |
+
vocal_array = np.array(vocal_audio.get_array_of_samples())
|
| 16 |
+
|
| 17 |
+
# Resize beat to match vocal duration
|
| 18 |
+
beat_duration = len(vocal_array) / vocal_audio.frame_rate
|
| 19 |
+
beat_resized = librosa.effects.trim(beat_audio, duration=beat_duration)[0]
|
| 20 |
+
|
| 21 |
+
# Combine vocal and beat
|
| 22 |
+
synchronized_audio = vocal_array + beat_resized
|
| 23 |
+
|
| 24 |
+
return synchronized_audio
|
| 25 |
+
|
| 26 |
+
# Gradio Interface
|
| 27 |
+
iface = gr.Interface(
|
| 28 |
+
fn=synchronize_audio,
|
| 29 |
+
inputs=[
|
| 30 |
+
gr.File("Vocal File", type="audio", accept=".mp3"),
|
| 31 |
+
gr.File("Beat File", type="audio", accept=".mp3"),
|
| 32 |
+
],
|
| 33 |
+
outputs="audio",
|
| 34 |
+
live=True,
|
| 35 |
+
title="Audio Synchronization",
|
| 36 |
+
description="Upload a vocal file and a beat to synchronize them.",
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
# Launch Gradio interface
|
| 40 |
+
iface.launch()
|