Bring melodies to life with pure Python. Input note strings, hear real sound.
Project description
himig
himig is a simple, pure-Python music synthesis and playback package. It lets you generate, play, and save melodies as WAV files using a human-friendly note and duration format. It’s perfect for educational projects, demos, and creative coding.
Features
- 🎵 Compose melodies using note names and durations (e.g.,
"C4:0.5") - 🔊 Play melodies directly on your system’s audio output
- 💾 Save melodies as standard 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
Installation
pip install himig
Or, for development:
git clone https://github.com/j-ncel/himig.git
cd himig
Quick Start
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 or Web Apps
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, orRfor rest)DURATION: Length in seconds (float or int)
- Example:
["C4:0.5", "G4:1.0", "R:0.25"]
Built-in Melodies
happy_birthdaytwinkle_twinkle
You can import them directly:
from himig import happy_birthday, twinkle_twinkle
You can contribute more melodies to the project, it is welcome!
API Reference
play(melody, sample_rate=44100, amplitude=32767)
Play a melody through your system’s audio output.
melody: List of note-duration stringssample_rate: Audio sample rate (Hz)amplitude: Peak amplitude
save(melody, filename, sample_rate=44100, amplitude=32767)
Save a melody as a WAV file.
melody: List of note-duration stringsfilename: Output WAV file path
generate_wav_bytes(melody, sample_rate=44100, amplitude=32767)
Generate a WAV file as an in-memory bytes buffer (for web apps).
- Returns:
io.BytesIOobject
Adding Your Own Melodies
Just create a list of note-duration strings:
my_song = [
"C4:0.5", "D4:0.5", "E4:1.0", "R:0.25", "E4:0.5", "D4:0.5", "C4:1.0"
]
play(my_song)
Project Structure
himig/
│
├── himig/
│ ├── __init__.py
│ ├── core.py
│ ├── audio_player.py
│ ├── constants.py
│ └── melodies.py
│
├── tests/
│ └── test_himig.py
├── README.md
├── pyproject.toml
└── 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
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 himig-1.0.0.tar.gz.
File metadata
- Download URL: himig-1.0.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
386e3729749e172de0003e305e3811299fea566fba8302e24a28e2bcf81791fa
|
|
| MD5 |
16e2d7c7c3783adbf7759e2fe17173ba
|
|
| BLAKE2b-256 |
b4a96628989c3b87d29dda5009b8a1c3b659eac280fe4e66c40b782ef9c784cd
|
File details
Details for the file himig-1.0.0-py3-none-any.whl.
File metadata
- Download URL: himig-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a0a6e735f335c4ff4668cb09a94b1a0169f4f6acf6ebf09460fa810bc799ecc
|
|
| MD5 |
a62e16c0b8f643a61b3149ae8c013404
|
|
| BLAKE2b-256 |
fe043807a055c52da2d9d847946fe78647aaf8147e064ae87f93074c7061c594
|