harp-dev commited on
Commit
91a5618
·
verified ·
1 Parent(s): 48d9793

Return audio at the format it was given

Browse files
Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -355,7 +355,14 @@ def api_vamp(input_audio,
355
 
356
  @spaces.GPU
357
  def harp_vamp(input_audio, sampletemp, periodic_p, dropout, n_mask_codebooks, model_choice, stretch_factor):
358
- sig = at.AudioSignal(input_audio).to_mono()
 
 
 
 
 
 
 
359
 
360
  input_audio = sig.cpu().detach().numpy()[0][0]
361
  input_audio = input_audio * np.iinfo(np.int16).max
@@ -386,9 +393,18 @@ def harp_vamp(input_audio, sampletemp, periodic_p, dropout, n_mask_codebooks, mo
386
  harp=True,
387
  )
388
 
 
 
 
 
 
 
 
 
 
389
  ll = LabelList()
390
  ll.append(OutputLabel(label='short label', t=0.0, description='longer description'))
391
- return save_audio(sig.detach().cpu()), ll
392
 
393
 
394
  if __name__ == "__main__":
@@ -797,14 +813,19 @@ if __name__ == "__main__":
797
  name="VampNet",
798
  description=(
799
  (
800
- "Generates new audio by remixing and extending your input, filling in the "
801
- "blanks to create a coherent continuation in the same style. Available "
802
- "models include: cat10: fine-tuned on expressive cat sounds; "
 
803
  "lazaro-ros-sep: percussion extracted from the Lázaro Ros discography, "
804
- "rich in Afro-Cuban rhythm supermetroid: trained on Super Metroid (SNES) "
805
- "gameplay audio for retro, game-style soundscapes. Repository: "
 
 
 
806
  "https://github.com/hugofloresgarcia/vampnet Paper: "
807
  "https://arxiv.org/abs/2307.04686"
 
808
  )
809
  ),
810
  author="Hugo Flores Garcia, Prem Seetharaman, Rithesh Kumar, Bryan Pardo",
 
355
 
356
  @spaces.GPU
357
  def harp_vamp(input_audio, sampletemp, periodic_p, dropout, n_mask_codebooks, model_choice, stretch_factor):
358
+ sig = at.AudioSignal(input_audio)
359
+
360
+ # Captured before the downmix, because generation runs in mono at VampNet's
361
+ # own rate and both have to be put back afterwards
362
+ original_sr = sig.sample_rate
363
+ original_channels = sig.num_channels
364
+
365
+ sig = sig.to_mono()
366
 
367
  input_audio = sig.cpu().detach().numpy()[0][0]
368
  input_audio = input_audio * np.iinfo(np.int16).max
 
393
  harp=True,
394
  )
395
 
396
+ sig = sig.detach().cpu()
397
+
398
+ if sig.sample_rate != original_sr:
399
+ sig = sig.resample(original_sr)
400
+
401
+ # Copies of one generated channel, not a stereo image, which the card says
402
+ if original_channels > 1 and sig.num_channels == 1:
403
+ sig.audio_data = sig.audio_data.repeat(1, original_channels, 1)
404
+
405
  ll = LabelList()
406
  ll.append(OutputLabel(label='short label', t=0.0, description='longer description'))
407
+ return save_audio(sig), ll
408
 
409
 
410
  if __name__ == "__main__":
 
813
  name="VampNet",
814
  description=(
815
  (
816
+ (
817
+ "Generates new audio by remixing and extending your input, filling in "
818
+ "the blanks to create a coherent continuation in the same style. "
819
+ "Available models include: cat10: fine-tuned on expressive cat sounds; "
820
  "lazaro-ros-sep: percussion extracted from the Lázaro Ros discography, "
821
+ "rich in Afro-Cuban rhythm supermetroid: trained on Super Metroid "
822
+ "(SNES) gameplay audio for retro, game-style soundscapes. Generation "
823
+ "runs in mono at the model's own rate; the result is resampled back to "
824
+ "the input's rate and copied across its channels, so the output has the "
825
+ "format it came in with but no stereo image. Repository: "
826
  "https://github.com/hugofloresgarcia/vampnet Paper: "
827
  "https://arxiv.org/abs/2307.04686"
828
+ )
829
  )
830
  ),
831
  author="Hugo Flores Garcia, Prem Seetharaman, Rithesh Kumar, Bryan Pardo",