Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
7 |
-
descriptions = ['dog barking', 'sirene of an emergency vehicle', 'footsteps in a corridor']
|
8 |
-
wav = model.generate(descriptions) # generates 3 samples.
|
9 |
β
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|