ComfyUI-MusicGen-HF Introduction
ComfyUI-MusicGen-HF is a standalone collection of ComfyUI nodes for creating music with MusicGen models through Hugging Face Transformers. You can describe a sound in everyday language, generate a short audio clip, preview it, and save it in a format suited to your project.
The extension is useful when you need a musical idea for a video, a game scene, an animation, or another creative work. Beyond basic text-to-music generation, its nodes help you work with musical timing, use an existing audio clip as a starting point, repeat previews, and smooth the join between sections of audio. It supports NVIDIA GPUs through CUDA, Apple Silicon through MPS, and CPU operation when acceleration is unavailable. It does not require changes to ComfyUI’s core files.
How ComfyUI-MusicGen-HF Works
Think of a prompt as a creative brief for a musician. You describe the style, instruments, rhythm, and mood you want, then the MusicGen node produces audio based on that description. For example:
Upbeat jazz with a saxophone lead, walking bass, and light drums.
A basic workflow is:
Your description → MusicGen (Hugging Face) → Save Audio
You can build on that workflow in three ways:
- Set a musical length. The BPM Duration Calculator turns tempo and a number of beats into seconds. At 120 beats per minute, 16 beats take 8 seconds. Connect its duration output to MusicGen’s
duration_overrideinput when you want a clip planned around that timing. - Start from existing audio. Load a reference clip and connect it to MusicGen’s optional
conditioning_audioinput. The extension describes this as audio continuation: MusicGen uses the clip as a starting point for generating more music. - Shape the result after generation. Preview a clip repeatedly, set a target duration, or use a transition node to make a repeated section or change between clips sound smoother.
BPM timing gives you a useful duration target, but it does not guarantee that every generated note or drum hit will land exactly on a beat. Listen to the result before relying on it as a finished loop.
ComfyUI-MusicGen-HF Features
Create music from a description
MusicGen (Hugging Face) is the main generation node. Its controls let you balance prompt-following, variation, and clip length:
| Control | What it changes |
|---|---|
prompt | Describes the music you want. Mentioning instruments, genre, tempo, or mood gives the model more direction. |
model_size | Selects the small, medium, or large model. Larger choices generally take longer to run. |
duration | Sets the requested clip length from 1 to 30 seconds. |
guidance_scale | Controls how strongly generation follows the prompt, from 1 to 10. A higher value emphasizes your description. |
do_sample | Enables sampling for more varied results. |
temperature | Adjusts sampling randomness from 0.1 to 2.0. Higher settings can produce less predictable results. |
seed | Sets a random seed so you can revisit a generation setup. |
max_new_tokens | Limits how much audio the model generates, from 50 to 1503 tokens. Reducing it can help when a generation is too demanding. |
conditioning_audio | Accepts an optional reference clip for audio continuation. |
duration_override | Accepts a duration from another node, such as the BPM calculator. A value of 0 uses the manual duration setting. |
For an initial experiment, try a short duration and a concrete prompt such as “gentle ambient synthesizer with soft piano and no heavy drums.” Change one setting at a time so you can hear its effect.
Plan a clip around tempo
BPM Duration Calculator accepts a tempo (bpm), a number of beats, and a time_signature such as 4/4, 3/4, 6/8, or 2/4. It outputs a duration in seconds and timing information. The time signature helps describe measures; it does not change the duration calculation. The node caps long results to stay within the generation token limit and rounds durations to approximately 0.02-second token boundaries.
BPM Duration Calculator → MusicGen duration_override → Save Audio
For example, set bpm to 120 and beats to 16 to request an 8-second clip. This is useful when sketching music for a timed scene or planning a repeated phrase.
Preview and repeat audio
Looping Audio Preview helps you hear how a clip feels when repeated. Set loop_count from 1 to 10, turn playback on or off with enable_preview, and use queue_mode when you want new audio to wait for the current preview to finish. Its conditioning_audio output also passes the input audio along to MusicGen.
Give separate preview nodes distinct instance_id values if you are working with several clips. Higher loop counts create more repeated audio and can use more memory.
Smooth transitions and adjust duration
Smooth Audio Queue processes audio for timed playback and transitions. Its target_duration setting can trim or pad audio to a requested length; 0 keeps the original duration. Set crossfade_duration between 0 and 2 seconds to blend transitions, and use separate queue_id values for independent streams. Its conditioning_audio output retains the original input for a MusicGen continuation workflow.
A crossfade is like gradually lowering one clip while raising the next. A longer fade may suit sustained sounds, while a shorter fade may preserve the impact of a quick rhythmic change.
Professional Loop Transition offers additional controls for repeated music:
| Setting | When it may help |
|---|---|
beat_match | Align a transition to beats in rhythmic music. |
phrase_match | Work toward a transition at a musical phrase boundary. |
zero_cross | Look for waveform points that can make a cut less noticeable. |
power_match | Balance differing audio levels before a crossfade. |
transition_beats | Set the transition length in beats, from 0.25 to 8. |
crossfade_curve | Choose how the blend changes over time: linear, equal_power, exponential, or s_curve. |
auto_normalize | Balance audio levels automatically. |
dc_offset_removal | Reduce waveform bias that can contribute to clicks. |
phase_align | Align waveforms to help reduce cancellation during a transition. |
Set bpm to match the audio’s actual tempo when using beat-based transitions. Distinct loop_id values keep independent transition chains separate. These tools can improve a join, but the best settings depend on what you hear in the source audio.
Load, save, and export audio
Load Audio File brings an existing clip into a workflow for preview, processing, or conditioning. Save MusicGen Audio (Legacy) provides a simpler saving option.
Save Audio (WAV/FLAC/MP3/Opus) offers several export choices:
| Format | Available options | A useful choice when… |
|---|---|---|
| WAV | Uncompressed | You want an uncompressed file for further editing. |
| FLAC | Lossless | You want to retain audio quality in a smaller file than WAV. |
| MP3 | 128k, 192k, 320k, V0 | You need a widely compatible compressed file. |
| Opus | 64k, 96k, 128k, 192k, 320k | You want a compact file in a modern audio format. |
ComfyUI-MusicGen-HF Models
The MusicGen node offers three model sizes. Start with small to explore prompts, then try a larger model when you want to compare the results and have time and memory available.
| Model | Approximate size listed by the author | What to expect |
|---|---|---|
| Small | 1.5 GB | The fastest option and a practical starting point for experiments. |
| Medium | 3.3 GB | A quality-focused option that takes longer to generate. |
| Large | 3.3 GB | The author’s highest-quality option and the slowest to generate. |
Model size, duration, and your computer’s available resources all affect the experience. The first use of a model downloads it to the Hugging Face cache; later uses can load the cached copy.
What's New with ComfyUI-MusicGen-HF
The version history supplied by the author lists these releases:
- v1.1.0: Added the BPM Duration Calculator, Looping Audio Preview, and Smooth Audio Queue. MusicGen also gained a duration override and improved conditioning support. Together, these changes make it easier to plan clips by beats, audition repetitions, and build longer audio workflows.
- v1.0.0: Introduced text-to-music generation, audio loading and conditioning, export to WAV/FLAC/MP3/Opus, and CUDA/MPS/CPU device support.
The supplied version history does not identify when every currently documented node, including Professional Loop Transition, was added.
Troubleshooting ComfyUI-MusicGen-HF
The model takes a long time to start
- Check your internet connection if this is the first time you have selected that model.
- Allow time for its download to finish. The author says model files are cached in
~/.cache/huggingface/for subsequent use. - Try the small model first to establish that generation works.
Generation runs out of memory or feels too slow
- Select the small model.
- Request a shorter
durationand reducemax_new_tokens. - Lower preview
loop_countif you are repeating audio. - Simplify a workflow with several simultaneous audio-processing nodes.
The author recommends at least 8 GB of RAM, with 12 GB or more for smoother queue processing. A GPU is optional, but can accelerate generation.
An Apple Silicon Mac reports an MPS error
The author states that the node falls back to CPU when MPS fails. If you are diagnosing the problem, check that the Mac meets the stated macOS 12.3+ and PyTorch 2.0+ requirements. CPU generation may be slower.
A BPM-based clip is shorter than expected
- Check the
bpmandbeatsvalues. At 120 BPM, 16 beats equal 8 seconds. - Check whether the calculated request exceeds the node’s generation limit; the author says it is capped at approximately 30.06 seconds.
- Remember that the calculator rounds to approximately 0.02-second token boundaries.
- Do not change the time signature expecting it to change the duration; it affects measure information instead.
A preview will not loop or a queue behaves unexpectedly
- Set
loop_countabove 1 and check thatenable_previewis on. - Give each independent Looping Audio Preview node a unique
instance_id. - Give independent Smooth Audio Queue streams different
queue_idvalues. - Reduce loop counts if previewing becomes memory-intensive.
A loop clicks, sounds choppy, or changes volume
- Confirm that the transition node’s
bpmmatches the source audio if you are using beat-based processing. - For a choppy join, try a longer
transition_beatsvalue orzero_cross. - For a volume jump, try
power_matchandauto_normalize. - For a hollow-sounding blend, try
phase_alignwith anequal_powercurve. - For clicks or other artifacts, try
dc_offset_removalor ans_curvecrossfade. In Smooth Audio Queue, shortencrossfade_durationif the source clip is very short.
No troubleshooting screenshots or videos are included in the supplied documentation.
Frequently asked questions
Do I need a GPU?
No. The extension supports CPU operation. It can also use CUDA on supported NVIDIA GPUs or MPS on supported Apple Silicon Macs.
Can I continue a piece of music I already have?
Yes. Load the clip with Load Audio File and connect it to MusicGen’s conditioning_audio input. Listen to the result to judge how well the continuation fits.
Can I make a perfectly seamless loop just by setting a BPM?
BPM controls a duration target, not the exact placement of notes. Preview the repetition and use a transition node if the join needs work.
Why does a longer preview use more memory?
The preview node creates repeated audio for the requested number of loops. Try a lower loop_count when resources are limited.
Which export format should I choose?
Use WAV or FLAC when preserving audio for further work matters most. Choose MP3 for broad compatibility, or Opus when a compact modern format suits your destination.
Learn More about ComfyUI-MusicGen-HF
- ComfyUI: Explore the visual workflow environment in which the extension’s nodes connect.
- Hugging Face MusicGen small model: Read about one of the MusicGen models used for generation.
- MusicGen research paper: Learn more about the research behind MusicGen when you are ready for a technical explanation.
For hands-on learning, begin with MusicGen → Save Audio. Then add the BPM calculator to plan a clip’s length, or add a preview node to hear how the result repeats.
