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

0𝕏koji
Nov 18, 2023

MusicGen Stereo

Run MusicGen on Google Colab T4

# install packages
!python3 -m pip install -U git+https://github.com/facebookresearch/audiocraft#egg=audiocraft

# 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')
model.set_generation_params(duration=60)

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

export music as a wav file.

from audiocraft.data.audio 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
https://soundcloud.com/koji-kanao/cosmic-rhythm

Fusion Flow
https://soundcloud.com/koji-kanao/fusion-flow

--

--

0𝕏koji

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