like random-art, but with music
Project description
Musical Hash
Introduction
Just as Random Art provides a method to visualize RSA keys, Musical Hash provides a method to "visualize" the output of a hash function as audio. It generates a unique melody for each hash value that can be exported as a wave file, a midi file, or a list of notes in ABC notation.
Quick Start
- Install the package:
pip install musical_hash
- In a Python console, import the package:
>>> import musical_hash
- Construct the musical hash object:
>>> hash = musical_hash.MusicalHash(b'Hello World!', 'md5')
- Export the hash as a wave file in the key of A pentatonic minor:
>>> hash.wave('hash.wav', key=musical_hash.A_PENTATONIC_MINOR)
- Or, export as a midi file:
>>> hash.midi('hash.mid', key=musical_hash.A_PENTATONIC_MINOR)
API Documentation
For the complete API documentation, click here.
Theory of Operation
In western classical music there are twelve semitones in an octave. The first note of the subsequent octave is the first harmonic of the first note of the previous octave. Thus we will consider a single octave as the universe of all notes available to "visualize" a sequence of bytes. Most pieces of music are written in a specific key, which is a subset of all available notes. Within a single octave, each key has a finite number of notes, so if we consider the sequence of bytes as an integer, we can find that integer's representation in a base equal to the number of notes in a key. We then assign each digit of this representation a musical note. This package comes with many diatonic and pentatonic keys as constants.
Dependencies
Only Python version 3.5 and greater are supported. This package should run on any POSIX system as well as Windows 7 and greater.
The following Pypi packages are required:
- mido
- numpy
- wavio
Contributing
Suggestions and pull requests are welcome. If you find a bug and don't have time to fix it yourself, feel free to open an issue. Also, I am not an expert at Music Theory; if you find an error with the way a scale or musical term is named, please call it out so that I can learn.
Future Tasks
- TODO: Make a hash that includes chords to decrease the tune length and increase the perceived uniqueness of each hash.
See Also
Originally I thought I was the only one with this idea, but after I implemented it I found this guy's repository, so check it out if you want to see another take on the concept.
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
File details
Details for the file musical_hash-0.1.3.zip
.
File metadata
- Download URL: musical_hash-0.1.3.zip
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 809d590f19b764c7664beb9d108dd1fc86402266455445a88235705d3d880cb4 |
|
MD5 | e032e2dec3a72996facd6df4193b43b0 |
|
BLAKE2b-256 | 86fb3c40ca04bec63f8a69a14e3dd423688909ff80ef2a1bfd895877282b0251 |