Simple musical key detection.
- Musher
- Table of Contents
- Quick Start
- Installation
- Usage
- Development
- Tests
- Documentation
- Cleanup
- Useful links
- Credits
pip install musher
You can choose to install this package in 2 ways, Python and C++. The package was primary written in C++ and wrapped in Python. Choose either of the following methods of installation.
pip install musher
-- MacOS --
brew install cmake
-- Linux --
sudo apt install cmake
-- Windows --
Download from https://cmake.org/download/
pip install conan
conan install musher
import os
import musher
audio_file_path = os.path.join("data", "audio_files", "mozart_c_major_30sec.wav")
wav_decoded = musher.decode_wav_from_file(audio_file_path)
print(wav_decoded)
{
'avg_bitrate_kbps': 1411,
'bit_depth': 16,
'channels': 2,
'file_type': 'wav',
'length_in_seconds': 30.0,
'mono': False,
'normalized_samples': array([
[ 0. , 0. , 0. , ..., -0.33203125, -0.32833862, -0.3274536 ],
[ 0. , 0. , 0. , ..., -0.29162598, -0.27130127, -0.25457764]
], dtype=float32),
'sample_rate': 44100,
'samples_per_channel': 1323000,
'stereo': True
}
normalized_samples = wav_decoded["normalized_samples"]
sample_rate = wav_decoded["sample_rate"]
# Different key profiles produce different results.
# 'Temperley' produces good results for classical music.
key_profile_type = "Temperley"
key_output = musher.detect_key(normalized_samples, sample_rate, key_profile_type)
print(key_output)
{
'first_to_second_relative_strength': 0.6078072169442225,
'key': 'C',
'scale': 'major',
'strength': 0.7603224296919142
}
Description of all available key profiles
pip install .
# OR
python3 setup.py install
pip install -e .
# OR
python3 setup.py develop
NOTE: This package has 2 dependencies: Pybind11 and Numpy. You may need to install these python packages if the setup.py does not do it for you.
python setup.py cmake
# OR
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .
python setup.py cmake --debug
# OR
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=On
cmake --build .
pip install tox pytest
This will run tests against a pip installed copy of the source code (best to do before deploying code).
# Running this command does not require pytest to be installed
tox
This will run tests directly (best to do while modifying the code base).
pytest ./tests -v
- Google Test (Conan should install this for you when the project is built in debug mode.)
# Ctest
python setup.py ctest
# OR
# Google test
python setup.py gtest
Generate documentation using Doxygen, Breathe, and Sphinx.
- Doxygen >1.5.1 - Generates C++ documentation
- Breathe - Translate Doxygen docs to Sphinx docs
- Sphinx - Generates python documentation
- C++ dependencies - Required to build the project
python setup.py cmake --docs
You must install the python module and generate the docs BEFORE running this command.
pip install -e .
- Generate docs
python setup.py publish_docs -m "Added docs for new function"
This will remove all the temporary files/folders created from building and testing this package.
python setup.py clean
Python audio libraries:
Essentia - C++ library for audio and music analysis, description and synthesis, including Python bindings.