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
ML Kaggle Titanic Problem using LogisticRegrission

-ML-Kaggle-Titanic-Problem-using-LogisticRegrission here you will find the solution for the titanic problem on kaggle with comments and step by step c

Mahmoud Nasser Abdulhamed 3 Oct 23, 2022
Simple Machine Learning Tool Kit

Getting started smltk (Simple Machine Learning Tool Kit) package is implemented for helping your work during data preparation testing your model The g

Alessandra Bilardi 1 Dec 30, 2021
LibRerank is a toolkit for re-ranking algorithms. There are a number of re-ranking algorithms, such as PRM, DLCM, GSF, miDNN, SetRank, EGRerank, Seq2Slate.

LibRerank LibRerank is a toolkit for re-ranking algorithms. There are a number of re-ranking algorithms, such as PRM, DLCM, GSF, miDNN, SetRank, EGRer

126 Dec 28, 2022
Pyomo is an object-oriented algebraic modeling language in Python for structured optimization problems.

Pyomo is a Python-based open-source software package that supports a diverse set of optimization capabilities for formulating and analyzing optimization models. Pyomo can be used to define symbolic p

Pyomo 1.4k Dec 28, 2022
Apache Liminal is an end-to-end platform for data engineers & scientists, allowing them to build, train and deploy machine learning models in a robust and agile way

Apache Liminals goal is to operationalise the machine learning process, allowing data scientists to quickly transition from a successful experiment to an automated pipeline of model training, validat

The Apache Software Foundation 121 Dec 28, 2022
A Python implementation of FastDTW

fastdtw Python implementation of FastDTW [1], which is an approximate Dynamic Time Warping (DTW) algorithm that provides optimal or near-optimal align

tanitter 651 Jan 04, 2023
MLflow App Using React, Hooks, RabbitMQ, FastAPI Server, Celery, Microservices

Katana ML Skipper This is a simple and flexible ML workflow engine. It helps to orchestrate events across a set of microservices and create executable

Tom Xu 8 Nov 17, 2022
The Ultimate FREE Machine Learning Study Plan

The Ultimate FREE Machine Learning Study Plan

Patrick Loeber (Python Engineer) 2.5k Jan 05, 2023
My capstone project for Udacity's Machine Learning Nanodegree

MLND-Capstone My capstone project for Udacity's Machine Learning Nanodegree Lane Detection with Deep Learning In this project, I use a deep learning-b

Michael Virgo 407 Dec 12, 2022
scikit-fem is a lightweight Python 3.7+ library for performing finite element assembly.

scikit-fem is a lightweight Python 3.7+ library for performing finite element assembly. Its main purpose is the transformation of bilinear forms into sparse matrices and linear forms into vectors.

Tom Gustafsson 297 Dec 13, 2022
A linear equation solver using gaussian elimination. Implemented for fun and learning/teaching.

A linear equation solver using gaussian elimination. Implemented for fun and learning/teaching. The solver will solve equations of the type: A can be

Sanjeet N. Dasharath 3 Feb 15, 2022
A complete guide to start and improve in machine learning (ML)

A complete guide to start and improve in machine learning (ML), artificial intelligence (AI) in 2021 without ANY background in the field and stay up-to-date with the latest news and state-of-the-art

Louis-François Bouchard 3.3k Jan 04, 2023
Python factor analysis library (PCA, CA, MCA, MFA, FAMD)

Prince is a library for doing factor analysis. This includes a variety of methods including principal component analysis (PCA) and correspondence anal

Max Halford 915 Dec 31, 2022
30 Days Of Machine Learning Using Pytorch

Objective of the repository is to learn and build machine learning models using Pytorch. 30DaysofML Using Pytorch

Mayur 119 Nov 24, 2022
Repository for DCA0305, an undergraduate course about Machine Learning Workflows and Pipelines

Federal University of Rio Grande do Norte Technology Center Department of Computer Engineering and Automation Machine Learning Based Systems Design Re

Ivanovitch Silva 81 Oct 18, 2022
SynapseML - an open source library to simplify the creation of scalable machine learning pipelines

Synapse Machine Learning SynapseML (previously MMLSpark) is an open source library to simplify the creation of scalable machine learning pipelines. Sy

Microsoft 3.9k Dec 30, 2022
Machine Learning for RC Cars

Suiron Machine Learning for RC Cars Prediction visualization (green = actual, blue = prediction) Click the video below to see it in action! Dependenci

Kendrick Tan 706 Jan 02, 2023
A statistical library designed to fill the void in Python's time series analysis capabilities, including the equivalent of R's auto.arima function.

pmdarima Pmdarima (originally pyramid-arima, for the anagram of 'py' + 'arima') is a statistical library designed to fill the void in Python's time se

alkaline-ml 1.3k Dec 22, 2022
Deep Survival Machines - Fully Parametric Survival Regression

Package: dsm Python package dsm provides an API to train the Deep Survival Machines and associated models for problems in survival analysis. The under

Carnegie Mellon University Auton Lab 10 Dec 30, 2022
TensorFlowOnSpark brings TensorFlow programs to Apache Spark clusters.

TensorFlowOnSpark TensorFlowOnSpark brings scalable deep learning to Apache Hadoop and Apache Spark clusters. By combining salient features from the T

Yahoo 3.8k Jan 04, 2023