A Python package for generating Lofi music using AI models
Project description
lofi-gen
A Python package for generating Lofi music using AI models like MusicGen.
Features
- Generate lofi music from text prompts using Meta's MusicGen model
- Create seamless long-form music loops (extend short clips to hours-long sessions)
- Easy-to-use API for music generation
- Spectral crossfading for smooth transitions
Installation
From PyPI
pip install lofi-gen
From Source
git clone https://github.com/gnikesh/lofi-gen.git
cd lofi-gen
pip install -e .
Quick Start
Basic Music Generation
from lofi_gen.music.models import MusicGenModel
# Initialize the model
model = MusicGenModel(model_size="large") # Options: "small", "medium", "large"
# Generate music from a text prompt
audio, sample_rate = model.generate_music(
prompt="lofi hip hop beat with soft piano, chill vibes",
duration_seconds=30
)
# Save the generated audio
model.save_audio(audio, sample_rate, "output.wav")
Generate Long-Form Music
from lofi_gen.music.models import MusicGenModel
from lofi_gen.music.pipelines import LongMusicGenerator
# Generate initial clip
model = MusicGenModel()
audio, sample_rate = model.generate_music(
prompt="relaxing nepali lofi with bansuri flute",
duration_seconds=60
)
model.save_audio(audio, sample_rate, "base_clip.wav")
# Extend it to a long seamless loop
extender = LongMusicGenerator(crossfade_sec=3.0, variation=True)
extender.generate(
input_file="base_clip.wav",
output_file="extended_lofi.wav",
target_duration_mins=60 # Create a 60-minute loop
)
Requirements
- Python >= 3.8
- PyTorch >= 2.0.0
- transformers >= 4.30.0
- librosa >= 0.10.0
- scipy, numpy, soundfile
See requirements.txt for full dependencies.
Model Sizes
MusicGen comes in three sizes:
- small: Fastest, lower quality (~300MB)
- medium: Balanced speed and quality (~1.5GB)
- large: Best quality, slower (~3.3GB)
Choose based on your hardware and quality requirements.
Advanced Usage
Custom Generation Parameters
audio, sample_rate = model.generate_music(
prompt="lofi hip hop beat",
duration_seconds=30,
guidance_scale=3.0, # How closely to follow the prompt (1.0-15.0)
temperature=1.0, # Randomness (0.1-2.0)
top_k=250, # Sampling diversity
top_p=0.0 # Nucleus sampling (0 to disable)
)
Seamless Loop Configuration
extender = LongMusicGenerator(
crossfade_sec=3.0, # Crossfade duration
variation=True # Add subtle variations to prevent monotony
)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Meta AI for the MusicGen model
- Hugging Face for the Transformers library
- The open-source community for various audio processing tools
Support
For issues, questions, or suggestions:
- Open an issue on GitHub
Roadmap
- Add more AI models (AudioLDM, Stable Audio, etc.)
- Video generation capabilities
- CLI interface for easy command-line usage
- Pre-trained models fine-tuned on Nepali music
- Web interface for music generation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lofi_gen-0.1.0.tar.gz.
File metadata
- Download URL: lofi_gen-0.1.0.tar.gz
- Upload date:
- Size: 18.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd3fda9235e69bd466d8c09fefb8cc786f52a41e7fe2a9bd957a7c85b75c87b8
|
|
| MD5 |
0dbdeef4e40dec75ad8596d5fb308b56
|
|
| BLAKE2b-256 |
4e2f6621798987e5ba8ac99a96ea908f836d8515d291bf7a01bf1e78457f2160
|
File details
Details for the file lofi_gen-0.1.0-py3-none-any.whl.
File metadata
- Download URL: lofi_gen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
522b1921cd15f1cfd17c46f9c071252b5361b124388fc2f1b99d88ce4c922581
|
|
| MD5 |
8b0813fcd58a24817b50e170c78bdfc1
|
|
| BLAKE2b-256 |
dfcf6f88c95ccd2e2d623960c17da732d810463f1785ce92bdfb0e91b1a657cc
|