Converting Text to Music

Written by on March 12, 2016 in LISP, Music, Programming with 0 Comments

Converting text to music can be fun. Opusmodus has a few built-in functions to work with text. Look up the description of text-to-pitch, for example. As described in its documentation,

(text-to-pitch ‘(“To be, or not to be, that is the question”))

=> (((g5 d5) (cs4 e4) (d5 f5) (cs5 d5 g5) (g5 d5)

    (cs4 e4) (g5 g4 c4 g5) (gs4 fs5) (g5g4 e4)

    (e5 gs5 e4 fs5 g5 gs4 d5 cs5)))

For today’s experiment, I wanted to do something more adventurous. I am a great enthusiast of NLP and text analysis, so instead of mapping letters to pitch, decided to determine the part of speech of each word and then map that part of speech to pitch. For example, we can map all Verbs to one pitch and all Adjectives to another. Of course, there is no guarantee that this simple algorithm yields memorable melody, but this gave me an opportunity to check out one of the popular text analysis engines – TextRazor. You can register with them and get a free API key (you need the key to test my program).

TextRazor has convenient APIs in Java, Python, etc., but since I am using Lisp, I decided to use their REST API. I needed two other Lisp libraries for this – Drakma and Yason, both of which can be easily obtained via Quicklisp. You can visit Opusmodus forum  to learn how to install Quicklisp.

The following figure shows the code fragment.

Text to Music

Text to Music

You can download the full source code here. Do not forget to substitute your API key in the marked place in the source code, otherwise, the program will not work.

Tags: ,


If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *