Skip to content

jmaldon1/Musher

Repository files navigation

Musher

Build Status PyPI version

Simple musical key detection.

Table of Contents

Quick Start

Install

pip install musher 

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.

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.

About

Simple musical key detection

Resources

License

Stars

Watchers

Forks

Packages

No packages published