ongudidan commited on
Commit
9c7885d
·
1 Parent(s): c580565

refactor: simplify UI parameters by replacing complex EQ sliders with denoising strength and vocal polish toggle

Browse files
Files changed (1) hide show
  1. app.py +31 -58
app.py CHANGED
@@ -182,25 +182,29 @@ def demo_fn(
182
  speech_upl: str,
183
  noise_type: str,
184
  snr: int,
185
- atten_lim_db: float,
186
- wet_dry_mix: float,
187
- post_process: bool,
188
- low_cut_freq: float,
189
- bass_gain: float,
190
- treble_gain: float,
191
- gate_threshold: float,
192
- enable_warmth: bool,
193
  mic_input: Optional[str] = None,
194
  ):
195
  if input_type == "mic":
196
  speech_upl = mic_input
197
 
198
  sr = config("sr", 48000, int, section="df")
199
- logger.info(f"Got parameters input_type: {input_type}, speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}, atten_lim_db: {atten_lim_db}, wet_dry_mix: {wet_dry_mix}, post_process: {post_process}, low_cut: {low_cut_freq}, bass: {bass_gain}, treble: {treble_gain}, gate: {gate_threshold}, warmth: {enable_warmth}")
200
  snr = int(snr)
201
  noise_fn = NOISES[noise_type]
202
  meta = AudioMetaData(-1, -1, -1, -1, "")
203
 
 
 
 
 
 
 
 
 
 
 
204
  max_s = 3600 # allow up to 1 hour (3600 seconds)
205
 
206
  if speech_upl is not None:
@@ -242,9 +246,17 @@ def demo_fn(
242
  alpha = wet_dry_mix / 100.0
243
  enhanced = alpha * enhanced + (1 - alpha) * sample
244
 
245
- # Apply professional post-processing (Low-cut filter + bass EQ + treble EQ + gate + warmth)
246
- if post_process:
247
- enhanced = post_process_audio(enhanced, sr, low_cut_freq, bass_gain, treble_gain, gate_threshold, enable_warmth)
 
 
 
 
 
 
 
 
248
 
249
  lim = torch.linspace(0.0, 1.0, int(sr * 0.15)).unsqueeze(0)
250
  lim = torch.cat((lim, torch.ones(1, enhanced.shape[-1] - lim.shape[1])), dim=1)
@@ -425,53 +437,14 @@ with gr.Blocks() as demo:
425
  value="10",
426
  ),
427
  gr.Slider(
428
- minimum=6,
429
- maximum=35,
430
- step=1,
431
- value=15,
432
- label="Max Attenuation (dB) - lower is more natural/clear, higher reduces more noise",
433
- ),
434
- gr.Slider(
435
- minimum=50,
436
  maximum=100,
437
  step=5,
438
- value=90,
439
- label="Voice Naturalness Mix (%) - 100% is fully denoised, 90% blends back some original voice",
440
- ),
441
- gr.Checkbox(
442
- label="Enable Post-Processing EQ & Filters",
443
- value=True,
444
- ),
445
- gr.Slider(
446
- minimum=20,
447
- maximum=200,
448
- step=10,
449
  value=80,
450
- label="Low-Cut Filter Cutoff (Hz) - cuts muddy AC rumble/handling noise",
451
- ),
452
- gr.Slider(
453
- minimum=-10,
454
- maximum=10,
455
- step=1,
456
- value=0,
457
- label="Voice Bass EQ Boost (dB) at 150Hz - adds warmth",
458
- ),
459
- gr.Slider(
460
- minimum=-10,
461
- maximum=10,
462
- step=1,
463
- value=3,
464
- label="Voice Treble EQ Boost (dB) at 6kHz - adds crispness/air",
465
- ),
466
- gr.Slider(
467
- minimum=-60,
468
- maximum=-30,
469
- step=5,
470
- value=-45,
471
- label="Noise Gate Threshold (dB) - lower keeps quiet sound, higher silences gaps",
472
  ),
473
  gr.Checkbox(
474
- label="Enable Analog Warmth (Soft Saturation)",
475
  value=True,
476
  ),
477
  mic_input,
@@ -490,10 +463,10 @@ with gr.Blocks() as demo:
490
  radio.change(toggle, radio, [mic_input, audio_file])
491
  gr.Examples(
492
  [
493
- ["file", "./samples/p232_013_clean.wav", "Kitchen", "10", 15, 90, True, 80, 0, 3, -45, True, None],
494
- ["file", "./samples/p232_013_clean.wav", "Cafe", "10", 15, 90, True, 80, 0, 3, -45, True, None],
495
- ["file", "./samples/p232_019_clean.wav", "Cafe", "10", 15, 90, True, 80, 0, 3, -45, True, None],
496
- ["file", "./samples/p232_019_clean.wav", "River", "10", 15, 90, True, 80, 0, 3, -45, True, None],
497
  ],
498
  fn=demo_fn,
499
  inputs=inputs,
 
182
  speech_upl: str,
183
  noise_type: str,
184
  snr: int,
185
+ denoising_strength: float,
186
+ vocal_polish: bool,
 
 
 
 
 
 
187
  mic_input: Optional[str] = None,
188
  ):
189
  if input_type == "mic":
190
  speech_upl = mic_input
191
 
192
  sr = config("sr", 48000, int, section="df")
193
+ logger.info(f"Got parameters input_type: {input_type}, speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}, strength: {denoising_strength}, polish: {vocal_polish}")
194
  snr = int(snr)
195
  noise_fn = NOISES[noise_type]
196
  meta = AudioMetaData(-1, -1, -1, -1, "")
197
 
198
+ # Map the simple 0-100% denoising strength to advanced model parameters
199
+ if denoising_strength == 0:
200
+ atten_lim_db = 0.0
201
+ wet_dry_mix = 0.0
202
+ else:
203
+ # Interpolate maximum attenuation between 6dB and 30dB
204
+ atten_lim_db = 6.0 + (denoising_strength / 100.0) * 24.0
205
+ # Interpolate dry/wet mix between 50% and 100%
206
+ wet_dry_mix = 50.0 + (denoising_strength / 100.0) * 50.0
207
+
208
  max_s = 3600 # allow up to 1 hour (3600 seconds)
209
 
210
  if speech_upl is not None:
 
246
  alpha = wet_dry_mix / 100.0
247
  enhanced = alpha * enhanced + (1 - alpha) * sample
248
 
249
+ # Apply professional post-processing (Low-cut filter + bass EQ + treble EQ + gate + warmth) using optimized studio defaults
250
+ if vocal_polish:
251
+ enhanced = post_process_audio(
252
+ enhanced,
253
+ sr,
254
+ low_cut_freq=80.0,
255
+ bass_gain=0.0,
256
+ treble_gain=3.0,
257
+ gate_threshold=-45.0,
258
+ enable_warmth=True
259
+ )
260
 
261
  lim = torch.linspace(0.0, 1.0, int(sr * 0.15)).unsqueeze(0)
262
  lim = torch.cat((lim, torch.ones(1, enhanced.shape[-1] - lim.shape[1])), dim=1)
 
437
  value="10",
438
  ),
439
  gr.Slider(
440
+ minimum=0,
 
 
 
 
 
 
 
441
  maximum=100,
442
  step=5,
 
 
 
 
 
 
 
 
 
 
 
443
  value=80,
444
+ label="Denoising Strength (%) - higher removes more noise, lower is more natural",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  ),
446
  gr.Checkbox(
447
+ label="Vocal Polish (80Hz Low-Cut, Treble EQ & Analog Warmth)",
448
  value=True,
449
  ),
450
  mic_input,
 
463
  radio.change(toggle, radio, [mic_input, audio_file])
464
  gr.Examples(
465
  [
466
+ ["file", "./samples/p232_013_clean.wav", "Kitchen", "10", 80, True, None],
467
+ ["file", "./samples/p232_013_clean.wav", "Cafe", "10", 80, True, None],
468
+ ["file", "./samples/p232_019_clean.wav", "Cafe", "10", 80, True, None],
469
+ ["file", "./samples/p232_019_clean.wav", "River", "10", 80, True, None],
470
  ],
471
  fn=demo_fn,
472
  inputs=inputs,