Skip to main content

Harmonization environment implementation via reinforcement learning

Project description

Music Harmonization Package

A Reinforcement Learning package to generate musical harmonies, starting from a general sequence of notes in the scale of C major. Outputs musical harmonies, MIDI files, and mp4 videos.

Prerequisites

Examples

Here are a few example outputs generated by the package. The top line is the melody, given as input. The other notes played are generated. In this case a simple C major scale. The following videos are two different outputs generated by the agent.

https://github.com/user-attachments/assets/e7a52a7e-48b0-4076-8552-e5e392ad850d

https://github.com/user-attachments/assets/9b4d98df-2e92-45ec-9ef5-695c0d947d09

Installation

Install this package via pyPI:

pip install harmonization-env

https://pypi.org/project/harmonization-env/

Basic Usage

Here's a complete example showing the main features:

import torch
from harmonization_env import *

path_to_params = "..."
env = HarmonizationEnv(device = 'cpu')

net = NetM.load_from_checkpoint(path_to_params, device = 'cpu')

# Create a melody sequence
# Notes are represented as MIDI numbers (60 = middle C)
melody = torch.tensor([64, 64, 65, 65, 
                       67, 69, 69, 62,
                       67, 67, 68, 71,
                       69, 71, 72, 65,
                       64, 64, 62, 62,
                       60, 60, 60, 60,
                       60], dtype = torch.int32)

melody += 12


# get output
chords, reward = agent.get(
    melody = melody,
)

run = chords[0, :]


v = Voicer(melody, run)
voices = v.get()

player = MIDIGenerator(tempo = 80) 

# get and play midi output
player.generate(voices, filenames = 'test0.mid')
player.play(filename = 'test0.mid')

# Create visualization video
# Download soundfont from https://member.keymusician.com/Member/FluidR3_GM/index.html
vg = VideoGenerator('test0.mid', soundfont_path='FluidR3_GM.sf2')
vg.get_video(output_filename='output.mp4')

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

harmonization_env-1.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

harmonization_env-1.0-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file harmonization_env-1.0.tar.gz.

File metadata

  • Download URL: harmonization_env-1.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.0

File hashes

Hashes for harmonization_env-1.0.tar.gz
Algorithm Hash digest
SHA256 aaf52662d70a5ac81a5edfac0924f1fbbee48ca727060b827eda2f3fc05453a7
MD5 af064a651b104839ebeafa444d6cf7c3
BLAKE2b-256 7f69d42526b3f047ceea451de93c6cb14fe9f93574e86e1aec03bda95fa6a973

See more details on using hashes here.

File details

Details for the file harmonization_env-1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for harmonization_env-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4100fb7a84636a9cc9798c5adee5806b5e30ab444749761d7bf6cf326c773b4b
MD5 3749d1ff382c9f61774b45e6f022bcf5
BLAKE2b-256 66c676b97c39bb7e6d3b3f5b96d9bff6c430376062e63605d1f2d6c4f7b9f952

See more details on using hashes here.

Supported by

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