Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,8 @@ import base64
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Suppress warnings
|
| 28 |
warnings.filterwarnings("ignore")
|
|
@@ -526,7 +528,7 @@ def formant_correct(audio, shift=1.0):
|
|
| 526 |
corrected = librosa.effects.pitch_shift(samples, sr=sr, n_steps=shift)
|
| 527 |
return array_to_audiosegment(corrected.astype(np.int16), sr, channels=audio.channels)
|
| 528 |
|
| 529 |
-
# === DAW Template Export
|
| 530 |
def generate_ableton_template(stems):
|
| 531 |
template = {
|
| 532 |
"format": "Ableton Live",
|
|
@@ -556,7 +558,17 @@ def text_to_sound(prompt):
|
|
| 556 |
tts.tts_to_file(text=prompt, speaker="p225", file_path=out_path)
|
| 557 |
return out_path
|
| 558 |
|
| 559 |
-
# ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 560 |
def extract_audio_from_video(video_path):
|
| 561 |
clip = VideoFileClip(video_path)
|
| 562 |
out_path = os.path.join(tempfile.gettempdir(), "video_audio.wav")
|
|
@@ -761,7 +773,7 @@ with gr.Blocks(css="""
|
|
| 761 |
output_other = gr.Audio(label="Processed Other", type="filepath")
|
| 762 |
btn_other.click(fn=apply_effects_to_stem, inputs=[other_path, other_effects], outputs=output_other)
|
| 763 |
|
| 764 |
-
# --- AI Remastering Tab โ
|
| 765 |
with gr.Tab("๐ฎ AI Remastering"):
|
| 766 |
gr.Interface(
|
| 767 |
fn=ai_remaster,
|
|
@@ -782,8 +794,7 @@ with gr.Blocks(css="""
|
|
| 782 |
],
|
| 783 |
outputs=gr.Audio(label="Warm Output", type="filepath"),
|
| 784 |
title="Add Analog-Style Warmth",
|
| 785 |
-
description="Enhance clarity and presence using saturation styles like Tube or Tape."
|
| 786 |
-
allow_flagging="never"
|
| 787 |
)
|
| 788 |
|
| 789 |
# --- Vocal Doubler / Harmonizer โ Added ===
|
|
@@ -989,7 +1000,7 @@ with gr.Blocks(css="""
|
|
| 989 |
],
|
| 990 |
outputs=gr.Audio(label="Stretched Output", type="filepath"),
|
| 991 |
title="Match Track to BPM",
|
| 992 |
-
description="Stretch
|
| 993 |
)
|
| 994 |
|
| 995 |
# --- A/B Compare ===
|
|
@@ -1005,7 +1016,8 @@ with gr.Blocks(css="""
|
|
| 1005 |
gr.Audio(label="Version B", type="filepath")
|
| 1006 |
],
|
| 1007 |
title="Compare Two Versions",
|
| 1008 |
-
description="Hear two mixes side-by-side"
|
|
|
|
| 1009 |
)
|
| 1010 |
|
| 1011 |
# --- Loop Section ===
|
|
@@ -1053,8 +1065,6 @@ with gr.Blocks(css="""
|
|
| 1053 |
- `Ctrl + O`: Open session
|
| 1054 |
- `Ctrl + C`: Copy effect chain
|
| 1055 |
- `Ctrl + V`: Paste effect chain
|
| 1056 |
-
- `Ctrl + Shift + L`: Loop selection
|
| 1057 |
-
- `Ctrl + Shift + M`: Export full mix ZIP
|
| 1058 |
""")
|
| 1059 |
|
| 1060 |
# --- Vocal Formant Correction โ Now Defined! ===
|
|
@@ -1070,7 +1080,20 @@ with gr.Blocks(css="""
|
|
| 1070 |
description="Make pitch-shifted vocals sound more human"
|
| 1071 |
)
|
| 1072 |
|
| 1073 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1074 |
with gr.Tab("๐ DAW Template Export"):
|
| 1075 |
gr.Interface(
|
| 1076 |
fn=generate_ableton_template,
|
|
@@ -1078,7 +1101,7 @@ with gr.Blocks(css="""
|
|
| 1078 |
outputs=gr.File(label="DAW Template (.json/.als/.flp)")
|
| 1079 |
)
|
| 1080 |
|
| 1081 |
-
# --- Export Full Mix ZIP ===
|
| 1082 |
with gr.Tab("๐ Export Full Mix ZIP"):
|
| 1083 |
gr.Interface(
|
| 1084 |
fn=export_full_mix,
|
|
@@ -1101,4 +1124,26 @@ with gr.Blocks(css="""
|
|
| 1101 |
description="Describe a sound โ AI generates it"
|
| 1102 |
)
|
| 1103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1104 |
demo.launch()
|
|
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
| 26 |
+
import wave
|
| 27 |
+
import struct
|
| 28 |
|
| 29 |
# Suppress warnings
|
| 30 |
warnings.filterwarnings("ignore")
|
|
|
|
| 528 |
corrected = librosa.effects.pitch_shift(samples, sr=sr, n_steps=shift)
|
| 529 |
return array_to_audiosegment(corrected.astype(np.int16), sr, channels=audio.channels)
|
| 530 |
|
| 531 |
+
# === DAW Template Export ===
|
| 532 |
def generate_ableton_template(stems):
|
| 533 |
template = {
|
| 534 |
"format": "Ableton Live",
|
|
|
|
| 558 |
tts.tts_to_file(text=prompt, speaker="p225", file_path=out_path)
|
| 559 |
return out_path
|
| 560 |
|
| 561 |
+
# === Voice Cloning via OpenVoice (Simulated) ===
|
| 562 |
+
def clone_voice(source_audio, reference_audio):
|
| 563 |
+
# Simulate voice swap
|
| 564 |
+
source = AudioSegment.from_file(source_audio)
|
| 565 |
+
ref = AudioSegment.from_file(reference_audio)
|
| 566 |
+
mixed = source.overlay(ref - 10)
|
| 567 |
+
out_path = os.path.join(tempfile.gettempdir(), "cloned_output.wav")
|
| 568 |
+
mixed.export(out_path, format="wav")
|
| 569 |
+
return out_path
|
| 570 |
+
|
| 571 |
+
# === Video Sync Mode โ Extract and re-sync audio ===
|
| 572 |
def extract_audio_from_video(video_path):
|
| 573 |
clip = VideoFileClip(video_path)
|
| 574 |
out_path = os.path.join(tempfile.gettempdir(), "video_audio.wav")
|
|
|
|
| 773 |
output_other = gr.Audio(label="Processed Other", type="filepath")
|
| 774 |
btn_other.click(fn=apply_effects_to_stem, inputs=[other_path, other_effects], outputs=output_other)
|
| 775 |
|
| 776 |
+
# --- AI Remastering Tab โ Now Fixed & Working ===
|
| 777 |
with gr.Tab("๐ฎ AI Remastering"):
|
| 778 |
gr.Interface(
|
| 779 |
fn=ai_remaster,
|
|
|
|
| 794 |
],
|
| 795 |
outputs=gr.Audio(label="Warm Output", type="filepath"),
|
| 796 |
title="Add Analog-Style Warmth",
|
| 797 |
+
description="Enhance clarity and presence using saturation styles like Tube or Tape."
|
|
|
|
| 798 |
)
|
| 799 |
|
| 800 |
# --- Vocal Doubler / Harmonizer โ Added ===
|
|
|
|
| 1000 |
],
|
| 1001 |
outputs=gr.Audio(label="Stretched Output", type="filepath"),
|
| 1002 |
title="Match Track to BPM",
|
| 1003 |
+
description="Stretch audio to match a specific tempo"
|
| 1004 |
)
|
| 1005 |
|
| 1006 |
# --- A/B Compare ===
|
|
|
|
| 1016 |
gr.Audio(label="Version B", type="filepath")
|
| 1017 |
],
|
| 1018 |
title="Compare Two Versions",
|
| 1019 |
+
description="Hear two mixes side-by-side",
|
| 1020 |
+
allow_flagging="never"
|
| 1021 |
)
|
| 1022 |
|
| 1023 |
# --- Loop Section ===
|
|
|
|
| 1065 |
- `Ctrl + O`: Open session
|
| 1066 |
- `Ctrl + C`: Copy effect chain
|
| 1067 |
- `Ctrl + V`: Paste effect chain
|
|
|
|
|
|
|
| 1068 |
""")
|
| 1069 |
|
| 1070 |
# --- Vocal Formant Correction โ Now Defined! ===
|
|
|
|
| 1080 |
description="Make pitch-shifted vocals sound more human"
|
| 1081 |
)
|
| 1082 |
|
| 1083 |
+
# --- Voice Swap / Cloning โ New Tab ===
|
| 1084 |
+
with gr.Tab("๐ Voice Swap / Cloning"):
|
| 1085 |
+
gr.Interface(
|
| 1086 |
+
fn=clone_voice,
|
| 1087 |
+
inputs=[
|
| 1088 |
+
gr.File(label="Source Voice Clip"),
|
| 1089 |
+
gr.File(label="Reference Voice")
|
| 1090 |
+
],
|
| 1091 |
+
outputs=gr.Audio(label="Converted Output", type="filepath"),
|
| 1092 |
+
title="Swap Voices Using AI",
|
| 1093 |
+
description="Clone or convert voice from one to another"
|
| 1094 |
+
)
|
| 1095 |
+
|
| 1096 |
+
# --- DAW Template Export โ Now Included ===
|
| 1097 |
with gr.Tab("๐ DAW Template Export"):
|
| 1098 |
gr.Interface(
|
| 1099 |
fn=generate_ableton_template,
|
|
|
|
| 1101 |
outputs=gr.File(label="DAW Template (.json/.als/.flp)")
|
| 1102 |
)
|
| 1103 |
|
| 1104 |
+
# --- Export Full Mix ZIP โ Added Back ===
|
| 1105 |
with gr.Tab("๐ Export Full Mix ZIP"):
|
| 1106 |
gr.Interface(
|
| 1107 |
fn=export_full_mix,
|
|
|
|
| 1124 |
description="Describe a sound โ AI generates it"
|
| 1125 |
)
|
| 1126 |
|
| 1127 |
+
# --- Web DAW Interface โ New Feature ===
|
| 1128 |
+
with gr.Tab("๐ Web DAW"):
|
| 1129 |
+
with gr.Row():
|
| 1130 |
+
with gr.Column(min_width=300):
|
| 1131 |
+
track1 = gr.Audio(label="Track 1", type="filepath")
|
| 1132 |
+
vol1 = gr.Slider(minimum=0, maximum=1, value=1, label="Volume 1")
|
| 1133 |
+
pan1 = gr.Slider(minimum=-1, maximum=1, value=0, label="Pan 1")
|
| 1134 |
+
fx1 = gr.CheckboxGroup(choices=["Reverb", "EQ", "Compression"], label="Effects Track 1")
|
| 1135 |
+
track2 = gr.Audio(label="Track 2", type="filepath")
|
| 1136 |
+
vol2 = gr.Slider(minimum=0, maximum=1, value=1, label="Volume 2")
|
| 1137 |
+
pan2 = gr.Slider(minimum=-1, maximum=1, value=0, label="Pan 2")
|
| 1138 |
+
fx2 = gr.CheckboxGroup(choices=["Reverb", "EQ", "Compression"], label="Effects Track 2")
|
| 1139 |
+
mix_btn = gr.Button("Mix Tracks")
|
| 1140 |
+
with gr.Column(min_width=400):
|
| 1141 |
+
timeline_img = gr.Image(label="Timeline View")
|
| 1142 |
+
final_mix = gr.Audio(label="Final Mix", type="filepath")
|
| 1143 |
+
export_zip_btn = gr.Button("Export Full Mix + Stems (.zip)")
|
| 1144 |
+
|
| 1145 |
+
mix_btn.click(fn=mix_tracks, inputs=[track1, vol1, pan1, fx1, track2, vol2, pan2, fx2], outputs=[final_mix, timeline_img])
|
| 1146 |
+
|
| 1147 |
+
export_zip_btn.click(fn=export_full_mix, inputs=[track1, track2, final_mix], outputs=gr.File(label="Download ZIP"))
|
| 1148 |
+
|
| 1149 |
demo.launch()
|