-
-
Save hyperaeolian/b2a9fd7789631e785f70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "Homework 5" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "import essentia.standard as ess\nimport librosa\nimport glob\nfrom pyechonest import config", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "rcParams['figure.figsize'] = (16,4)\nmyLib = glob.glob('/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/*')\nconfig.ECHO_NEST_API_KEY=\"YOUR_API_KEY\"", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "myLib", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 3, | |
"text": "['/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/grooveReady.wav',\n '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/jayZ.wav',\n '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/mozart.wav',\n '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/radiohead.wav',\n '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/strauss.wav']" | |
} | |
], | |
"prompt_number": 3 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "songs = []\nfor song in myLib:\n loader = ess.MonoLoader(filename=song)\n s = loader()\n songs.append(s)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 4 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "def computeFeature(audio, feature):\n feature_array = []\n for a in audio:\n feature_array.append(feature(a))\n return feature_array", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 12 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Beat Tracking Degara\nhttp://essentia.upf.edu/documentation/reference/std_BeatTrackerDegara.html" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beatTracker = ess.BeatTrackerDegara()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 6 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beats = computeFeature(songs, beatTracker)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 7 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beats[1] #Jay-Z 'Holy Grail'", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 8, | |
"text": "array([ 0.8243084 , 1.68344665, 2.49614501, ..., 336.57324219,\n 337.04925537, 337.52526855], dtype=float32)" | |
} | |
], | |
"prompt_number": 8 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Beat Tracker Multi Feature http://essentia.upf.edu/documentation/reference/std_BeatTrackerMultiFeature.html" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beatTracMultFeat = ess.BeatTrackerMultiFeature()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 10 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beatsMF = computeFeature(songs, beatTracMultFeat)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 13 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beatsMF[1]", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 14, | |
"text": "(array([ 0.83591837, 1.68344665, 2.49614501, 3.29723358,\n 4.09832191, 4.87619019, 5.677279 , 6.45514727,\n 7.24462557, 8.03410435, 8.82358265, 9.61306095,\n 10.40253925, 11.19201756, 11.98149681, 12.77097511,\n 13.56045341, 14.34993172, 15.13941002, 15.91727829,\n 16.71836662, 17.50784492, 18.2857132 , 19.0751915 ,\n 19.86467171, 20.66576004, 21.45523834, 22.24471664,\n 23.05741501, 23.84689331, 24.63637161, 25.41423988,\n 26.20371819, 26.98158646, 27.75945473, 28.56054306,\n 29.35002136, 30.13949966, 30.91736984, 31.69523811,\n 32.48471451, 33.27419281, 34.06367111, 34.85314941,\n 35.64263153, 36.43210983, 37.22158813, 38.01106644,\n 38.80054474, 39.59002304, 40.39110947, 41.18058777,\n 41.97006607, 42.75954437, 43.54902267, 44.33850098,\n 45.12797928, 45.90584946, 46.69532776, 47.496418 ,\n 48.29750443, 49.08698273, 49.87646103, 50.66593933,\n 51.45541763, 52.23328781, 53.02276611, 53.80063248,\n 54.59011078, 55.37958908, 56.16906738, 56.9585495 ,\n 57.7480278 , 58.54911423, 59.33859253, 60.12807083,\n 60.91754913, 61.69541931, 62.48489761, 63.27437592,\n 64.0638504 , 64.85333252, 65.65441895, 66.44390106,\n 67.23337555, 68.02285767, 68.81233215, 69.60181427,\n 70.37968445, 71.157547 , 71.94702911, 72.75972748,\n 73.5608139 , 74.35029602, 75.13977051, 75.92925262,\n 76.71872711, 77.49659729, 78.28607941, 79.07555389,\n 79.86503601, 80.6545105 , 81.44399261, 82.22185516,\n 82.99972534, 83.80081177, 84.59029388, 85.37976837,\n 86.16925049, 86.97033691, 87.75981903, 88.54929352,\n 89.33877563, 90.12825012, 90.91773224, 91.70720673,\n 92.49668884, 93.28616333, 94.07564545, 94.86511993,\n 95.65460205, 96.44407654, 97.23355865, 98.02303314,\n 98.80090332, 99.59038544, 100.36825562, 101.16934204,\n 101.97042847, 102.77151489, 103.56099701, 104.33886719,\n 105.11672974, 105.90621185, 106.69568634, 107.48516846,\n 108.27464294, 109.06412506, 109.85360718, 110.64308167,\n 111.42095184, 112.21042633, 113.01152039, 113.78938293,\n 114.57886505, 115.37995148, 116.16943359, 116.95890808,\n 117.75999451, 118.54947662, 119.33895111, 120.11682129,\n 120.90630341, 121.69577789, 122.48526001, 123.2747345 ,\n 124.07582855, 124.8536911 , 125.64317322, 126.44425964,\n 127.24534607, 128.02322388, 128.80108643, 129.59056091,\n 130.3800354 , 131.16952515, 131.95899963, 132.74847412,\n 133.52635193, 134.32743835, 135.11691284, 135.90638733,\n 136.69587708, 137.4969635 , 138.28643799, 139.07591248,\n 139.86538696, 140.65487671, 141.4443512 , 142.23382568,\n 143.02331543, 143.81278992, 144.59065247, 145.38012695,\n 146.1696167 , 146.97070312, 147.76017761, 148.53804016,\n 149.33914185, 150.11700439, 150.90647888, 151.68435669,\n 152.47383118, 153.2749176 , 154.07600403, 154.85388184,\n 155.63174438, 156.40960693, 157.21069336, 158.01179504,\n 158.80126953, 159.59074402, 160.38021851, 161.15809631,\n 161.93595886, 162.73704529, 163.52653503, 164.32762146,\n 165.11709595, 165.91818237, 166.70765686, 167.49714661,\n 168.28662109, 169.06448364, 169.85395813, 170.64344788,\n 171.43292236, 172.22239685, 173.01187134, 173.81297302,\n 174.60244751, 175.38031006, 176.1697998 , 176.97088623,\n 177.76036072, 178.53822327, 179.32771301, 180.1171875 ,\n 180.91827393, 181.70774841, 182.50883484, 183.29832458,\n 184.08779907, 184.86566162, 185.64353943, 186.42140198,\n 187.2224884 , 188.02357483, 188.82466125, 189.62576294,\n 190.41523743, 191.20471191, 191.98257446, 192.76045227,\n 193.54992676, 194.33940125, 195.12889099, 195.90675354,\n 196.69622803, 197.47410583, 198.26358032, 199.06466675,\n 199.85414124, 200.65522766, 201.45632935, 202.23419189,\n 203.02366638, 203.81314087, 204.60263062, 205.3921051 ,\n 206.18157959, 206.9594574 , 207.73731995, 208.53840637,\n 209.3394928 , 210.12898254, 210.91845703, 211.70793152,\n 212.49740601, 213.28689575, 214.07637024, 214.86584473,\n 215.64370728, 216.43319702, 217.22267151, 218.012146 ,\n 218.80163574, 219.57949829, 220.38058472, 221.18167114,\n 221.97114563, 222.76063538, 223.55010986, 224.32797241,\n 225.10585022, 225.95336914, 226.83573914, 227.71809387,\n 228.61206055, 229.50602722], dtype=float32),\n 2.463263750076294)" | |
} | |
], | |
"prompt_number": 14 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Beatogram & Beats Loudness http://essentia.upf.edu/documentation/reference/std_Beatogram.html<br>\nI'm not sure what I'm doing wrong here:" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beatsLoudness = ess.BeatsLoudness()\nbeatogram = ess.Beatogram()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 15 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "beatsLoudness(songs[1])", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"metadata": {}, | |
"output_type": "pyout", | |
"prompt_number": 16, | |
"text": "(array([], dtype=float32), [])" | |
} | |
], | |
"prompt_number": 16 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": "Tempo" | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Tempo Detection in Librosa" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "signal, sr = librosa.load(myLib[1], sr=44100)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": "/usr/local/lib/python2.7/site-packages/librosa/core.py:105: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n frame = frame[s_start - n_prev : ]\n" | |
} | |
], | |
"prompt_number": 17 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "onsets = librosa.onset.onset_strength(signal)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 18 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "tempo = librosa.beat.estimate_tempo(onsets, sr=sr)\nprint round(tempo)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "145.0\n" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": "/usr/local/lib/python2.7/site-packages/librosa/core.py:1182: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n return result[:max_size]\n" | |
} | |
], | |
"prompt_number": 19 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Correct according to Echo Nest:" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "#Query tempo from the Echo Nest API\nfrom pyechonest import song as ensong\nresults = ensong.search(artist='jay-z',title='holy grail')\nholy_grail = results[0]\nprint 'tempo:',holy_grail.audio_summary['tempo'],'duration:',holy_grail.audio_summary['duration']", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "tempo: " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "145.04 duration: 338.39955\n" | |
} | |
], | |
"prompt_number": 21 | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "Let's try a radiohead song:" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "signal, sr = librosa.load(myLib[3], sr=44100)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": "/usr/local/lib/python2.7/site-packages/librosa/core.py:105: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n frame = frame[s_start - n_prev : ]\n" | |
} | |
], | |
"prompt_number": 22 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "onsets = librosa.onset.onset_strength(signal)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 23 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "tempo = librosa.beat.estimate_tempo(onsets, sr=sr)\nprint round(tempo)", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "128.0\n" | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stderr", | |
"text": "/usr/local/lib/python2.7/site-packages/librosa/core.py:1182: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future\n return result[:max_size]\n" | |
} | |
], | |
"prompt_number": 24 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "results = ensong.search(artist='radiohead',title='lotus flower')\nlotus_flower = results[0]\nprint 'tempo:',lotus_flower.audio_summary['tempo'],'duration:',lotus_flower.audio_summary['duration']", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "tempo: " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "128.0 duration: 300.30077\n" | |
} | |
], | |
"prompt_number": 25 | |
}, | |
{ | |
"cell_type": "heading", | |
"level": 3, | |
"metadata": {}, | |
"source": "Danceability http://essentia.upf.edu/documentation/reference/std_Danceability.html" | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": "On a scale from 0 to 1, 1 being the most danceable" | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "result = ensong.search(artist='radiohead',title='lotus flower')\nlotus_flower = result[0]\nprint 'On a scale of 0 to 1, Lotus Flower is ',lotus_flower.audio_summary['danceability'], 'daceable according to EN'", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "On a scale of 0 to 1, Lotus Flower is " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "0.724149 daceable according to EN\n" | |
} | |
], | |
"prompt_number": 26 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "danceability = ess.Danceability()", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 27 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "print danceability(songs[3]) / 3 #normalizing to 1", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "0.348730484645\n" | |
} | |
], | |
"prompt_number": 28 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": "for i, song in enumerate(songs):\n print myLib[i][55:], 's danceability is', danceability(song) / 3", | |
"language": "python", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "grooveReady.wav s danceability is " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "0.467631181081\njayZ.wav s danceability is " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "0.48052239418\nmozart.wav s danceability is " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "0.384332537651\nradiohead.wav s danceability is " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "0.348730484645\nstrauss.wav s danceability is " | |
}, | |
{ | |
"output_type": "stream", | |
"stream": "stdout", | |
"text": "0.265775263309\n" | |
} | |
], | |
"prompt_number": 30 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment