Plasmati commited on
Commit
19fe9e7
·
verified ·
1 Parent(s): 25bf40b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -26
app.py CHANGED
@@ -3,40 +3,27 @@ import subprocess
3
  subprocess.run(["pip", "install", "-r", "requirements.txt"])
4
 
5
  import gradio as gr
6
- import librosa
7
- import numpy as np
8
  from pydub import AudioSegment
9
 
10
- # Function to synchronize vocal and beat
11
  def synchronize_audio(vocal_file, beat_file):
12
- # Load audio files
13
- vocal_audio = AudioSegment.from_file(vocal_file.name, format="mp3")
14
- beat_audio, sr = librosa.load(beat_file.name, sr=None)
15
 
16
- # Convert vocal audio to numpy array
17
- vocal_array = np.array(vocal_audio.get_array_of_samples())
18
 
19
- # Resize beat to match vocal duration
20
- beat_duration = len(vocal_array) / vocal_audio.frame_rate
21
- beat_resized = librosa.effects.trim(beat_audio, duration=beat_duration)[0]
22
 
23
- # Combine vocal and beat
24
- synchronized_audio = vocal_array + beat_resized
25
 
26
- return synchronized_audio
27
-
28
- # Gradio Interface
29
  iface = gr.Interface(
30
- fn=synchronize_audio,
31
- inputs=[
32
- gr.File("Vocal File", type="audio", mime="audio/*"),
33
- gr.File("Beat File", type="audio", mime="audio/*"),
34
- ],
35
- outputs="audio",
36
- live=True,
37
- title="Audio Synchronization",
38
- description="Upload a vocal file and a beat to synchronize them.",
39
  )
40
 
41
- # Launch Gradio interface
42
  iface.launch()
 
3
  subprocess.run(["pip", "install", "-r", "requirements.txt"])
4
 
5
  import gradio as gr
 
 
6
  from pydub import AudioSegment
7
 
 
8
  def synchronize_audio(vocal_file, beat_file):
9
+ # Load the audio files
10
+ vocal = AudioSegment.from_file(vocal_file)
11
+ beat = AudioSegment.from_file(beat_file)
12
 
13
+ # Synchronize the audio tracks
14
+ synchronized_audio = vocal.overlay(beat)
15
 
16
+ # Export the synchronized audio
17
+ synchronized_audio.export("output_synchronized_audio.mp3", format="mp3")
 
18
 
19
+ return "Audio synchronization completed. You can download the synchronized audio."
 
20
 
21
+ # Gradio interface
 
 
22
  iface = gr.Interface(
23
+ synchronize_audio,
24
+ inputs=[gr.File("Vocal File"), gr.File("Beat File")],
25
+ outputs=gr.Textbox(),
26
+ live=True
 
 
 
 
 
27
  )
28
 
 
29
  iface.launch()