ongudidan commited on
Commit
974a4a4
·
verified ·
1 Parent(s): cb1e8bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -14
app.py CHANGED
@@ -103,31 +103,18 @@ def load_audio_gradio(
103
  return audio, meta
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
-
114
-
115
  def demo_fn(speech_upl: str, noise_type: str, snr: int, mic_input: Optional[str] = None):
116
  if mic_input:
117
  speech_upl = mic_input
118
-
119
  sr = config("sr", 48000, int, section="df")
120
  logger.info(f"Got parameters speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}")
121
  snr = int(snr)
122
  noise_fn = NOISES[noise_type]
123
  meta = AudioMetaData(-1, -1, -1, -1, "")
124
 
125
- max_s = 3600 # allow up to 1 hour (3600 seconds)
126
 
127
  if speech_upl is not None:
128
- # ✅ Ensure compatible WAV input
129
- speech_upl = ensure_wav(speech_upl)
130
-
131
  sample, meta = load_audio(speech_upl, sr)
132
  max_len = max_s * sr
133
  if sample.shape[-1] > max_len:
@@ -180,6 +167,7 @@ def demo_fn(speech_upl: str, noise_type: str, snr: int, mic_input: Optional[str]
180
 
181
  return noisy_wav, noisy_im, enhanced_wav, enh_im
182
 
 
183
  def specshow(
184
  spec,
185
  ax=None,
 
103
  return audio, meta
104
 
105
 
 
 
 
 
 
 
 
 
 
106
  def demo_fn(speech_upl: str, noise_type: str, snr: int, mic_input: Optional[str] = None):
107
  if mic_input:
108
  speech_upl = mic_input
 
109
  sr = config("sr", 48000, int, section="df")
110
  logger.info(f"Got parameters speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}")
111
  snr = int(snr)
112
  noise_fn = NOISES[noise_type]
113
  meta = AudioMetaData(-1, -1, -1, -1, "")
114
 
115
+ max_s = 3600 # allow up to 1 hour
116
 
117
  if speech_upl is not None:
 
 
 
118
  sample, meta = load_audio(speech_upl, sr)
119
  max_len = max_s * sr
120
  if sample.shape[-1] > max_len:
 
167
 
168
  return noisy_wav, noisy_im, enhanced_wav, enh_im
169
 
170
+
171
  def specshow(
172
  spec,
173
  ax=None,