tee342 commited on
Commit
7713285
·
verified ·
1 Parent(s): 1c854fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -39
app.py CHANGED
@@ -306,24 +306,6 @@ def analyze_audio(audio_path):
306
 
307
  return stats, image
308
 
309
- # === Voiceprint Matching (Optional – requires Python 3.9) ===
310
- try:
311
- from resemblyzer import preprocess_wav, VoiceEncoder
312
-
313
- encoder = VoiceEncoder()
314
-
315
- def match_speakers(clip1, clip2):
316
- wav1 = preprocess_wav(clip1)
317
- wav2 = preprocess_wav(clip2)
318
- embed1 = encoder.embed_utterance(wav1)
319
- embed2 = encoder.embed_utterance(wav2)
320
- similarity = np.inner(embed1, embed2)
321
- return f"Speaker Match Score: {similarity:.2f}"
322
-
323
- except ImportError:
324
- def match_speakers(*args):
325
- return "⚠️ Speaker matching requires Python 3.9 or below"
326
-
327
  # === Save/Load Project File (.aiproj) ===
328
  def save_project(audio_path, preset_name, effects):
329
  project_data = {
@@ -336,7 +318,7 @@ def save_project(audio_path, preset_name, effects):
336
  pickle.dump(project_data, f)
337
  return out_path
338
 
339
- # === VAD Detect & Trim Silence ===
340
  def detect_silence(audio_file, silence_threshold=-50.0, min_silence_len=1000):
341
  audio = AudioSegment.from_file(audio_file)
342
 
@@ -371,11 +353,10 @@ def load_plugin(plugin_file, audio_file):
371
  plugin = module_from_spec(spec)
372
  spec.loader.exec_module(plugin)
373
 
374
- # Run the plugin
375
  audio = AudioSegment.from_file(audio_file)
376
  processed = plugin.process(audio)
377
 
378
- # Save output
379
  out_path = os.path.join(tempfile.gettempdir(), "plugin_output.wav")
380
  processed.export(out_path, format="wav")
381
  return out_path
@@ -482,7 +463,10 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
482
  description="Type anything and turn it into natural-sounding speech."
483
  )
484
 
485
- # --- Speaker Matching (Voiceprint) ===
 
 
 
486
  with gr.Tab("🧏‍♂️ Match Speakers"):
487
  gr.Interface(
488
  fn=match_speakers,
@@ -495,21 +479,15 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
495
  description="Detect speaker similarity using AI."
496
  )
497
 
498
- # --- Voice Cloning (Dummy) ===
499
- with gr.Tab("🎭 Voice Cloning (AI Dubbing)"):
500
- gr.Interface(
501
- fn=apply_style_transfer,
502
- inputs=[
503
- gr.Audio(label="Upload Voice Clip", type="filepath"),
504
- gr.Radio(["Happy", "Sad", "Angry", "Calm"], label="Choose Tone")
505
- ],
506
- outputs=gr.Audio(label="Stylized Output", type="filepath"),
507
- title="Change Emotional Tone of Voice",
508
- description="Shift the emotional style of any voice clip."
509
- )
510
-
511
  # --- Auto-Save Sessions ===
512
- with gr.Tab("🧾 Shareable Preset"):
 
 
 
 
 
 
 
513
  gr.Interface(
514
  fn=encode_preset,
515
  inputs=[
@@ -522,7 +500,7 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
522
  description="Generate a link to share your effect chain with others."
523
  )
524
 
525
- # --- VAD – Trim Silence Automatically ===
526
  with gr.Tab("✂️ Trim Silence Automatically"):
527
  gr.Interface(
528
  fn=detect_silence,
@@ -533,7 +511,7 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
533
  ],
534
  outputs=gr.File(label="Trimmed Output"),
535
  title="Auto-Detect & Remove Silence",
536
- description="Detect and trim silence at start/end or between words"
537
  )
538
 
539
  # --- Load/Save Project ===
@@ -565,7 +543,7 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
565
  )
566
 
567
  # --- Custom Effect Plugin System ===
568
- with gr.Tab("🧩 Custom Effect Plugin"):
569
  gr.Interface(
570
  fn=load_plugin,
571
  inputs=[
 
306
 
307
  return stats, image
308
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
  # === Save/Load Project File (.aiproj) ===
310
  def save_project(audio_path, preset_name, effects):
311
  project_data = {
 
318
  pickle.dump(project_data, f)
319
  return out_path
320
 
321
+ # === Trim Silence Automatically (VAD) ===
322
  def detect_silence(audio_file, silence_threshold=-50.0, min_silence_len=1000):
323
  audio = AudioSegment.from_file(audio_file)
324
 
 
353
  plugin = module_from_spec(spec)
354
  spec.loader.exec_module(plugin)
355
 
356
+ # Run plugin
357
  audio = AudioSegment.from_file(audio_file)
358
  processed = plugin.process(audio)
359
 
 
360
  out_path = os.path.join(tempfile.gettempdir(), "plugin_output.wav")
361
  processed.export(out_path, format="wav")
362
  return out_path
 
463
  description="Type anything and turn it into natural-sounding speech."
464
  )
465
 
466
+ # --- Speaker Matching (Dummy) ===
467
+ def match_speakers(*args):
468
+ return "⚠️ Speaker matching requires Python 3.9 or below"
469
+
470
  with gr.Tab("🧏‍♂️ Match Speakers"):
471
  gr.Interface(
472
  fn=match_speakers,
 
479
  description="Detect speaker similarity using AI."
480
  )
481
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
  # --- Auto-Save Sessions ===
483
+ def encode_preset(selected_effects, preset_name, export_format):
484
+ import base64
485
+ import json
486
+ data = {"effects": selected_effects, "preset": preset_name, "format": export_format}
487
+ encoded = base64.b64encode(json.dumps(data).encode()).decode()
488
+ return f"https://your-space-url?preset={encoded}"
489
+
490
+ with gr.Tab("🧾 Share Session"):
491
  gr.Interface(
492
  fn=encode_preset,
493
  inputs=[
 
500
  description="Generate a link to share your effect chain with others."
501
  )
502
 
503
+ # --- VAD – Detect & Remove Silence ===
504
  with gr.Tab("✂️ Trim Silence Automatically"):
505
  gr.Interface(
506
  fn=detect_silence,
 
511
  ],
512
  outputs=gr.File(label="Trimmed Output"),
513
  title="Auto-Detect & Remove Silence",
514
+ description="Trim intros/outs or between speech automatically"
515
  )
516
 
517
  # --- Load/Save Project ===
 
543
  )
544
 
545
  # --- Custom Effect Plugin System ===
546
+ with gr.Tab("🧩 Load Custom Effect"):
547
  gr.Interface(
548
  fn=load_plugin,
549
  inputs=[