Gertie01 commited on
Commit
c4d0a5f
β€’
1 Parent(s): 3df4b51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -1,12 +1,22 @@
1
  import torchaudio
2
  from audiocraft.models import AudioGen
3
  from audiocraft.data.audio import audio_write
 
4
  ​
5
  model = AudioGen.get_pretrained('facebook/audiogen-medium')
6
- model.set_generation_params(duration=5) # generate 5 seconds.
7
- descriptions = ['dog barking', 'sirene of an emergency vehicle', 'footsteps in a corridor']
8
- wav = model.generate(descriptions) # generates 3 samples.
9
  ​
10
- for idx, one_wav in enumerate(wav):
11
- # Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
12
- audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)
 
 
 
 
 
 
 
 
 
 
 
 
1
  import torchaudio
2
  from audiocraft.models import AudioGen
3
  from audiocraft.data.audio import audio_write
4
+ import argparse
5
  ​
6
  model = AudioGen.get_pretrained('facebook/audiogen-medium')
7
+ model.set_generation_params(duration=5) # generate [duration] seconds.
 
 
8
  ​
9
+ def generate_audio(descriptions):
10
+ wav = model.generate(descriptions) # generates samples for all descriptions in array.
11
+
12
+ for idx, one_wav in enumerate(wav):
13
+ # Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
14
+ audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)
15
+ print(f'Generated {idx}th sample.')
16
+ ​
17
+ if __name__ == "__main__":
18
+ parser = argparse.ArgumentParser(description="Generate audio based on descriptions.")
19
+ parser.add_argument("descriptions", nargs='+', help="List of descriptions for audio generation")
20
+ args = parser.parse_args()
21
+
22
+ generate_audio(args.descriptions)