CPP-Song-Key-BPM-Finder is a C++ command-line project that uses a Python analysis bridge (librosa + numpy) to detect:
- tempo (BPM)
- musical key (major/minor)
- confidence and analysis metadata
The project now uses a proper chroma-based key estimation pipeline with Krumhansl-Schmuckler key profiles instead of using tuning estimation as a key proxy.
src/main.cpp: single C++ entrypointinclude/bridge_runner.hpp: C++ bridge execution utilitiesscripts/PyBridge.py: Python analysis engineCMakeLists.txt: build configurationrequirements.txt: Python dependencies
- C++17 compiler (
g++,clang++, or MSVC) - CMake 3.16+
- Python 3.9+
pip
- Install Python dependencies:
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt- Configure and build:
cmake -S . -B build
cmake --build buildRun human-readable output:
KEY_BPM_PYTHON=.venv/bin/python ./build/Key-BpmFinder <audio_file>Run JSON output from the same executable:
KEY_BPM_PYTHON=.venv/bin/python ./build/Key-BpmFinder --json <audio_file>Human-readable mode:
BPM: 121.53
Key: A minor
Key score: 0.8652
Key confidence: 0.0421
Sample rate: 44100
Duration (seconds): 34.18
JSON mode:
{"bpm": 121.53, "key": "A minor", "key_score": 0.8652, "key_confidence": 0.0421, "sample_rate": 44100, "duration_seconds": 34.18}Error: Audio file not found: check the file path.Error: Could not find PyBridge.py: ensurescripts/PyBridge.pyexists in the repository.ModuleNotFoundError: No module named 'librosa': install dependencies withpython3 -m pip install -r requirements.txt.- If you use a virtual environment, set
KEY_BPM_PYTHONto that Python executable. - If an audio backend error appears, install
ffmpegand retry.
Key-BpmFindercopiesscripts/PyBridge.pyinto the build output directory automatically.- Key estimation is probabilistic; confidence is included so low-confidence detections are visible.