Convert MP3 audio files to Minecraft Note Block Studio (.nbs) format.
Installation β’ Usage β’ Configuration β’ How It Works β’ Contributing
mp3-to-nbs is a command-line tool that analyses audio files and converts them into playable Note Block Studio songs. It uses spectral analysis to detect pitch, onset, and amplitude information from the input audio and maps the results onto Minecraft's vanilla note block instruments.
- Automatic pitch detection β uses the pYIN algorithm for robust fundamental frequency tracking
- Smart instrument mapping β assigns notes to the best-fitting vanilla instrument based on frequency range
- Onset detection β finds note attacks to produce natural-sounding rhythms
- Configurable presets β choose from
default,faithful,dense, orminimalconversion profiles - Layer management β distributes polyphonic notes across layers with overflow protection
- Fine pitch support β preserves pitch accuracy beyond the 25-key note block range
- Multiple audio formats β supports MP3, WAV, FLAC, OGG, and more
- Beautiful CLI β progress bars, conversion summaries, and coloured output via Rich
- Python 3.9 or later
- FFmpeg (required by librosa for MP3 decoding)
git clone https://github.com/devRaikou/mp3-to-nbs.git
cd mp3-to-nbs
pip install .pip install -e ".[dev]"mp3-to-nbs song.mp3This creates song.nbs in the same directory.
mp3-to-nbs song.mp3 -o my_song.nbsmp3-to-nbs song.mp3 --preset faithfulmp3-to-nbs song.mp3 --tempo 20 --instrument flutemp3-to-nbs song.mp3 \
-o output.nbs \
--tempo 20 \
--preset faithful \
--instrument guitar \
--max-layers 30 \
--sensitivity 0.3 \
--pitch-algo pyin \
--song-name "My Song" \
--author "devra" \
--verbose| Flag | Short | Default | Description |
|---|---|---|---|
--output |
-o |
<input>.nbs |
Output file path |
--tempo |
-t |
10.0 |
Ticks per second |
--instrument |
-i |
harp |
Default instrument |
--preset |
-p |
β | Configuration preset |
--max-layers |
β | 20 |
Maximum NBS layers |
--sensitivity |
β | 0.35 |
Onset sensitivity (0β1) |
--pitch-algo |
β | pyin |
Pitch algorithm (pyin / piptrack) |
--no-auto-instrument |
β | β | Disable frequency-based instrument selection |
--song-name |
β | filename | NBS header song name |
--author |
β | β | NBS header author |
--verbose |
-v |
β | Debug logging |
--quiet |
-q |
β | Suppress output |
| Preset | Tempo | Sensitivity | Max Layers | Best for |
|---|---|---|---|---|
default |
10 TPS | 0.35 | 20 | General use |
faithful |
20 TPS | 0.20 | 30 | High accuracy |
dense |
20 TPS | 0.15 | 40 | Complex tracks |
minimal |
5 TPS | 0.50 | 10 | Simple melodies |
Presets can be overridden with individual CLI flags:
mp3-to-nbs song.mp3 --preset faithful --tempo 15from mp3_to_nbs import convert, ConversionConfig
config = ConversionConfig(
tempo=20.0,
max_layers=30,
instrument="guitar",
song_name="My Song",
song_author="devra",
)
result = convert("song.mp3", "output.nbs", config)
print(f"Placed {result.notes_placed} notes in {result.elapsed:.1f}s")The conversion pipeline has four stages:
βββββββββββ βββββββββββββ βββββββββββββββ βββββββββββββ
β Load ββββββΆβ Analyse ββββββΆβ Map Notes ββββββΆβ Write NBS β
β Audio β β (pYIN) β β (key+inst) β β (pynbs) β
βββββββββββ βββββββββββββ βββββββββββββββ βββββββββββββ
- Load Audio β reads the input file via librosa, resamples to 22050 Hz mono.
- Analyse β runs onset detection to find note attacks, pYIN pitch tracking for fundamental frequency estimation, and RMS for amplitude.
- Map Notes β quantises timestamps to the NBS tick grid, converts Hz β MIDI β NBS key (with octave folding), selects the best instrument, and maps amplitude to velocity.
- Write NBS β distributes notes across layers (avoiding collisions), sets header metadata, and saves via pynbs.
Minecraft has 16 vanilla note block instruments, each suited to a different frequency range:
| ID | Instrument | Range |
|---|---|---|
| 0 | Harp | Mid (F#3βF#5) |
| 1 | Double Bass | Low (B1βF#3) |
| 5 | Guitar | Low-Mid (F#2βF#4) |
| 6 | Flute | Mid-High (F#4βF#6) |
| 7 | Bell | High (F#5βF#7) |
| 13 | Bit | Mid (F#3βF#5) |
| 14 | Banjo | Mid (F#3βF#5) |
| 15 | Pling | Mid (F#3βF#5) |
When auto-instrument is enabled (default), the converter picks the instrument whose range best matches each detected note's frequency.
src/mp3_to_nbs/
βββ __init__.py # Package metadata & public API
βββ __main__.py # python -m entry point
βββ cli.py # CLI argument parser & Rich output
βββ audio.py # Audio loading & spectral analysis
βββ converter.py # Conversion pipeline orchestrator
βββ nbs_writer.py # NBS file builder (pynbs)
βββ instruments.py # Instrument definitions & mapping
βββ config.py # Configuration dataclass & presets
See CONTRIBUTING.md for guidelines on how to contribute.
This project is licensed under the MIT License.