Skip to main content

Simple musical key detection

Project description

Musher

Build Status PyPI version

Simple musical key detection.

Table of Contents

Quick Start

Install

pip install musher 

Documentation

Sample Usage

What key profile should I use?

Installation

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.

Python 3.5+

pip install musher

C++ 14

Dependencies

Cmake

-- MacOS --
brew install cmake

-- Linux --
sudo apt install cmake

-- Windows --
Download from https://cmake.org/download/

Conan

pip install conan

Install (WIP)

conan install musher

Usage

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}

Key Profiles

Description of all available key profiles

Development

Python

Install normally

pip install .
# OR
python3 setup.py install

Install in debug mode

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.

C++

Build normally

python setup.py cmake

# OR

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .

Build in debug mode

python setup.py cmake --debug

# OR

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=On
cmake --build .

Tests

Python

Required dependencies

pip install tox pytest

Running tests

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

C++

Required dependencies

  1. Google Test (Conan should install this for you when the project is built in debug mode.)

Running tests

# Ctest
python setup.py ctest

# OR

# Google test
python setup.py gtest

Documentation

Generate documentation using Doxygen, Breathe, and Sphinx.

Link to documentation

Dependencies

  1. Doxygen >1.5.1 - Generates C++ documentation
  2. Breathe - Translate Doxygen docs to Sphinx docs
  3. Sphinx - Generates python documentation
  4. C++ dependencies - Required to build the project

How to Generate

python setup.py cmake --docs

Publish to Github Pages

You must install the python module and generate the docs BEFORE running this command.

  1. pip install -e .
  2. Generate docs
python setup.py publish_docs -m "Added docs for new function"

Cleanup

This will remove all the temporary files/folders created from building and testing this package.

python setup.py clean

Useful links

Python audio libraries:

Credits

Essentia - C++ library for audio and music analysis, description and synthesis, including Python bindings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

musher-0.0.4.tar.gz (36.4 MB view hashes)

Uploaded Source

Built Distributions

musher-0.0.4-pp37-pypy37_pp73-win32.whl (191.1 kB view hashes)

Uploaded PyPy Windows x86

musher-0.0.4-pp37-pypy37_pp73-manylinux2010_x86_64.whl (293.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64

musher-0.0.4-pp36-pypy36_pp73-win32.whl (191.1 kB view hashes)

Uploaded PyPy Windows x86

musher-0.0.4-pp36-pypy36_pp73-manylinux2010_x86_64.whl (293.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64

musher-0.0.4-cp39-cp39-win_amd64.whl (230.4 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

musher-0.0.4-cp39-cp39-win32.whl (192.6 kB view hashes)

Uploaded CPython 3.9 Windows x86

musher-0.0.4-cp39-cp39-manylinux2010_x86_64.whl (4.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

musher-0.0.4-cp39-cp39-manylinux2010_i686.whl (4.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

musher-0.0.4-cp39-cp39-macosx_10_12_x86_64.whl (282.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.12+ x86-64

musher-0.0.4-cp38-cp38-win_amd64.whl (230.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

musher-0.0.4-cp38-cp38-win32.whl (192.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

musher-0.0.4-cp38-cp38-manylinux2010_x86_64.whl (4.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

musher-0.0.4-cp38-cp38-manylinux2010_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

musher-0.0.4-cp38-cp38-macosx_10_12_x86_64.whl (282.7 kB view hashes)

Uploaded CPython 3.8 macOS 10.12+ x86-64

musher-0.0.4-cp37-cp37m-win_amd64.whl (231.7 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

musher-0.0.4-cp37-cp37m-win32.whl (194.2 kB view hashes)

Uploaded CPython 3.7m Windows x86

musher-0.0.4-cp37-cp37m-manylinux2010_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

musher-0.0.4-cp37-cp37m-manylinux2010_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

musher-0.0.4-cp37-cp37m-macosx_10_12_x86_64.whl (278.8 kB view hashes)

Uploaded CPython 3.7m macOS 10.12+ x86-64

musher-0.0.4-cp36-cp36m-win_amd64.whl (231.5 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

musher-0.0.4-cp36-cp36m-win32.whl (194.0 kB view hashes)

Uploaded CPython 3.6m Windows x86

musher-0.0.4-cp36-cp36m-manylinux2010_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

musher-0.0.4-cp36-cp36m-manylinux2010_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

musher-0.0.4-cp36-cp36m-macosx_10_12_x86_64.whl (278.7 kB view hashes)

Uploaded CPython 3.6m macOS 10.12+ x86-64

musher-0.0.4-cp35-cp35m-win_amd64.whl (231.5 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

musher-0.0.4-cp35-cp35m-win32.whl (194.0 kB view hashes)

Uploaded CPython 3.5m Windows x86

musher-0.0.4-cp35-cp35m-manylinux2010_x86_64.whl (4.4 MB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

musher-0.0.4-cp35-cp35m-manylinux2010_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

musher-0.0.4-cp35-cp35m-macosx_10_12_x86_64.whl (275.5 kB view hashes)

Uploaded CPython 3.5m macOS 10.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page