File size: 1,153 Bytes
01ac216
 
 
c17e769
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
pip install gradio
pip install librosa


import gradio as gr
import librosa
import numpy as np
from pydub import AudioSegment

# Function to synchronize vocal and beat
def synchronize_audio(vocal_file, beat_file):
    # Load audio files
    vocal_audio = AudioSegment.from_file(vocal_file, format="mp3")
    beat_audio, sr = librosa.load(beat_file, sr=None)

    # Convert vocal audio to numpy array
    vocal_array = np.array(vocal_audio.get_array_of_samples())

    # Resize beat to match vocal duration
    beat_duration = len(vocal_array) / vocal_audio.frame_rate
    beat_resized = librosa.effects.trim(beat_audio, duration=beat_duration)[0]

    # Combine vocal and beat
    synchronized_audio = vocal_array + beat_resized

    return synchronized_audio

# Gradio Interface
iface = gr.Interface(
    fn=synchronize_audio,
    inputs=[
        gr.File("Vocal File", type="audio", accept=".mp3"),
        gr.File("Beat File", type="audio", accept=".mp3"),
    ],
    outputs="audio",
    live=True,
    title="Audio Synchronization",
    description="Upload a vocal file and a beat to synchronize them.",
)

# Launch Gradio interface
iface.launch()