tee342 commited on
Commit
b9afa4a
Β·
verified Β·
1 Parent(s): 2977c96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -8
app.py CHANGED
@@ -23,6 +23,9 @@ import base64
23
  import pickle
24
  import json
25
  import soundfile as sf
 
 
 
26
 
27
  # Suppress warnings
28
  warnings.filterwarnings("ignore")
@@ -549,7 +552,7 @@ def clone_voice(source_audio, reference_audio):
549
  mixed.export(out_path, format="wav")
550
  return out_path
551
 
552
- # === AI Remastering – Now Fixed! ===
553
  def ai_remaster(audio_path):
554
  try:
555
  audio = AudioSegment.from_file(audio_path)
@@ -559,14 +562,82 @@ def ai_remaster(audio_path):
559
  cleaned_wav_path = os.path.join(tempfile.gettempdir(), "cleaned.wav")
560
  cleaned.export(cleaned_wav_path, format="wav")
561
  isolated_path = apply_vocal_isolation(cleaned_wav_path)
562
- final_audio = AudioSegment.from_wav(isolated_path)
563
- final_path = os.path.join(tempfile.gettempdir(), "remastered_output.wav")
564
- final_audio.export(final_path, format="wav")
565
  return final_path
566
  except Exception as e:
567
  print(f"Remastering Error: {str(e)}")
568
  return None
569
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
570
  # === Main UI – With Studio Pulse Branding ===
571
  with gr.Blocks(css="""
572
  body {
@@ -917,6 +988,7 @@ with gr.Blocks(css="""
917
  "Reverb",
918
  "Auto Gain",
919
  "Vocal Distortion",
 
920
  "Stage Mode"
921
  ]),
922
  gr.Checkbox(label="Isolate Vocals After Effects"),
@@ -982,7 +1054,7 @@ with gr.Blocks(css="""
982
  ],
983
  outputs=gr.Audio(label="Stretched Output", type="filepath"),
984
  title="Match Track to BPM",
985
- description="Stretch audio to match a specific tempo"
986
  )
987
 
988
  # --- A/B Compare ===
@@ -1042,11 +1114,14 @@ with gr.Blocks(css="""
1042
  ### Keyboard Controls
1043
  - `Ctrl + Z`: Undo last effect
1044
  - `Ctrl + Y`: Redo
1045
- - `Spacebar`: Play/Stop playback
1046
- - `Ctrl + S`: Save current session
1047
  - `Ctrl + O`: Open session
1048
  - `Ctrl + C`: Copy effect chain
1049
  - `Ctrl + V`: Paste effect chain
 
 
 
1050
  """)
1051
 
1052
  # --- Vocal Formant Correction – Now Defined! ===
@@ -1059,7 +1134,7 @@ with gr.Blocks(css="""
1059
  ],
1060
  outputs=gr.Audio(label="Natural-Sounding Vocal", type="filepath"),
1061
  title="Preserve Vocal Quality During Pitch Shift",
1062
- description="Make pitch-shifted vocals sound more human"
1063
  )
1064
 
1065
  # --- Voice Swap / Cloning – New Tab ===
@@ -1096,4 +1171,35 @@ with gr.Blocks(css="""
1096
  description="Perfect for sharing with producers or archiving"
1097
  )
1098
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1099
  demo.launch()
 
23
  import pickle
24
  import json
25
  import soundfile as sf
26
+ import wave
27
+ import struct
28
+ from moviepy.editor import VideoFileClip, AudioFileClip
29
 
30
  # Suppress warnings
31
  warnings.filterwarnings("ignore")
 
552
  mixed.export(out_path, format="wav")
553
  return out_path
554
 
555
+ # === AI Remastering – Now Working! ===
556
  def ai_remaster(audio_path):
557
  try:
558
  audio = AudioSegment.from_file(audio_path)
 
562
  cleaned_wav_path = os.path.join(tempfile.gettempdir(), "cleaned.wav")
563
  cleaned.export(cleaned_wav_path, format="wav")
564
  isolated_path = apply_vocal_isolation(cleaned_wav_path)
565
+ final_path = ai_mastering_chain(isolated_path, genre="Pop", target_lufs=-14.0)
 
 
566
  return final_path
567
  except Exception as e:
568
  print(f"Remastering Error: {str(e)}")
569
  return None
570
 
571
+ def ai_mastering_chain(audio_path, genre="Pop", target_lufs=-14.0):
572
+ audio = AudioSegment.from_file(audio_path)
573
+ audio = auto_eq(audio, genre=genre)
574
+ audio = match_loudness(audio_path, target_lufs=target_lufs)
575
+ audio = apply_stereo_widen(audio, pan_amount=0.3)
576
+ out_path = os.path.join(tempfile.gettempdir(), "mastered_output.wav")
577
+ audio.export(out_path, format="wav")
578
+ return out_path
579
+
580
+ # === Generate PDF Report ===
581
+ from fpdf import FPDF
582
+
583
+ class PDFReport(FPDF):
584
+ def header(self):
585
+ self.set_font('Arial', 'B', 12)
586
+ self.cell(0, 10, 'Studio Pulse AI - Session Report', ln=True, align='C')
587
+
588
+ def export_session_report(session_data):
589
+ pdf = PDFReport()
590
+ pdf.add_page()
591
+ pdf.set_font("Arial", size=10)
592
+ pdf.multi_cell(0, 10, txt=session_data)
593
+ out_path = os.path.join(tempfile.gettempdir(), "session_report.pdf")
594
+ pdf.output(out_path)
595
+ return out_path
596
+
597
+ # === Video Sync Mode – Extract and re-sync audio ===
598
+ def extract_audio_from_video(video_path):
599
+ clip = VideoFileClip(video_path)
600
+ out_path = os.path.join(tempfile.gettempdir(), "video_audio.wav")
601
+ clip.audio.write_audiofile(out_path)
602
+ return out_path
603
+
604
+ def re_sync_audio(video_path, edited_audio_path):
605
+ original_clip = VideoFileClip(video_path)
606
+ edited_audio = AudioSegment.from_file(edited_audio_path)
607
+ temp_audio_path = os.path.join(tempfile.gettempdir(), "temp_edited.mp3")
608
+ edited_audio.export(temp_audio_path, format="mp3")
609
+ final_clip = original_clip.set_audio(temp_audio_path)
610
+ out_path = os.path.join(tempfile.gettempdir(), "final_video.mp4")
611
+ final_clip.write_videofile(out_path, codec="libx264", audio_codec="aac")
612
+ return out_path
613
+
614
+ # === Sidechain Compression / Ducking ===
615
+ def sidechain_ducking(background, voice, threshold=-16, ratio=4):
616
+ bg_samples, bg_sr = audiosegment_to_array(background)
617
+ voice_samples, v_sr = audiosegment_to_array(voice)
618
+ if bg_sr != v_sr:
619
+ voice_samples = librosa.resample(voice_samples, orig_sr=v_sr, target_sr=bg_sr)
620
+ bg_rms = np.sqrt(np.mean(bg_samples ** 2))
621
+ voice_rms = np.sqrt(np.mean(voice_samples ** 2))
622
+ if voice_rms > bg_rms * threshold / 100:
623
+ bg_samples = bg_samples * ratio
624
+ return array_to_audiosegment(bg_samples.astype(np.int16), bg_sr, channels=background.channels)
625
+
626
+ # === Effect Chains Marketplace ===
627
+ def publish_effect_chain(chain_json, name, tags):
628
+ chain_id = base64.b64encode(chain_json.encode()).decode()
629
+ return {
630
+ "id": chain_id,
631
+ "name": name,
632
+ "tags": tags
633
+ }
634
+
635
+ def search_effect_chains(query):
636
+ return [
637
+ {"name": "Radio Ready", "tags": ["loudness", "bass", "treble"]},
638
+ {"name": "Clean Vocal", "tags": ["noise", "normalize"]}
639
+ ]
640
+
641
  # === Main UI – With Studio Pulse Branding ===
642
  with gr.Blocks(css="""
643
  body {
 
988
  "Reverb",
989
  "Auto Gain",
990
  "Vocal Distortion",
991
+ "Harmony",
992
  "Stage Mode"
993
  ]),
994
  gr.Checkbox(label="Isolate Vocals After Effects"),
 
1054
  ],
1055
  outputs=gr.Audio(label="Stretched Output", type="filepath"),
1056
  title="Match Track to BPM",
1057
+ description="Stretch or shrink audio to match a specific tempo"
1058
  )
1059
 
1060
  # --- A/B Compare ===
 
1114
  ### Keyboard Controls
1115
  - `Ctrl + Z`: Undo last effect
1116
  - `Ctrl + Y`: Redo
1117
+ - `Spacebar`: Play/Stop
1118
+ - `Ctrl + S`: Save session
1119
  - `Ctrl + O`: Open session
1120
  - `Ctrl + C`: Copy effect chain
1121
  - `Ctrl + V`: Paste effect chain
1122
+ - `Ctrl + Shift + L`: Loop selection
1123
+ - `Ctrl + Shift + P`: Export PDF report
1124
+ - `Ctrl + Shift + M`: Export full mix ZIP
1125
  """)
1126
 
1127
  # --- Vocal Formant Correction – Now Defined! ===
 
1134
  ],
1135
  outputs=gr.Audio(label="Natural-Sounding Vocal", type="filepath"),
1136
  title="Preserve Vocal Quality During Pitch Shift",
1137
+ description="Make pitch-shifted vocals sound more natural"
1138
  )
1139
 
1140
  # --- Voice Swap / Cloning – New Tab ===
 
1171
  description="Perfect for sharing with producers or archiving"
1172
  )
1173
 
1174
+ # --- Session Report Export (PDF) ===
1175
+ with gr.Tab("πŸ“„ Session Report"):
1176
+ gr.Interface(
1177
+ fn=export_session_report,
1178
+ inputs=gr.Textbox(label="Session Data (JSON)", lines=10),
1179
+ outputs=gr.File(label="Download PDF Report"),
1180
+ title="Export Detailed Session Report",
1181
+ description="For professional use or sharing with collaborators"
1182
+ )
1183
+
1184
+ # --- Effect Chains Marketplace – New Tab ===
1185
+ with gr.Tab("🧩 Effect Chain Marketplace"):
1186
+ gr.Interface(
1187
+ fn=publish_effect_chain,
1188
+ inputs=[
1189
+ gr.Textbox(label="Effect Chain (JSON)", lines=2),
1190
+ gr.Textbox(label="Name", value="My Chain"),
1191
+ gr.CheckboxGroup(choices=["music", "vocals", "podcast", "radio", "edm"], label="Tags")
1192
+ ],
1193
+ outputs=gr.JSON(label="Published Chain Info"),
1194
+ title="Publish Your Effect Chain",
1195
+ description="Share your setup with others"
1196
+ )
1197
+
1198
+ with gr.Tab("🧩 Search Chains"):
1199
+ gr.Interface(
1200
+ fn=search_effect_chains,
1201
+ inputs=gr.Textbox(label="Search Query", value="vocal"),
1202
+ outputs=gr.JSON(label="Matching Chains")
1203
+ )
1204
+
1205
  demo.launch()