{"id":179,"date":"2016-03-12T15:29:04","date_gmt":"2016-03-12T15:29:04","guid":{"rendered":"http:\/\/www.rangakrish.com\/?p=179"},"modified":"2016-03-13T03:53:56","modified_gmt":"2016-03-13T03:53:56","slug":"converting-text-to-music","status":"publish","type":"post","link":"https:\/\/www.rangakrish.com\/index.php\/2016\/03\/12\/converting-text-to-music\/","title":{"rendered":"Converting Text to Music"},"content":{"rendered":"<p>Converting text to music can be fun. <a href=\"https:\/\/opusmodus.com\" target=\"_blank\">Opusmodus<\/a>\u00a0has a few built-in functions to work with text. Look up the description of <strong>text-to-pitch<\/strong>, for example. As described in its documentation,<\/p>\n<p><strong><em>(text-to-pitch &#8216;(&#8220;To be, or not to be, that is the question&#8221;))<\/em><\/strong><\/p>\n<p><strong><em>=&gt; (((g5 d5) (cs4 e4) (d5 f5) (cs5 d5 g5) (g5 d5)<\/em><\/strong><\/p>\n<p><strong><em>\u00a0 \u00a0 (cs4 e4) (g5 g4 c4 g5) (gs4 fs5) (g5g4 e4)<\/em><\/strong><\/p>\n<p><strong><em>\u00a0 \u00a0 (e5 gs5 e4 fs5 g5 gs4 d5 cs5)))<\/em><\/strong><\/p>\n<p>For today\u2019s 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 <strong>Verbs<\/strong> to one pitch and all <strong>Adjectives<\/strong> to another. Of course, there is no guarantee that this simple algorithm yields <em>memorable<\/em> melody, but this gave me an opportunity to check out one of the popular text analysis engines &#8211; <a href=\"https:\/\/www.textrazor.com\" target=\"_blank\">TextRazor<\/a>. You can register with them and get a free API key (you need the key to test my program).<\/p>\n<p>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 &#8211; Drakma and Yason, both of which can be easily obtained via <a href=\"https:\/\/www.quicklisp.org\/beta\/\" target=\"_blank\">Quicklisp<\/a>. You can visit Opusmodus <a href=\"https:\/\/opusmodus.com\/forums\/topic\/309-how-to-install-quicklisp-beta\/\" target=\"_blank\">forum<\/a>\u00a0 to learn how to install Quicklisp.<\/p>\n<p>The following figure shows the\u00a0code fragment.<\/p>\n<figure id=\"attachment_180\" aria-describedby=\"caption-attachment-180\" style=\"width: 710px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music.png\" rel=\"attachment wp-att-180\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" data-attachment-id=\"180\" data-permalink=\"https:\/\/www.rangakrish.com\/index.php\/2016\/03\/12\/converting-text-to-music\/text-to-music\/\" data-orig-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music.png\" data-orig-size=\"825,1211\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Text to Music\" data-image-description=\"&lt;p&gt;Text to Music&lt;\/p&gt;\n\" data-image-caption=\"&lt;p&gt;Text to Music&lt;\/p&gt;\n\" data-large-file=\"https:\/\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music-698x1024.png\" class=\"wp-image-180\" src=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music-204x300.png?resize=710%2C1042\" alt=\"Text to Music\" width=\"710\" height=\"1042\" srcset=\"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music.png?resize=204%2C300&amp;ssl=1 204w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music.png?resize=768%2C1127&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music.png?resize=698%2C1024&amp;ssl=1 698w, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/03\/Text-to-Music.png?w=825&amp;ssl=1 825w\" sizes=\"(max-width: 710px) 100vw, 710px\" \/><\/a><figcaption id=\"caption-attachment-180\" class=\"wp-caption-text\">Text to Music<\/figcaption><\/figure>\n<p>You can download the full source code <a href=\"http:\/\/www.rangakrish.com\/downloads\/text-to-music.opmo\" target=\"_blank\">here<\/a>. Do not forget to substitute your API key in the marked place in the source code, otherwise, the program will not work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Converting text to music can be fun. Opusmodus\u00a0has 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 &#8216;(&#8220;To be, or not to be, that is the question&#8221;)) =&gt; (((g5 d5) (cs4 e4) (d5 f5) (cs5 d5 g5) (g5 d5) \u00a0 \u00a0 (cs4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,5,17],"tags":[46,45],"class_list":["post-179","post","type-post","status-publish","format-standard","hentry","category-lisp","category-music","category-programming","tag-part-of-speech","tag-textrazor"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9OLnF-2T","jetpack-related-posts":[{"id":227,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/05\/10\/generating-melody-to-fit-harmony\/","url_meta":{"origin":179,"position":0},"title":"Generating Melody to Fit Harmony","author":"admin","date":"May 10, 2016","format":false,"excerpt":"There are two common approaches to composing music. One involves synthesizing a suitable chord progression first and then layering melody over it. The other is to start with melody and then harmonize it by applying chords. Of course, you can mix both approaches - use one technique for a portion\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Melody Over Harmony","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/05\/Melody-Over-Harmony-888x1024.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/05\/Melody-Over-Harmony-888x1024.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/05\/Melody-Over-Harmony-888x1024.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/05\/Melody-Over-Harmony-888x1024.png?resize=700%2C400 2x"},"classes":[]},{"id":2242,"url":"https:\/\/www.rangakrish.com\/index.php\/2020\/12\/20\/jfugue-a-java-library-for-music-synthesis\/","url_meta":{"origin":179,"position":1},"title":"JFugue: A Java Library for Music Synthesis","author":"admin","date":"December 20, 2020","format":false,"excerpt":"JFugue\u00a0is an open-source Java library that can be used for algorithmic music composition. Developed by David Koelle, currently it is in its fifth major version. You can get the library from here. I had downloaded the library some time ago, but could not spend much time since my primary focus\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Simple Java Program","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/12\/java-2-300x142.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/12\/java-2-300x142.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2020\/12\/java-2-300x142.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":208,"url":"https:\/\/www.rangakrish.com\/index.php\/2016\/04\/19\/motifs-and-transformations\/","url_meta":{"origin":179,"position":2},"title":"Motifs and Transformations","author":"admin","date":"April 19, 2016","format":false,"excerpt":"One of the creative approaches to synthesizing music is to start with a short melodic motif and then apply various transformations on it. The motif is usually (but not necessarily) of 1 bar duration. What are some possible transformations? This depends on one\u2019s creativity, but here is a simple list:\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Motifs and transformations","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/04\/Motifs-and-transformations.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/04\/Motifs-and-transformations.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/04\/Motifs-and-transformations.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2016\/04\/Motifs-and-transformations.png?resize=700%2C400 2x"},"classes":[]},{"id":2298,"url":"https:\/\/www.rangakrish.com\/index.php\/2021\/01\/31\/using-l-system-to-generate-music\/","url_meta":{"origin":179,"position":3},"title":"Using L-System to Generate Music","author":"admin","date":"January 31, 2021","format":false,"excerpt":"L-system\u00a0is a powerful string rewriting system. Opusmodus\u00a0supports an implementation of this system (inspired by and based on this\u00a0implementation). It is possible to use the L-system to generate anything\u00a0that can be described in terms of an alphabet and a set of rewriting rules.\u00a0 Let us start with a simple example: As\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"Defining an L-system in Opusmodus","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2021\/01\/example1-300x152.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1501,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/03\/20\/controlling-reaktor-from-opusmodus-using-osc\/","url_meta":{"origin":179,"position":4},"title":"Controlling Reaktor from Opusmodus Using OSC","author":"admin","date":"March 20, 2019","format":false,"excerpt":"I am a great fan of Opusmodus\u00a0software. I have written many articles about it in the past. Owing to my several other commitments, I am not able to spend much time on it these days, but I keep checking the features in new releases regularly. The software has evolved substantially\u2026","rel":"","context":"In &quot;LISP&quot;","block_context":{"text":"LISP","link":"https:\/\/www.rangakrish.com\/index.php\/category\/lisp\/"},"img":{"alt_text":"A Simple Sine Oscillator","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/03\/Reaktor-1-1.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/03\/Reaktor-1-1.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/03\/Reaktor-1-1.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/03\/Reaktor-1-1.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1817,"url":"https:\/\/www.rangakrish.com\/index.php\/2019\/12\/08\/using-definite-clause-grammars-dcg-for-information-extraction\/","url_meta":{"origin":179,"position":5},"title":"Using Definite Clause Grammars (DCG) for Information Extraction","author":"admin","date":"December 8, 2019","format":false,"excerpt":"In the previous article, I showed how we can use ATNs for extracting key information from natural language text. I also pointed out in that article that Definite Clause Grammars (DCG) are a more compact formalism for doing this. That will be the focus of today's article. For a nice\u2026","rel":"","context":"In &quot;Natural Language Processing&quot;","block_context":{"text":"Natural Language Processing","link":"https:\/\/www.rangakrish.com\/index.php\/category\/natural-language-processing\/"},"img":{"alt_text":"Processing the Text","src":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/www.rangakrish.com\/wp-content\/uploads\/2019\/12\/Processing-file-code.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":0,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/posts\/179\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rangakrish.com\/index.php\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}