Spaces:
Runtime error
Runtime error
Create merge_audio.py
Browse files- merge_audio.py +15 -0
merge_audio.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydub import AudioSegment
|
| 2 |
+
|
| 3 |
+
def merge_audio_tracks(vocal_path, music_path, output_path="final_song.wav"):
|
| 4 |
+
vocals = AudioSegment.from_file(vocal_path)
|
| 5 |
+
music = AudioSegment.from_file(music_path)
|
| 6 |
+
|
| 7 |
+
# Trim or loop to match lengths
|
| 8 |
+
if len(vocals) > len(music):
|
| 9 |
+
vocals = vocals[:len(music)]
|
| 10 |
+
else:
|
| 11 |
+
music = music[:len(vocals)]
|
| 12 |
+
|
| 13 |
+
final = music.overlay(vocals - 3) # reduce vocals a bit
|
| 14 |
+
final.export(output_path, format="wav")
|
| 15 |
+
return output_path
|