PyHarmonize: Adding harmony lines to recorded melodies in Python

Overview

PyHarmonize: Adding harmony lines to recorded melodies in Python

About

To use this module, the user provides

  • a wav file containing a melody,
  • the key in which the melody is, and
  • the scale degree(s) of the desired harmony.

The module then outputs a wav file which contains the original melody, together with the added harmony line(s).

We first give some examples, the installation instructions are further below.

Examples (with audio files)

We here provide three audio examples together with the code used to generate them. See the folder examples/ for more detailed example notebooks.

Note that the embedded mp4 video files that contain the audio in the following are by default muted.

Example 1: Added third on a distorted electric guitar

In this example we add a harmony line a third above the input melody, which is played on a distorted electric guitar. Here are the input signal used, as well as the final result:

guitar_distorted_E_major_ex1.mp4
guitar_distorted_E_major_ex1_added_3.mp4

And here is the code used to generate this output:

import PyHarmonize

# Create dictionary with parameters
parameters = {'input_filename':'./guitar_distorted_E_major_ex1.wav', # input audio is in the key of E major
              'output_filename':'./guitar_distorted_E_major_ex1_with_harmony.wav',
              'key':'E',
              'mode':'major'}

# Generate instance of the class harmony_generator
harmony_generator = PyHarmonize.harmony_generator(parameters=parameters)

# Add harmony
# Note that scale_degrees = [3] means we add one melody line,
# which is always three notes higher within the scale. Depending on the note
# played, "three notes higher within the scale" is either 3 or 4 semitones up.
output_dictionary = harmony_generator.add_harmonies(scale_degrees = [3])

Example 2: Added third and fifth on a distorted electric guitar

In this example we add two harmony lines to an input signal. Here are the input signal and the result:

guitar_distorted_E_major_ex2.mp4
guitar_distorted_E_major_ex2_added_3_5.mp4

The code for this example is essentially the same as in the first example, except that now the list scale_degrees contains more than one element:

import PyHarmonize

# Create dictionary with parameters
parameters = {'input_filename':'./guitar_distorted_E_major_ex2.wav', # input audio is in the key of E major
              'output_filename':'./guitar_distorted_E_major_ex2_with_harmony.wav',
              'key':'E',
              'mode':'major'}

# Generate instance of the class harmony_generator
harmony_generator = PyHarmonize.harmony_generator(parameters=parameters)

# Add harmony
output_dictionary = harmony_generator.add_harmonies(scale_degrees = [3, 5]) # add third and fifth

If we add some more octaves and thirds, we can generate a more synthesizer-like sound. Here is an example for that:

guitar_distorted_E_major_ex2_added_3_5_octaves.mp4

To generate this output, we pass scale_degrees = [-8, -6, 3, 5, 8, 10], which adds pitch shifted signals an octave lower (-8), the third one octave lower (-6), a third up (3), a fifth up (5), an octave up (8), and a third an octave higher (10).

Example 3: Added third, fifth, and octave on a clean electric guitar

In this example we add thirds, fifths, and octaves to a melody in A major, which is played on a clean electric guitar. Here are input and output files:

guitar_clean_A_major.mp4
guitar_clean_A_major_added_3_5_8.mp4

The code for generating this harmony is:

import PyHarmonize

# Create dictionary with parameters
parameters = {'input_filename':'./guitar_clean_A_major.wav', # input audio is in the key of A major
              'output_filename':'./guitar_clean_A_major_with_harmony.wav',
              'key':'A',
              'mode':'major'}

# Generate instance of the class harmony_generator
harmony_generator = PyHarmonize.harmony_generator(parameters=parameters)

# Add harmony
output_dictionary = harmony_generator.add_harmonies(scale_degrees = [3,5,8])
# The list
#       scale_degrees = [3, 5, 8]
# means that we add four melody lines:
# 1. a third up
# 2. a fifth up
# 3. one octave up

Installation

To install the module PyHarmonize, as well as its requirements (NumPy, SciPy, librosa, and SoundFile), clone this repository and run the installation script:

>> git clone https://github.com/juliankappler/PyHarmonize.git
>> cd PyHarmonize
>> pip install -r requirements.txt
>> python setup.py install
Owner
Julian Kappler
Julian Kappler
A repository to work on Machine Learning course. Select an algorithm to classify writer's gender, of Hebrew texts.

MachineLearning A repository to work on Machine Learning course. Select an algorithm to classify writer's gender, of Hebrew texts. Tested algorithms:

Haim Adrian 1 Feb 01, 2022
BudouX is the successor to Budou, the machine learning powered line break organizer tool.

BudouX Standalone. Small. Language-neutral. BudouX is the successor to Budou, the machine learning powered line break organizer tool. It is standalone

Google 868 Jan 05, 2023
Pandas DataFrames and Series as Interactive Tables in Jupyter

Pandas DataFrames and Series as Interactive Tables in Jupyter Star Turn pandas DataFrames and Series into interactive datatables in both your notebook

Marc Wouts 364 Jan 04, 2023
GAM timeseries modeling with auto-changepoint detection. Inspired by Facebook Prophet and implemented in PyMC3

pm-prophet Pymc3-based universal time series prediction and decomposition library (inspired by Facebook Prophet). However, while Faceook prophet is a

Luca Giacomel 314 Dec 25, 2022
machine learning model deployment project of Iris classification model in a minimal UI using flask web framework and deployed it in Azure cloud using Azure app service

This is a machine learning model deployment project of Iris classification model in a minimal UI using flask web framework and deployed it in Azure cloud using Azure app service. We initially made th

Krishna Priyatham Potluri 73 Dec 01, 2022
As we all know the BGMI Loot Crate comes with so many resources for the gamers, this ML Crate will be the hub of various ML projects which will be the resources for the ML enthusiasts! Open Source Program: SWOC 2021 and JWOC 2022.

Machine Learning Loot Crate 💻 🧰 🔴 Welcome contributors! As we all know the BGMI Loot Crate comes with so many resources for the gamers, this ML Cra

Abhishek Sharma 89 Dec 28, 2022
Visualize classified time series data with interactive Sankey plots in Google Earth Engine

sankee Visualize changes in classified time series data with interactive Sankey plots in Google Earth Engine Contents Description Installation Using P

Aaron Zuspan 76 Dec 15, 2022
Case studies with Bayesian methods

Case studies with Bayesian methods

Baze Petrushev 8 Nov 26, 2022
This machine learning model was developed for House Prices

This machine learning model was developed for House Prices - Advanced Regression Techniques competition in Kaggle by using several machine learning models such as Random Forest, XGBoost and LightGBM.

serhat_derya 1 Mar 02, 2022
A Streamlit demo to interactively visualize Uber pickups in New York City

Streamlit Demo: Uber Pickups in New York City A Streamlit demo written in pure Python to interactively visualize Uber pickups in New York City. View t

Streamlit 230 Dec 28, 2022
Automatically create Faiss knn indices with the most optimal similarity search parameters.

It selects the best indexing parameters to achieve the highest recalls given memory and query speed constraints.

Criteo 419 Jan 01, 2023
Backprop makes it simple to use, finetune, and deploy state-of-the-art ML models.

Backprop makes it simple to use, finetune, and deploy state-of-the-art ML models. Solve a variety of tasks with pre-trained models or finetune them in

Backprop 227 Dec 10, 2022
A machine learning toolkit dedicated to time-series data

tslearn The machine learning toolkit for time series analysis in Python Section Description Installation Installing the dependencies and tslearn Getti

2.3k Dec 29, 2022
Model factory is a ML training platform to help engineers to build ML models at scale

Model Factory Machine learning today is powering many businesses today, e.g., search engine, e-commerce, news or feed recommendation. Training high qu

16 Sep 23, 2022
This is a curated list of medical data for machine learning

Medical Data for Machine Learning This is a curated list of medical data for machine learning. This list is provided for informational purposes only,

Andrew L. Beam 5.4k Dec 26, 2022
A concept I came up which ditches the idea of "layers" in a neural network.

Dynet A concept I came up which ditches the idea of "layers" in a neural network. Install Copy Dynet.py to your project. Run the example Install matpl

Anik Patel 4 Dec 05, 2021
All-in-one web-based development environment for machine learning

All-in-one web-based development environment for machine learning Getting Started • Features & Screenshots • Support • Report a Bug • FAQ • Known Issu

3 Feb 03, 2021
mlpack: a scalable C++ machine learning library --

a fast, flexible machine learning library Home | Documentation | Doxygen | Community | Help | IRC Chat Download: current stable version (3.4.2) mlpack

mlpack 4.2k Jan 01, 2023
2D fluid simulation implementation of Jos Stam paper on real-time fuild dynamics, including some suggested extensions.

Fluid Simulation Usage Download this repo and store it in your computer. Open a terminal and go to the root directory of this folder. Make sure you ha

Mariana Ávalos Arce 5 Dec 02, 2022
List of Data Science Cheatsheets to rule the world

Data Science Cheatsheets List of Data Science Cheatsheets to rule the world. Table of Contents Business Science Business Science Problem Framework Dat

Favio André Vázquez 11.7k Dec 30, 2022