{"id":4735,"date":"2020-12-20T19:29:38","date_gmt":"2020-12-20T13:59:38","guid":{"rendered":"https:\/\/copyassignment.com\/?p=4735"},"modified":"2022-06-18T16:32:28","modified_gmt":"2022-06-18T11:02:28","slug":"create-your-own-music-with-python-coding","status":"publish","type":"post","link":"https:\/\/copyassignment.com\/create-your-own-music-with-python-coding\/","title":{"rendered":"Create your own Music with Python Coding"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>You are here because you want to learn to create your own Music with Python Coding or you are excited to know how someone or you can make music by coding? Right!<\/p>\n\n\n\n<p>And you know what\u2019s the fun part? You don\u2019t need any physical instrument or any type of professional experience to compose your own music with Python.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What do I need<\/strong>?<\/h2>\n\n\n\n<p>To create your own Music with coding or to Create your own Music with Python, make sure that you are pretty familiar with Python Programming and you have an up-to-date browser and an Internet Connection. Nothing else is required. Now, let&#8217;s start to create your own Music with Python Coding Language. Just follow these simple steps below:&#8211;<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Opening Earsketch Programming Environment<\/h2>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>EarSketch is a free educational programming environment. Its core purpose is to teach coding in two widely used languages, Python and Javascript, through music composing and remixing.<\/p>\n\n\n\n<p class=\"has-text-align-center has-medium-font-size\"><a rel=\"noreferrer noopener\" href=\"https:\/\/earsketch.gatech.edu\/landing\/#\/\" target=\"_blank\">Click here<\/a> to go to <strong>Earsketch<\/strong>.<\/p>\n\n\n\n<p>From there, click on &#8220;<strong>Start Coding<\/strong>&#8221; to land on the Programming Interface.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>When you click on Start Coding, You will land on a page that must be looking like this:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>From this point, you can Either choose to start your tour to get familiar with the Earsketch Environment.<\/p>\n\n\n\n<p>But, I am skipping the tour. So, when you click on Skip\u2026 You must be seeing something like this :<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Now, You have to click on Create a New Script, It will pop up a dialog box like this, where it will ask you the name of the Script and Script Language, As we are using Python to code here so, choose the scripting language to be Python :<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>So, When you click on Create, you will see that there is some pre-written code in the Code Editor, that is :<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"20\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># python code\n# script_name:\n#\n# author:\n# description:\n#\nfrom earsketch import *\ninit()\nsetTempo(120)\nfinish()<\/pre><\/div>\n\n\n\n<p>Here, It imports everything from earsketch using, \u201cfrom earsketch import *\u201d<br>Then it initializes the whole library using \u201cinit()\u201d And then, there is \u201csetTempo(120)\u201d- So, Tempo means the speed of the soundtrack and it is measured in beats per minute (BPM). And setTempo sets the speed of the soundtrack. So, by default, we get it as 120. So we will let it remain the same.<br>And then there is a \u201cfinish()\u201d in the end, what it does is that it ends the<br>soundtrack.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">STEP 2: Let\u2019s create a list of the sound clips that we need in our music<\/h2>\n\n\n\n<p>As you can see, there is a Content Manager which has 3,600 sound clips that are produced from various instruments and that we can use in making our own music, without getting any copyright strike. You can browse and preview all the clips and then add them according to your own taste. The sound clips that we are gonna use in this project are added to a list named as sounds are below, but feel free to use any sound clip you like.<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">sounds=[YG_TRAP_BRASS_1,YG_TRAP_BRASS_2,YG_TRAP_BRASS_3,YG_TRAP_BRA\nSS_4,YG_TRAP_BRASS_5,HIPHOP_BASSSUB_001,RD_RNB_SFX_TONEBASS_\n1,YG_NEW_HIP_HOP_BASS_1,Y07_BASS]\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<p>You can copy this above sounds list inside your code editor.<br>Now, It\u2019s time to play some music!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">STEP 3: Playing Music<\/h2>\n\n\n\n<p>Now, we will be playing some music. And the whole sound playing code that we are gonna write is gonna be between setTempo(120) and finish(). But before that, I want to let you know the function that we are gonna use.<\/p>\n\n\n\n<p>We are going to use the \u201cfitMedia()\u201d function to add your sound clip into the<br>Digital Audio Workstation (DAW) provided to us.<\/p>\n\n\n\n<div class=\"maindiv\"><h2>Syntax:<\/h2><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">fitMedia(&lt;Track_Name&gt;, &lt;Track_Number&gt;, &lt;Starting_Point&gt;,\n&lt;Ending_Point&gt;\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<p>So we already have our track names stored in our sounds list, now we can simply access them with the help of their index number.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>So, now here is an example for you,<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">fitMedia(sounds[0], 1, 1, 3)\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<p>Now what this will do, It\u2019s gonna fit the first track in our sounds list in the Digital Audio Workstation, at Track number 1, from 1st point to the 3rd point.<\/p>\n\n\n\n<p>Now, that\u2019s how we are gonna add other clips to our DAW. But remember that two clips at the same track number, with overlapping Starting and Ending points, can cause a problem to your composed music.<\/p>\n\n\n\n<p>In this project, we want that the whole clip should be of 15 points, i.e. around 28 seconds and we want the Brass tracks (From sounds list 0-4th index) to be played from the point where the previous track ended and all the tracks are gonna be of 3 points each, i.e. around 4 and 1\/2 seconds each.<br>So, what our code is gonna look like :<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">fitMedia(sounds[0], 1, 1, 3)\nfitMedia(sounds[1], 2, 3, 6)\nfitMedia(sounds[2], 3, 6, 9)\nfitMedia(sounds[3], 4, 9, 12)\nfitMedia(sounds[4], 5, 12, 15)\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<p>As you can see, we have made the ending point of the previous track as the starting point of the next track. And also that we have put all the clips in consecutive track numbers.<br>Let\u2019s run this:<br>                You must be able to see something like this in your DAW.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Play it and listen to it.<\/strong><\/h3>\n\n\n\n<p><strong><br><\/strong>            Now, let\u2019s add other clips also to our music.<br>I am gonna add the Hip-Hop Bass Beats to our music from the 8<sup>th<\/sup> point till the end, i.e. the 15<sup>th<\/sup> point. So, I am gonna add:<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">fitMedia(sounds[5], 6, 8,15)\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Run and listen to it.<\/strong><\/h3>\n\n\n\n<p><strong><br><\/strong>            Now, we will add the code for the sound clip at the 6th index, i.e. Tone Bass (RD_RNB_SFX_TONEBASS_1). And we will play it from the 2nd point till the end of the clip.<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">fitMedia(sounds[6], 7, 2, 15)\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Run and listen to it.<\/strong><\/h3>\n\n\n\n<p class=\"has-medium-font-size\"><strong><br><\/strong>Now we will add soft bass to our whole track. This sound clip is at the 7th index of our sounds list. Add the below code:<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">fitMedia(sounds[7], 8, 1, 15)\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Run and listen to it. <\/strong><\/h3>\n\n\n\n<p><\/p>\n\n\n\n<p>Now we will be adding the last clip to our music, i.e. some hard bass from the 1st point till the 8th point because after that we have already put an awesome bass drop sound clip and we are gonna give this clip a fade-in effect also by using a function called <strong>setEffect()<\/strong>. <\/p>\n\n\n\n<p>We can use many effects in this <strong>setEffect()<\/strong> function, like <strong>VOLUME<\/strong>, <strong>DELAY<\/strong>, <strong>DISTORTION<\/strong>, <strong>PITCH<\/strong>, etc. <\/p>\n\n\n\n<p>But as we are going to make a Fade in effect, we will be using the VOLUME effect, and it\u2019s GAIN effect parameter. Because we want the clip to gain volume from low volume to the normal volume.<\/p>\n\n\n\n<p> <strong>setEffect() <\/strong>takes 7 arguments, that are:<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">setEffect(&lt;Track_Number_Where_Effect_is_to_be_added&gt;, \n&lt;EFFECT&gt;,&lt;EFFECT PARAMETER&gt;, START, START_POINT, END, END_POINT)\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<p>Now, let\u2019s write the code for it!<\/p>\n\n\n\n<div class=\"maindiv\"><div class=\"codediv\"><strong><pre style=\"color:#cf2e2e;\">fitMedia(sounds[8], 9, 1, 8)\nsetEffect( 9, VOLUME, GAIN, -30, 1, 0, 8)\n<\/pre><\/strong>\n<\/div><\/div>\n\n\n\n<p>The above code, adds the bass soundtrack to your DAW and the setEffect()<br>acts on the 9<sup>th <\/sup>track by Gaining the Volume from -30 dB to 0dB, between 1<sup>st<\/sup> point to the 8<sup>th <\/sup>point.<\/p>\n\n\n\n<p>So, add it and then run it.<br>The final code snippet must have been looking like this:<\/p>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><div style=\"position:absolute;top:-20px;right:0px;cursor:pointer\" class=\"copy-simple-code-block\"><span class=\"dashicon dashicons dashicons-admin-page\"><\/span><\/div><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"python\" data-theme=\"xcode\" data-fontsize=\"18\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"true\"># python code\n# script_name:\n#\n# author:\n# description:\n#\nfrom earsketch import *\ninit()\nsetTempo(120)\nsounds =\n[YG_TRAP_BRASS_1,YG_TRAP_BRASS_2,YG_TRAP_BRASS_3,YG_TRAP_BRA\nSS_4,YG_TRAP_BRASS_5,HIPHOP_BASSSUB_001,RD_RNB_SFX_TONEBASS_\n1,YG_NEW_HIP_HOP_BASS_1,Y07_BASS]\nfitMedia(sounds[0], 1, 1, 3)\nfitMedia(sounds[1], 2, 3, 6)\nfitMedia(sounds[2], 3, 6, 9)\nfitMedia(sounds[3], 4, 9, 12)\nfitMedia(sounds[4], 5, 12, 15)\nfitMedia(sounds[5], 6, 8,15)\nfitMedia(sounds[6], 7, 2, 15)\nfitMedia(sounds[7], 8, 1, 15)\nfitMedia(sounds[8], 9, 1, 8)\nsetEffect( 9, VOLUME, GAIN, -30, 1, 0, 8)\nfinish()<\/pre><\/div>\n\n\n\n<p>And your final DAW of our &#8220;Create your own Music with Python&#8221; project must have been looking like this:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<script async=\"\" src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\n<ins class=\"adsbygoogle\" style=\"display:block; text-align:center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-9886351916045880\" data-ad-slot=\"2002566052\"><\/ins>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>See, what I made, check this video<\/strong>:<\/h3>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<center><iframe width=\"560\" height=\"315\" data-src=\"https:\/\/www.youtube.com\/embed\/CLUREN_LJaM\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe><\/center>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Listen to the final Music\u2026 Good huh!<\/p>\n\n\n\n<p>Well, this article was just to give you a basic understanding of how to use Earsketch and Create your own Music with Python.<\/p>\n\n\n\n<p>You can do a lot more than this. There is a lot of function available to do many cool things, like making your own beat, that will help you to make a remix of songs. You can also add your local audio files in your DAW. There<br>are a lot of things that you can explore. Keep exploring new things. <\/p>\n\n\n\n<p>Our team hopes for your Magnificent Journey in Coding.<br>Hope you liked this article.<br>Thank You!<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p style=\"font-size:22px\"><strong>Also Read:<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><a href=\"https:\/\/copyassignment.com\/python-turtle-design-of-spiral-square-and-hexagon\/\">Python Turtle Design of Spiral Square and Hexagon<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/copyassignment.com\/colored-hexagons-turtle-design\/\">Colored Hexagons Turtle Design<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/copyassignment.com\/shutdown-computer-with-voice-python\/\">Shutdown Computer with Voice in Python<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/copyassignment.com\/guess-the-number-python\/\">Guess the Number Python<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/copyassignment.com\/snake-game-in-python-using-pygame\/\">Snake Game in Python using Pygame<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/copyassignment.com\/crack-any-password-using-python\/\">Crack Any Password Using Python<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/copyassignment.com\/get-wifi-passwords-with-python\/\">Get WiFi Passwords With Python<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n","protected":false},"excerpt":{"rendered":"<p>You are here because you want to learn to create your own Music with Python Coding or you are excited to know how someone or&#8230;<\/p>\n","protected":false},"author":1,"featured_media":12759,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,1403],"tags":[1140,1139,1138],"class_list":["post-4735","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allcategorites","category-python-projects","tag-create-your-own-music-with-coding","tag-create-your-own-music-with-python","tag-create-your-own-music-with-python-coding","wpcat-22-id","wpcat-1403-id"],"_links":{"self":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/4735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/comments?post=4735"}],"version-history":[{"count":0,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/posts\/4735\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media\/12759"}],"wp:attachment":[{"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/media?parent=4735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/categories?post=4735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/copyassignment.com\/wp-json\/wp\/v2\/tags?post=4735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}