Skip to main content

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

Project description

Test Himig on macOS, Linux, and Windows PyPI Python License

Himig

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

Features

  • Compose melodies using note names and durations "NOTE:DURATION" format (e.g., "C4:0.5").
  • Play melodies directly on your system audio.
  • Save melodies as WAV files.
  • Generate in-memory WAV bytes for web apps.
  • Sample built-in melodies: Happy Birthday, Twinkle Twinkle, Ode to Joy, Für Elise.
  • 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

License

This project is licensed under the MIT License. See the LICENSE file for details.

Buy Me a Coffee

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.3.tar.gz (8.0 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.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: himig-1.0.3.tar.gz
  • Upload date:
  • Size: 8.0 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.3.tar.gz
Algorithm Hash digest
SHA256 f06ff4b1cee7edf756f50246e3b29c34ef4202d4b3b8aa20e04f2d9b7102b687
MD5 00d9cfee2ee5d6473ef244214541ae41
BLAKE2b-256 770897879ebdb3dd0058f8bff134cda848251eb72bc2221ffd65ecf053d7bcfb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: himig-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c5ae9c09d819ad39cbebfd109107cbce6f9c0bba3e58181d514803032a2ca730
MD5 ba6a1f5af90a724ddf98c28d62fc7762
BLAKE2b-256 9314496c70cdc75630839820494cdc4aafacc809fc6d710a8005e49651bbe52a

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