mirror of
https://github.com/hanzoai/mugen.git
synced 2026-11-03 01:48:40 +00:00
9.0 KiB
9.0 KiB
In [1]:
from audiocraft.models import MusicGen
from audiocraft.models import MultiBandDiffusion
USE_DIFFUSION_DECODER = False
model = MusicGen.get_pretrained('facebook/musicgen-style')
if USE_DIFFUSION_DECODER:
mbd = MultiBandDiffusion.get_mbd_musicgen()In [ ]:
model.set_generation_params(
use_sampling=True,
top_k=250,
duration=30
)In [ ]:
from audiocraft.utils.notebook import display_audio
model.set_generation_params(
duration=8, # generate 8 seconds, can go up to 30
use_sampling=True,
top_k=250,
cfg_coef=3., # Classifier Free Guidance coefficient
cfg_coef_beta=None, # double CFG is only useful for text-and-style conditioning
)
output = model.generate(
descriptions=[
'80s pop track with bassy drums and synth',
'90s rock song with loud guitars and heavy drums',
'Progressive rock drum and bass solo',
'Punk Rock song with loud drum and power guitar',
'Bluesy guitar instrumental with soulful licks and a driving rhythm section',
'Jazz Funk song with slap bass and powerful saxophone',
'drum and bass beat with intense percussions'
],
progress=True, return_tokens=True
)
display_audio(output[0], sample_rate=32000)
if USE_DIFFUSION_DECODER:
out_diffusion = mbd.tokens_to_wav(output[1])
display_audio(out_diffusion, sample_rate=32000)In [ ]:
import torchaudio
from audiocraft.utils.notebook import display_audio
model.set_generation_params(
duration=8, # generate 8 seconds, can go up to 30
use_sampling=True,
top_k=250,
cfg_coef=3., # Classifier Free Guidance coefficient
cfg_coef_beta=None, # double CFG is only useful for text-and-style conditioning
)
model.set_style_conditioner_params(
eval_q=1, # integer between 1 and 6
# eval_q is the level of quantization that passes
# through the conditioner. When low, the models adheres less to the
# audio conditioning
excerpt_length=3., # the length in seconds that is taken by the model in the provided excerpt
)
melody_waveform, sr = torchaudio.load("../assets/electronic.mp3")
melody_waveform = melody_waveform.unsqueeze(0).repeat(2, 1, 1)
output = model.generate_with_chroma(
descriptions=[None, None],
melody_wavs=melody_waveform,
melody_sample_rate=sr,
progress=True, return_tokens=True
)
display_audio(output[0], sample_rate=32000)
if USE_DIFFUSION_DECODER:
out_diffusion = mbd.tokens_to_wav(output[1])
display_audio(out_diffusion, sample_rate=32000)In [ ]:
import torchaudio
from audiocraft.utils.notebook import display_audio
model.set_generation_params(
duration=8, # generate 8 seconds, can go up to 30
use_sampling=True,
top_k=250,
cfg_coef=3., # Classifier Free Guidance coefficient
cfg_coef_beta=5., # double CFG is necessary for text-and-style conditioning
# Beta in the double CFG formula. between 1 and 9. When set to 1
# it is equivalent to normal CFG.
)
model.set_style_conditioner_params(
eval_q=1, # integer between 1 and 6
# eval_q is the level of quantization that passes
# through the conditioner. When low, the models adheres less to the
# audio conditioning
excerpt_length=3., # the length in seconds that is taken by the model in the provided excerpt
)
melody_waveform, sr = torchaudio.load("../assets/electronic.mp3")
melody_waveform = melody_waveform.unsqueeze(0).repeat(3, 1, 1)
descriptions = ["8-bit old video game music", "Chill lofi remix", "80s New wave with synthesizer"]
output = model.generate_with_chroma(
descriptions=descriptions,
melody_wavs=melody_waveform,
melody_sample_rate=sr,
progress=True, return_tokens=True
)
display_audio(output[0], sample_rate=32000)
if USE_DIFFUSION_DECODER:
out_diffusion = mbd.tokens_to_wav(output[1])
display_audio(out_diffusion, sample_rate=32000)