AudioGenStarter / app.py
Prof-Reza's picture
Update app.py
ba4a9c6
raw
history blame contribute delete
885 Bytes
import gradio as gr
import torchaudio
from audiocraft.models import AudioGen
from audiocraft.data.audio import audio_write
iface = gr.Interface(fn=audioGen, inputs="text", outputs="text")
iface.launch()
def audioGen(audioPrompt):
model = AudioGen.get_pretrained('facebook/audiogen-medium')
model.set_generation_params(duration=5) # generate 8 seconds.
wav = model.generate_unconditional(4) # generates 4 unconditional audio samples
descriptions = ['dog barking', 'sirenes of an emergency vehicule', 'footsteps in a corridor']
wav = model.generate(descriptions) # generates 3 samples.
for idx, one_wav in enumerate(wav):
# Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)
return "Hello " + audioPrompt + "!!"