A completely free, local AI music generator powered by Meta's MusicGen and Streamlit.
No paid APIs. No cloud dependency. Just open-source creativity on your own machine.
-
🧠 Text-to-Music Generation using
facebook/musicgen-small -
🎧 Outputs playable MP3 and WAV files
-
⚙️ Runs fully offline after first model download
-
🤖 Optional local LLM (Ollama + Mistral) to refine prompts
-
💾 Download button for easy export
-
💬 Simple and clean Streamlit UI
`local_musicgen_studio/
├── app.py
├── requirements.txt
├── .env.example
├── README.md
└── outputs/``python -m venv venv
venv\Scripts\activate # (Windows)
source venv/bin/activate # (Mac/Linux)`
`pip install -r requirements.txt`
If you see warnings about FFmpeg, follow the setup instructions below.
`pip install ffmpeg-downloader
python -m ffmpeg_downloader -o "C:\ffmpeg"`
Then add `C:\ffmpeg\bin` to your **System PATH**, and verify:
`ffmpeg -version`
brew install ffmpeg
sudo apt install ffmpeg
# Optional local LLM for prompt refinement OLLAMA_MODEL=mistral
streamlit run app.py
Once launched, open the local URL displayed in your terminal.
-
"A calm ambient piano piece with soft reverb and slow tempo"
-
"Energetic EDM track with strong kick, synth bass, and fast rhythm"
-
"Epic orchestral build with strings, drums, and brass"
-
"Chill lo-fi beat with vinyl crackle and warm piano loops"
-
"Retro 80s synthwave with analog pads and gated drums"
| Step | Component | Description |
|---|---|---|
| 1 | Streamlit UI | Collects prompt and duration |
| 2 | (Optional) Local LLM | Refines user's natural prompt |
| 3 | MusicGen Model | Generates raw audio tensors |
| 4 | Pydub + SoundFile | Converts to WAV/MP3 |
| 5 | Streamlit | Plays and allows download |
| Library | Purpose |
|---|---|
torch |
Core ML backend |
transformers |
Access to Meta's MusicGen model |
soundfile |
Writing NumPy arrays to WAV |
pydub |
Convert WAV → MP3 |
streamlit |
Interactive UI |
dotenv |
Environment variable loader |
`torch==2.2.2
transformers==4.42.3
accelerate==0.31.0
soundfile==0.12.1
pydub==0.25.1
streamlit==1.37.0
python-dotenv`
-
Change
facebook/musicgen-small→facebook/musicgen-mediumfor higher-quality generation. -
Adjust
duration_secslider range for longer or shorter tracks. -
Use Ollama with Mistral or Phi for smarter prompt refinement.
-
Save generated outputs automatically to the
outputs/directory.
| Prompt | Duration | Result |
|---|---|---|
| "Chill lo-fi beat with soft drums and electric piano" | 15 sec | Lo-fi instrumental loop |
| "Epic cinematic build with strings and brass" | 20 sec | Orchestral score intro |
-
Meta AI -- MusicGen
-
Streamlit
-
Hugging Face Transformers
MIT License --- free for personal and commercial use.
Please credit the open-source authors when sharing.
Mohamed Azarudeen Allabaksh
AI & Data Science | Stony Brook University
📂 GitHub: github.com/azarudeenallabaksh
🔗 LinkedIn: linkedin.com/in/mohamed-azarudeen