TulipAIs commited on
Commit
67781e6
1 Parent(s): e8ad7b7

updating audio gen starter code in app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,7 +1,21 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
1
  import gradio as gr
2
+ import torchaudio
3
+ from audiocraft.models import AudioGen
4
+ from audiocraft.data.audio import audio_write
5
+
6
+ model = AudioGen.get_pretrained('facebook/audiogen-medium')
7
+ model.set_generation_params(duration=5) # generate 8 seconds.
8
+ wav = model.generate_unconditional(4) # generates 4 unconditional audio samples
9
+ descriptions = ['dog barking', 'sirenes of an emergency vehicule', 'footsteps in a corridor']
10
+ wav = model.generate(descriptions) # generates 3 samples.
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
 
 
 
16
 
17
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
18
+ iface.launch()
19
+
20
+ def greet(name):
21
+ return "Hello " + name + "!!"