Hendrik Schroeter commited on
Commit
e7bb95d
1 Parent(s): aa8350e

Fix default

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -18,7 +18,7 @@ from df.enhance import enhance, init_df, load_audio, save_audio
18
  from df.utils import resample
19
 
20
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
21
- model, df, _ = init_df()
22
  model = model.to(device=device).eval()
23
 
24
 
@@ -41,6 +41,7 @@ def mix_at_snr(clean, noise, snr, eps=1e-10):
41
  if noise.shape[1] < clean.shape[1]:
42
  noise = noise.repeat((1, int(math.ceil(clean.shape[1] / noise.shape[1]))))
43
  max_start = int(noise.shape[1] - clean.shape[1])
 
44
  start = torch.randint(0, max_start, ()).item()
45
  logger.debug(f"start: {start}, {clean.shape}")
46
  noise = noise[:, start : start + clean.shape[1]]
@@ -64,7 +65,7 @@ def load_audio_gradio(
64
  if audio_or_file is None:
65
  return None
66
  if isinstance(audio_or_file, str):
67
- if audio_or_file.lower()=="none":
68
  return None
69
  # First try default format
70
  audio, meta = load_audio(audio_or_file, sr)
@@ -92,11 +93,10 @@ def mix_and_denoise(
92
  if noise_fn is None:
93
  noise_fn = "samples/dkitchen.wav"
94
  meta = AudioMetaData(-1, -1, -1, -1, "")
95
- if speech_upl is not None and "none" not in speech_upl:
96
- speech_file = "samples/p232_013_clean.wav"
97
- if speech_upl is not None and "none" not in speech_upl:
98
- speech_file = speech_upl
99
- speech, meta = load_audio(speech_file, sr)
100
  else:
101
  tmp = load_audio_gradio(speech_rec, sr)
102
  assert tmp is not None
 
18
  from df.utils import resample
19
 
20
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
21
+ model, df, _ = init_df(config_allow_defaults=True)
22
  model = model.to(device=device).eval()
23
 
24
 
 
41
  if noise.shape[1] < clean.shape[1]:
42
  noise = noise.repeat((1, int(math.ceil(clean.shape[1] / noise.shape[1]))))
43
  max_start = int(noise.shape[1] - clean.shape[1])
44
+ ic(max_start)
45
  start = torch.randint(0, max_start, ()).item()
46
  logger.debug(f"start: {start}, {clean.shape}")
47
  noise = noise[:, start : start + clean.shape[1]]
 
65
  if audio_or_file is None:
66
  return None
67
  if isinstance(audio_or_file, str):
68
+ if audio_or_file.lower() == "none":
69
  return None
70
  # First try default format
71
  audio, meta = load_audio(audio_or_file, sr)
 
93
  if noise_fn is None:
94
  noise_fn = "samples/dkitchen.wav"
95
  meta = AudioMetaData(-1, -1, -1, -1, "")
96
+ if speech_rec is None and speech_upl is None:
97
+ speech, meta = load_audio("samples/p232_013_clean.wav", sr)
98
+ elif speech_upl is not None:
99
+ speech, meta = load_audio(speech_upl, sr)
 
100
  else:
101
  tmp = load_audio_gradio(speech_rec, sr)
102
  assert tmp is not None