Skip to main content

Python music synthesis module that lets you compose, play, and save melodies

Project description

Himig

himig is a Python music synthesis module that lets you compose, play, and save melodies.


  • Compose melodies using note names and durations (e.g., "C4:0.5").
  • Play melodies directly on your system’s audio output.
  • Save melodies as WAV files.
  • Generate in-memory WAV bytes for web apps (e.g., Streamlit).
  • Sample built-in melodies: Happy Birthday, Twinkle Twinkle.
  • Lightweight: Only depends on numpy.

Demo

👉 Himig Playground on Streamlit Cloud 👈

Demo preview


Installation

pip install himig

Or, for development:

git clone https://github.com/j-ncel/himig.git
cd himig
pip install -e .

Usage

Play a Melody

from himig import play

melody = ["C4:0.5", "C4:0.5", "G4:1.0"]
play(melody)

Save a Melody as WAV

from himig import save

melody = ["C4:0.5", "C4:0.5", "G4:1.0"]
save(melody, "happy.wav")

Use Built-in Melodies

from himig import play, happy_birthday, twinkle_twinkle

play(happy_birthday)
play(twinkle_twinkle)

Use in Streamlit

import streamlit as st
from himig import generate_wav_bytes, happy_birthday

wav_bytes = generate_wav_bytes(happy_birthday)
st.audio(wav_bytes, format="audio/wav")

Melody Format

  • Each melody is a list of strings: "NOTE:DURATION"
    • NOTE: Note name (e.g., C4, F#5, Bb3, or R for rest)
    • DURATION: Length in seconds (float or int)
  • Example: ["C4:0.5", "G4:1.0", "R:0.25"]

Built-in Melodies

  • happy_birthday
  • twinkle_twinkle

You can import them directly:

from himig import happy_birthday, twinkle_twinkle

You can contribute more melodies to the project—contributions are welcome!


Project Structure

himig/
│
├── himig/
│   ├── __init__.py
│   ├── _core.py
│   ├── _audio_player.py
│   ├── constants.py
│   └── melodies.py
├── playground/
│   ├── st-playground.py
│   └── demo.gif
├── tests/
│   └── test_himig.py
├── README.md
├── pyproject.toml
├── requirements.txt
└── LICENSE

Links


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

himig-1.0.2.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

himig-1.0.2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file himig-1.0.2.tar.gz.

File metadata

  • Download URL: himig-1.0.2.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for himig-1.0.2.tar.gz
Algorithm Hash digest
SHA256 75c19867754d940f56061a2abf83ab5f15726b934c5967ab9625b315ee97da92
MD5 7fc4b042d37306e1d7644e4c979163b6
BLAKE2b-256 c884b0c42bde4cd40fa8696b6787358d396b6e022e2d179ce68247efbf1a7ef3

See more details on using hashes here.

File details

Details for the file himig-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: himig-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for himig-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 60aaf7cef24757b40fbc19b9ea26c48238f340e2d096d522a559cb664a3752a1
MD5 27c5dfab5de7b893bf718ae04543ee5a
BLAKE2b-256 00b606727d1c1fe70aaff0f829140826c1749b6ad4f221d6d4a8bab15ab41d69

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