Run MusicGen-stereo on Google Colab (Free-tier)

Nov 18, 2023

MusicGen Stereo

Run MusicGen on Google Colab T4

# install packages
!python3 -m pip install -U git+

# import packages
from audiocraft.models import musicgen
from audiocraft.utils.notebook import display_audio
import torch

# generate music
# in this case, we'll try to generate a couple of music
prompts = ['futuristic rock music', 'futuristic jazz music'] # describe music you want to generate

model = musicgen.MusicGen.get_pretrained('facebook/musicgen-stereo-medium')

res = model.generate(prompts,
display_audio(res, 32000)

export music as a wav file.

from import audio_write

for idx, one_wav in enumerate(res):
audio_write(f'generated_music_{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness")

The following is what I generated. Both of prompts were generated by ChatGPT😁

Cosmic Rhythm

Fusion Flow




software engineer works for a Biotechnology Research startup in Brooklyn. #CreativeCoding #Art #IoT #MachineLearning #python #typescript #javascript #reactjs