Nodes/Story JSON Nodes/MusicGen Audio (local music)
ComfyUI Node

MusicGen Audio (local music)

Background music for the final cut, generated locally

By stepan-bogatorjov·Created 5 months ago·Updated about a month ago· 0
MusicGen Audio (local music)
    • AUDIO
    • duration_seconds
    promptwarm cinematic lo-fi piano, soft strings, gentle heartbeat, calm bedtime story mood
    duration_seconds15.0
    modelfacebook/musicgen-small
    guidance_scale3.0
    temperature1.00
    top_k250
    seed0
    fade_out_seconds1.5
    keep_model_loadedfalse
    prompt_override

    MusicGenAudio is the local music-maker in the Story JSON Nodes pack (stepan-bogatorjov/comfy_scenes_json_node): a prompt goes in, an AUDIO track comes out, generated by Meta's MusicGen on your own GPU. It's the counterpart to KokoroSceneAudio - one gives you narration, this gives you the background bed - and together they mean the final cut can have a full soundtrack with no API key and no licensing drama.

    The ecosystem context is worth knowing before you judge it. This KB's audio essay names ACE-Step as the current open "local Suno", with ACE-Step 1.5 running on 4GB cards at "quality approaching Suno v4.5/v5" - MusicGen is the older sibling that pack ecosystem largely moved past for song-level generation, but it's still a perfectly reasonable choice for what this node does: a short, instrumental, text-described music bed under a voiceover, where nobody's going to scrutinize the arrangement. Instrumental generation is where MusicGen has always been decent, and that's precisely this use case. The default prompt - "warm cinematic lo-fi piano, soft strings, gentle heartbeat, calm bedtime story mood" - tells you exactly what the author tuned it for.

    How it works

    It uses Hugging Face transformers (MusicgenForConditionalGeneration) in fp16 on CUDA. MusicGen trains on 30-second windows, so anything longer is produced by audio-prompted continuation: generate a window, feed its tail back as the audio prompt, keep only the newly generated part, repeat until the requested length. Sampling is controlled by guidance scale (how hard to follow the prompt), temperature and top_k, with a seed for reproducibility. fade_out_seconds ramps the end down so the music doesn't click into the next track, and the whole thing is peak-normalized. keep_model_loaded decides whether the weights stay resident between scenes or get unloaded so your video-gen VRAM comes back.

    The inputs that matter

    • prompt - the music description. Get specific about mood and instruments.
    • duration_seconds - 1–300. This is also an output, so you know exactly how long the track ended up.
    • model - musicgen-small (300M, ~1GB VRAM, fastest), musicgen-medium (1.5B, ~3.5GB, better musicality), or the stereo variants.
    • guidance_scale / temperature / top_k - the sampling dials; defaults are sane, nudge guidance up if it's ignoring the prompt.
    • seed - 0 randomizes; set one to reproduce a track.
    • keep_model_loaded - off by default, which is right on an 8GB laptop card that also has to render video.
    • prompt_override - optional, so a per-scene music cue can arrive from the story JSON and win over the node's prompt.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/stepan-bogatorjov/comfy_scenes_json_node
    

    Then install transformers into ComfyUI's Python (the same python_embeded gotcha as Kokoro):

    # Windows portable:
    ComfyUI\python_embeded\python.exe -m pip install transformers
    

    First run downloads the chosen weights from Hugging Face - musicgen-medium is over a gigabyte, so budget for it.

    Troubleshooting

    First run feels broken because it's downloading; watch the console, not the frozen progress bar. On a shared GPU, remember the model is fp16 on CUDA but falls back to fp32 on CPU - which is much slower and heavier, so prefer CUDA if you have any GPU at all. And the keep_model_loaded tradeoff is real: leaving it on speeds up multi-scene runs but holds VRAM that video generation wants back - that's why the default is off. Wire the AUDIO output into SaveAudioPassthrough (a music prefix helps), then point StoryFinalCompile's music_folder at it, and it becomes the track under the final cut.

    Categoryaudio

    Inputs (10)

    NameTypeDefaultDescription
    promptSTRINGwarm cinematic lo-fi piano, soft strings, gentle heartbeat, calm bedtime story mood
    duration_secondsFLOAT15.01–300
    modelCOMBOfacebook/musicgen-small4 options: facebook/musicgen-small, facebook/musicgen-medium, facebook/musicgen-stereo-small, facebook/musicgen-stereo-medium
    guidance_scaleFLOAT3.01–10
    temperatureFLOAT1.000.1–2
    top_kINT2500–1000
    seedINT00–4294967295
    fade_out_secondsFLOAT1.50–10
    keep_model_loadedBOOLEANfalse
    prompt_overrideoptSTRING

    Outputs (2)

    NameTypeDescription
    AUDIOAUDIO
    duration_secondsFLOAT