DEV Community

Cover image for Run MusicGen-stereo on Google Colab (Free-tier)

Posted on

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

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 the music you want to generate

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

res = model.generate(prompts, 
display_audio(res, 32000)
Enter fullscreen mode Exit fullscreen mode

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")
Enter fullscreen mode Exit fullscreen mode

The following is what I generated. Both of prompts were generated by ChatGPT๐Ÿ˜

Cosmic Rhythm

Fusion Flow

Top comments (0)