-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathgenerate_manual.py
More file actions
33 lines (25 loc) · 805 Bytes
/
Copy pathgenerate_manual.py
File metadata and controls
33 lines (25 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import torchaudio
import time
from audiocraft.models.musicgen import MusicGen
from audiocraft.data.audio import audio_write
from prompts import PROMPTS
MODEL_NAME = "facebook/musicgen-large"
MUSIC_DURATION_SECONDS = 60
print("obtaining model...")
model = MusicGen.get_pretrained(MODEL_NAME)
model.set_generation_params(duration=MUSIC_DURATION_SECONDS)
print("model obtained. generating audio...")
a = time.time()
wav = model.generate(PROMPTS)
b = time.time()
print(f"audio generated. took {b - a} seconds.")
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,
format="mp3",
strategy="loudness",
loudness_compressor=True,
)