ongudidan commited on
Commit
d527034
·
1 Parent(s): 8871317

fix: improve format conversion robustness and align tensor shapes for dry/wet blending

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -104,10 +104,18 @@ def load_audio_gradio(
104
 
105
 
106
  def ensure_wav(filepath: str) -> str:
107
- """Convert MP3 (or other formats) to WAV using ffmpeg if needed."""
108
- if filepath.lower().endswith(".mp3"):
109
  wav_path = filepath.rsplit(".", 1)[0] + ".wav"
110
- subprocess.run(["ffmpeg", "-y", "-i", filepath, wav_path], check=True)
 
 
 
 
 
 
 
 
111
  return wav_path
112
  return filepath
113
 
@@ -161,6 +169,11 @@ def demo_fn(
161
  logger.info("Denoising finished")
162
 
163
  # Dry/wet blending: mix original 'sample' back into 'enhanced' to restore voice texture
 
 
 
 
 
164
  alpha = wet_dry_mix / 100.0
165
  enhanced = alpha * enhanced + (1 - alpha) * sample
166
 
 
104
 
105
 
106
  def ensure_wav(filepath: str) -> str:
107
+ """Convert MP3 (or other non-WAV formats) to WAV using ffmpeg if needed."""
108
+ if not filepath.lower().endswith(".wav"):
109
  wav_path = filepath.rsplit(".", 1)[0] + ".wav"
110
+ if wav_path == filepath:
111
+ wav_path = filepath + ".wav"
112
+ # Run ffmpeg silently to convert the format
113
+ subprocess.run(
114
+ ["ffmpeg", "-y", "-i", filepath, wav_path],
115
+ check=True,
116
+ stdout=subprocess.DEVNULL,
117
+ stderr=subprocess.DEVNULL
118
+ )
119
  return wav_path
120
  return filepath
121
 
 
169
  logger.info("Denoising finished")
170
 
171
  # Dry/wet blending: mix original 'sample' back into 'enhanced' to restore voice texture
172
+ # Ensure both tensors have the exact same shape (DeepFilterNet can output a slightly different length due to STFT framing)
173
+ min_len = min(enhanced.shape[-1], sample.shape[-1])
174
+ enhanced = enhanced[..., :min_len]
175
+ sample = sample[..., :min_len]
176
+
177
  alpha = wet_dry_mix / 100.0
178
  enhanced = alpha * enhanced + (1 - alpha) * sample
179