MusicGen (Meta): Open-Source Music Generation with Integration

We design and deploy artificial intelligence systems: from prototype to production-ready solutions. Our team combines expertise in machine learning, data engineering and MLOps to make AI work not in the lab, but in real business.
Showing 1 of 1All 1566 services
MusicGen (Meta): Open-Source Music Generation with Integration
Simple
~2-3 days
Frequently Asked Questions

AI Development Areas

AI Solution Development Stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1319
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1226
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    927
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1161
  • image_logo-advance_0.webp
    B2B Advance company logo design
    622
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    897

You write a prompt 'ambient with slow beat and pads' — the model outputs 30 seconds of music. MusicGen from Meta does this with zero latency. Open-source, MIT license, commercial use without royalties. The problem: most proprietary music generation solutions are either expensive or closed-source, costing up to $500/month per request. You can't control the model and pay per request. MusicGen solves this: you get full control over inference, fine-tuning, and deployment. We've already integrated it into several products: from background music generation for videos to dynamic soundtracks in games. Licensing cost savings are significant: moving away from proprietary services recovers GPU expenses within months, with savings of up to 70%.

How MusicGen Works

MusicGen is an autoregressive transformer trained on 20,000 hours of licensed music. Audio is encoded into tokens via EnCodec (32 kHz), then the model predicts the token sequence based on text or melody. Under the hood — a T5-encoder for conditioning.

In production, we use facebook/musicgen-large (3.3B parameters) or facebook/musicgen-medium (1.5B) for fast responses. The choice depends on your quality/latency requirements.

Model Parameters Time on A100 (30s) Recommendation
small 300M ~8s Fast prototypes
medium 1.5B ~12s Production balance
large 3.3B ~20s Quality first
melody 1.5B ~15s Reference generation

Problems Integrations Solve

The main issue is latency. Without optimization, generation on a high-end GPU can take up to a minute per track. We solve this through INT8 quantization and dynamic batching. The second problem is long tracks: the model is limited to 30 seconds. Chunking with overlap and crossfade allows compositions of any length without quality loss. The third problem is integration into existing stacks. We provide a ready REST API with monitoring and scaling.

Why MusicGen Is Better Than Alternatives

The MIT license allows embedding the model in commercial products without royalties. It's the only open-source model of this class that supports generation from text and melody. Alternatives like Jukebox or Riffusion are either slower or have duration and quality limitations. For example, the small version on an RTX 3090 generates 30 seconds in 45 seconds — faster than any comparable model with similar quality. You can also fine-tune the model on your data via LoRA, adapting it to a specific genre or style. Our 5+ years of AI/ML experience ensure reliable deployment.

What's Included in the Integration

We deliver a complete package for deployment and operation:

  • API and architecture documentation
  • Docker image with optimized model (INT8, batch)
  • Helm charts for Kubernetes
  • Fine-tuning scripts (LoRA) for your data
  • Monitoring via Prometheus metrics (latency, throughput)
  • 3 months of support after deployment
  • Guaranteed latency under 3 seconds for p95

How Integration Works

We don't just run the model. We account for latency, throughput, and GPU cost. The process includes:

  1. Analytics: load assessment (RPS) and target latency (p95 < 3 seconds).
  2. Design: model selection (medium/large) and deployment scheme (CPU/GPU).
  3. Implementation: API, caching, monitoring (Prometheus + Grafana).
  4. Testing: load tests, A/B comparison against baseline.
  5. Deployment: Kubernetes Helm charts or Docker Compose + CI/CD.
Stage Duration Result
Analytics 1 day Report with loads and recommendations
Development 2-4 days REST API + optimizations
Deployment 1-2 days Production infrastructure

Example: REST API with FastAPI and Triton

from fastapi import FastAPI
from pydantic import BaseModel
import numpy as np
import tritonclient.http as triton_http

app = FastAPI()
client = triton_http.InferenceServerClient(url="triton:8000")

class GenerateRequest(BaseModel):
    prompt: str
    duration: int = 30
    cfg_scale: float = 3.0

@app.post("/generate")
async def generate(req: GenerateRequest):
    inputs = [triton_http.InferInput("TEXT", [1, 1], "BYTES")]
    inputs[0].set_data_from_numpy(np.array([req.prompt.encode()], dtype=np.object_))
    result = client.infer("musicgen_ensemble", inputs)
    audio = result.as_numpy("AUDIO")[0]
    return {"url": upload_to_s3(audio, req.prompt)}

Code: MusicGen Melody — generation by reference

melody_model = MusicGen.get_pretrained("facebook/musicgen-melody")

def generate_variation(reference_audio: bytes, style_description: str) -> bytes:
    melody_wav, sr = torchaudio.load(io.BytesIO(reference_audio))
    melody_model.set_generation_params(duration=30)
    wav = melody_model.generate_with_chroma(
        descriptions=[style_description],
        melody_wavs=melody_wav.unsqueeze(0),
        melody_sample_rate=sr,
        progress=True
    )
    buf = io.BytesIO()
    torchaudio.save(buf, wav[0].cpu(), sample_rate=32000, format="mp3")
    return buf.getvalue()

Prompts by Genre

MUSICGEN_STYLE_PROMPTS = {
    "corporate": "uplifting corporate background, piano, strings, positive mood, no drums",
    "lofi": "lofi hip hop, relaxing, vinyl crackle, mellow piano, slow beat",
    "epic": "epic orchestral, cinematic, strings, brass, powerful drums, intense",
    "ambient": "ambient electronic, atmospheric, pads, soft synths, meditative",
    "jazz": "smooth jazz, saxophone, double bass, brushed drums, relaxed",
    "acoustic": "acoustic guitar, warm, folk style, fingerpicking, natural reverb",
}

Long Tracks via Chunking

def generate_long_music(description: str, total_duration: int = 120) -> bytes:
    chunk_duration = 30
    overlap = 5
    chunks = []
    model.set_generation_params(duration=chunk_duration)
    wav = model.generate([description]).cpu()
    chunks.append(wav[0])
    while sum(w.shape[-1] for w in chunks) / 32000 < total_duration - overlap:
        continuation = model.generate_continuation(
            chunks[-1][:, :, -int(overlap * 32000):],
            prompt_sample_rate=32000,
            descriptions=[description]
        )
        chunks.append(continuation[0].cpu())
    full_wav = torch.cat(chunks, dim=-1)[:, :int(total_duration * 32000)]
    buf = io.BytesIO()
    torchaudio.save(buf, full_wav, sample_rate=32000, format="mp3")
    return buf.getvalue()
Minimum Infrastructure Requirements
  • GPU: NVIDIA Tesla T4 (16 GB VRAM) for medium, A100 for large.
  • RAM: 16 GB for inference, 32 GB for batching.
  • Storage: 20 GB for the model, S3-compatible for audio.
  • Software: Docker, CUDA 11.8+, PyTorch 2.0+.

Documentation for the API and fine-tuning scripts (LoRA) are also included. We have been working with AI/ML for over 5 years and have implemented 20+ projects on generative models. Our certified engineers guarantee a smooth integration.

Calculate the integration cost for your project — contact us. Get a consultation on latency optimization and model selection. Timelines range from 3 to 7 days. Typical savings from switching to MusicGen are $500–$2000 per month.

Source: MusicGen on GitHub — official Meta repository with documentation and examples.