String to music is an extremely simple example of how one can play music from their computer that is generated by strings of text.
This example simply reads the first N characters of the input string (chosen at run-time), and maps them into musical notes (starting from A one octave below middle C) like so:
a->A
b->A#
c->B
...
z->A#
where 'z' ends up on A#-6
, the A-sharp above middle-C (B-6
is used for non-alphabetical characters). The program plays one chord at a time (by default it plays a single note based on only the first letter).
To extend this program, the natural language processing toolkit for python could be employed to find rhythms in the text, rather than playing each note with the same time interval. And a better mapping might be found based on the meaning of words rather than just the letters which compose it.
As it stands, this program basically preserves the alliterations in text and nothing more.
Run python test.py --help
to get instructions for how to run the program...
NOTE: This README is meant to be understood by an absolute beginner as this project is mainly scaffolding for a friend. If you are more techinically savvy, just take a look at the short setup script and you should see how to run thigs pretty easily.
To set this up you need to open your Terminal program... Hit Command+Space and type Terminal and hit enter, a little window will pop up.
In the window type
mkdir text_to_music
cd text_to_music
open ./
That should pop up a little finder window in a new directory you made.
Then on this github page, click on the "Clone or Download" button on the upper right of this list of files and click Download as Zip. Unzip the contents in the new folder you made and go back to the terminal.
It's probably easiest from here to just run
source setup.sh
But just for the sake of documentation, that script will download a few software dependancies for you.
First you need "Homebrew", which will let you download fluid-synth, the software that plays notes for us. That's accomplished by typing
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
and hitting enter. Then you want to install fluid-synth, this is done by running:
brew install fluid-synth
Then you want to grab a "SoundFont" library. The one I downloaded was from this page, and it's this file. To do this automatically, you'll need wget...
brew install wget
Then you can get the file off my server:
wget http://www.bobak.io/Nice-Keys-B-JNv1.5.sf2
Finally, you need to install 'mingus', which is a front end to fluid-synth and has a lot of other features which can help you make this more musically literate instead of just playing notes based on letters. To do this, you first need 'pip'
sudo easy_install pip
You will have to enter your password there (the letters won't show up on the terminal, but don't worry you are entering characters.)
Once that's done, install mingus
pip install mingus
If an error message pops up here, let me know and I'll show you how to install "virtualenv", which I had to do to get this running, but you might be more lucky.
Otherwise, you are ready to run the program. Just type
python test.py --help
for instructions. Have fun!