Prof-Reza commited on
Commit
3ad5ec8
1 Parent(s): 309dc60

Create app.py

Browse files

creating app.py

Files changed (1) hide show
  1. app.py +13 -0
app.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 8 seconds.
7
+ wav = model.generate_unconditional(4) # generates 4 unconditional audio samples
8
+ descriptions = ['dog barking', 'sirenes of an emergency vehicule', 'footsteps in a corridor']
9
+ wav = model.generate(descriptions) # generates 3 samples.
10
+
11
+ for idx, one_wav in enumerate(wav):
12
+ # Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
13
+ audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)