DEV Community

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

Posted on

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

MusicGen Stereo
https://medium.com/r/?url=https%3A%2F%2Fhuggingface.co%2Ffacebook%2Fmusicgen-stereo-medium

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

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

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay