Hendrik Schroeter commited on
Commit
f9a20e8
1 Parent(s): 039a05e
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -108,15 +108,20 @@ def demo_fn(
108
  )
109
  noise_fn = NOISES[noise_type]
110
  meta = AudioMetaData(-1, -1, -1, -1, "")
 
111
  if speech_rec is None and speech_upl is None:
112
  sample, meta = load_audio("samples/p232_013_clean.wav", sr)
113
  elif speech_upl is not None:
114
  sample, meta = load_audio(speech_upl, sr)
 
 
 
 
115
  else:
116
  tmp = load_audio_gradio(speech_rec, sr)
117
  assert tmp is not None
118
  sample, meta = tmp
119
- sample = sample[..., : 10 * meta.sample_rate] # limit to 10 seconds
120
  if sample.dim() > 1 and sample.shape[0] > 1:
121
  assert (
122
  sample.shape[1] > sample.shape[2]
 
108
  )
109
  noise_fn = NOISES[noise_type]
110
  meta = AudioMetaData(-1, -1, -1, -1, "")
111
+ max_s = 10 # limit to 10 seconds
112
  if speech_rec is None and speech_upl is None:
113
  sample, meta = load_audio("samples/p232_013_clean.wav", sr)
114
  elif speech_upl is not None:
115
  sample, meta = load_audio(speech_upl, sr)
116
+ max_len = max_s * sr
117
+ if sample.shape[-1] > max_len:
118
+ start = torch.randint(0, sample.shape[-1] - max_len, ()).item()
119
+ sample = sample[..., start : start + max_len]
120
  else:
121
  tmp = load_audio_gradio(speech_rec, sr)
122
  assert tmp is not None
123
  sample, meta = tmp
124
+ sample = sample[..., : max_s * sr]
125
  if sample.dim() > 1 and sample.shape[0] > 1:
126
  assert (
127
  sample.shape[1] > sample.shape[2]