harp-dev commited on
Commit
0cbd892
·
verified ·
1 Parent(s): 64e5bb6

Return the result at the input's rate and channel count, and pin cqt_nsgt_pytorch

Browse files

It was written mono at the checkpoint's rate (22.05 or 44.1 kHz). The model card says the channels are copies.

Files changed (2) hide show
  1. app.py +14 -5
  2. requirements.txt +1 -1
app.py CHANGED
@@ -255,9 +255,9 @@ def inpaint(input_audio_path, checkpoint_choice, gap_length_s, gap_position_s, s
255
  sample_rate = ckpt_cfg["sample_rate"]
256
  audio_len = ckpt_cfg["audio_len"]
257
 
258
- audio_np, sr_in = sf.read(input_audio_path, dtype="float32", always_2d=False)
259
- if audio_np.ndim > 1:
260
- audio_np = audio_np.mean(axis=-1) # the model is mono-only
261
  audio = torch.from_numpy(audio_np).unsqueeze(0).to(DEVICE)
262
 
263
  segment = prepare_segment(audio, sr_in, sample_rate, audio_len)
@@ -272,9 +272,15 @@ def inpaint(input_audio_path, checkpoint_choice, gap_length_s, gap_position_s, s
272
  y_masked = segment * mask
273
  pred = sampler.predict_inpainting(y_masked, mask)
274
 
 
 
 
 
 
 
275
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
276
  out_path = f.name
277
- sf.write(out_path, pred.squeeze(0).cpu().numpy(), sample_rate)
278
  return out_path
279
 
280
 
@@ -285,7 +291,10 @@ model_card = ModelCard(
285
  "solo piano (MAESTRO) or mixed classical instrumentation (MusicNet). "
286
  "The input is resampled to the chosen model's rate and center-cropped "
287
  "or zero-padded to its fixed segment length (about 8.4s for MAESTRO, "
288
- "4.2s for MusicNet) before the gap is filled. Repository: "
 
 
 
289
  "https://github.com/eloimoliner/audio-inpainting-diffusion Paper: "
290
  "https://arxiv.org/abs/2305.15266"
291
  ),
 
255
  sample_rate = ckpt_cfg["sample_rate"]
256
  audio_len = ckpt_cfg["audio_len"]
257
 
258
+ audio_np, sr_in = sf.read(input_audio_path, dtype="float32", always_2d=True)
259
+ input_channels = audio_np.shape[1]
260
+ audio_np = audio_np.mean(axis=-1) # the model is mono-only
261
  audio = torch.from_numpy(audio_np).unsqueeze(0).to(DEVICE)
262
 
263
  segment = prepare_segment(audio, sr_in, sample_rate, audio_len)
 
272
  y_masked = segment * mask
273
  pred = sampler.predict_inpainting(y_masked, mask)
274
 
275
+ # Returned at the input's rate, with the mono result copied across the input's channels
276
+ pred = pred.squeeze(0).detach()
277
+ if sr_in != sample_rate:
278
+ pred = torchaudio.functional.resample(pred, sample_rate, sr_in)
279
+ out = pred.cpu().numpy()[:, None].repeat(input_channels, axis=1)
280
+
281
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
282
  out_path = f.name
283
+ sf.write(out_path, out, sr_in)
284
  return out_path
285
 
286
 
 
291
  "solo piano (MAESTRO) or mixed classical instrumentation (MusicNet). "
292
  "The input is resampled to the chosen model's rate and center-cropped "
293
  "or zero-padded to its fixed segment length (about 8.4s for MAESTRO, "
294
+ "4.2s for MusicNet) before the gap is filled. The models are "
295
+ "fixed-rate and mono, so the result is resampled back to the input's "
296
+ "rate and copied across its channels: the output has the format it "
297
+ "came in with, but no stereo image. Repository: "
298
  "https://github.com/eloimoliner/audio-inpainting-diffusion Paper: "
299
  "https://arxiv.org/abs/2305.15266"
300
  ),
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  git+https://github.com/TEAMuP-dev/pyharp.git@v0.4.2
2
- cqt_nsgt_pytorch
3
  einops
4
  torch
5
  torchaudio
 
1
  git+https://github.com/TEAMuP-dev/pyharp.git@v0.4.2
2
+ cqt_nsgt_pytorch==0.0.10
3
  einops
4
  torch
5
  torchaudio