Clearwave48 commited on
Commit
d0c4c17
Β·
verified Β·
1 Parent(s): a960e11

Update denoiser.py

Browse files
Files changed (1) hide show
  1. denoiser.py +16 -15
denoiser.py CHANGED
@@ -174,7 +174,7 @@ class Denoiser:
174
  # then convert to MP3 via ffmpeg (already in the Dockerfile).
175
  tmp_wav = os.path.join(out_dir, "denoised_tmp.wav")
176
  out_path = os.path.join(out_dir, out_name)
177
- sf.write(tmp_wav, out_audio, sr, subtype="PCM_24")
178
 
179
  result = subprocess.run([
180
  "ffmpeg", "-y", "-i", tmp_wav,
@@ -324,24 +324,25 @@ class Denoiser:
324
  except Exception as e:
325
  logger.warning(f"[Denoiser] DeepFilterNet unavailable ({e})")
326
 
327
- # ── Fallback: Two-pass noisereduce (voice-preserving) ─────────────
328
- # prop_decrease kept LOW on both passes to avoid speech artifacts.
 
 
 
 
 
 
 
 
329
  try:
330
  import noisereduce as nr
331
- pass1 = nr.reduce_noise(
332
  y=audio, sr=sr,
333
  stationary=True,
334
- prop_decrease=0.65,
335
- ).astype(np.float32)
336
- pass2 = nr.reduce_noise(
337
- y=pass1, sr=sr,
338
- stationary=False,
339
- prop_decrease=0.30, # very gentle β€” voice stays natural
340
- freq_mask_smooth_hz=400,
341
- time_mask_smooth_ms=80,
342
  ).astype(np.float32)
343
- print("[Denoiser] βœ… Two-pass noisereduce done (voice-preserving)")
344
- return pass2, "noisereduce_2pass"
345
  except Exception as e:
346
  logger.warning(f"noisereduce failed: {e}")
347
 
@@ -710,7 +711,7 @@ class Denoiser:
710
  logger.warning(f"ffmpeg non-zero exit: {stderr[-400:]}")
711
  # Fallback: soundfile passthrough
712
  data, sr = sf.read(src, always_2d=True)
713
- sf.write(dst, data, sr, subtype="PCM_24")
714
 
715
  def _resample(self, audio: np.ndarray, orig_sr: int, target_sr: int) -> np.ndarray:
716
  if orig_sr == target_sr:
 
174
  # then convert to MP3 via ffmpeg (already in the Dockerfile).
175
  tmp_wav = os.path.join(out_dir, "denoised_tmp.wav")
176
  out_path = os.path.join(out_dir, out_name)
177
+ sf.write(tmp_wav, out_audio, sr, format="WAV", subtype="PCM_24")
178
 
179
  result = subprocess.run([
180
  "ffmpeg", "-y", "-i", tmp_wav,
 
324
  except Exception as e:
325
  logger.warning(f"[Denoiser] DeepFilterNet unavailable ({e})")
326
 
327
+ # ── Fallback: Single-pass noisereduce, stationary only ────────────
328
+ # PHILOSOPHY: do as little as possible to the signal.
329
+ # - stationary=True β†’ only targets steady/consistent noise (fan,
330
+ # hum, AC, room hiss). Leaves transient
331
+ # speech harmonics completely untouched.
332
+ # - prop_decrease=0.5 β†’ reduces noise by ~50%, not 100%.
333
+ # Keeps a thin noise floor so the voice
334
+ # never sounds "hollow" or over-processed.
335
+ # - No second pass, no non-stationary processing β€” those modes
336
+ # touch voice frequencies and cause the robotic effect.
337
  try:
338
  import noisereduce as nr
339
+ cleaned = nr.reduce_noise(
340
  y=audio, sr=sr,
341
  stationary=True,
342
+ prop_decrease=0.50,
 
 
 
 
 
 
 
343
  ).astype(np.float32)
344
+ print("[Denoiser] βœ… noisereduce done (voice-preserving, stationary only)")
345
+ return cleaned, "noisereduce_stationary"
346
  except Exception as e:
347
  logger.warning(f"noisereduce failed: {e}")
348
 
 
711
  logger.warning(f"ffmpeg non-zero exit: {stderr[-400:]}")
712
  # Fallback: soundfile passthrough
713
  data, sr = sf.read(src, always_2d=True)
714
+ sf.write(dst, data, sr, format="WAV", subtype="PCM_24")
715
 
716
  def _resample(self, audio: np.ndarray, orig_sr: int, target_sr: int) -> np.ndarray:
717
  if orig_sr == target_sr: