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
- ffmpeg must be installed on your system.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaf52662d70a5ac81a5edfac0924f1fbbee48ca727060b827eda2f3fc05453a7
|
|
| MD5 |
af064a651b104839ebeafa444d6cf7c3
|
|
| BLAKE2b-256 |
7f69d42526b3f047ceea451de93c6cb14fe9f93574e86e1aec03bda95fa6a973
|
File details
Details for the file harmonization_env-1.0-py3-none-any.whl.
File metadata
- Download URL: harmonization_env-1.0-py3-none-any.whl
- Upload date:
- Size: 34.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4100fb7a84636a9cc9798c5adee5806b5e30ab444749761d7bf6cf326c773b4b
|
|
| MD5 |
3749d1ff382c9f61774b45e6f022bcf5
|
|
| BLAKE2b-256 |
66c676b97c39bb7e6d3b3f5b96d9bff6c430376062e63605d1f2d6c4f7b9f952
|