import essentia.standard as ess
import librosa
import glob
from pyechonest import config
rcParams['figure.figsize'] = (16,4)
myLib = glob.glob('/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/*')
config.ECHO_NEST_API_KEY="YOUR_API_KEY"
myLib
['/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/grooveReady.wav', '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/jayZ.wav', '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/mozart.wav', '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/radiohead.wav', '/Users/milrober/Desktop/MIR/Code/240E_Homework/samples/strauss.wav']
songs = []
for song in myLib:
loader = ess.MonoLoader(filename=song)
s = loader()
songs.append(s)
def computeFeature(audio, feature):
feature_array = []
for a in audio:
feature_array.append(feature(a))
return feature_array
Beat Tracking Degara http://essentia.upf.edu/documentation/reference/std_BeatTrackerDegara.html
beatTracker = ess.BeatTrackerDegara()
beats = computeFeature(songs, beatTracker)
beats[1] #Jay-Z 'Holy Grail'
array([ 0.8243084 , 1.68344665, 2.49614501, ..., 336.57324219, 337.04925537, 337.52526855], dtype=float32)
Beat Tracker Multi Feature http://essentia.upf.edu/documentation/reference/std_BeatTrackerMultiFeature.html
beatTracMultFeat = ess.BeatTrackerMultiFeature()
beatsMF = computeFeature(songs, beatTracMultFeat)
beatsMF[1]
(array([ 0.83591837, 1.68344665, 2.49614501, 3.29723358, 4.09832191, 4.87619019, 5.677279 , 6.45514727, 7.24462557, 8.03410435, 8.82358265, 9.61306095, 10.40253925, 11.19201756, 11.98149681, 12.77097511, 13.56045341, 14.34993172, 15.13941002, 15.91727829, 16.71836662, 17.50784492, 18.2857132 , 19.0751915 , 19.86467171, 20.66576004, 21.45523834, 22.24471664, 23.05741501, 23.84689331, 24.63637161, 25.41423988, 26.20371819, 26.98158646, 27.75945473, 28.56054306, 29.35002136, 30.13949966, 30.91736984, 31.69523811, 32.48471451, 33.27419281, 34.06367111, 34.85314941, 35.64263153, 36.43210983, 37.22158813, 38.01106644, 38.80054474, 39.59002304, 40.39110947, 41.18058777, 41.97006607, 42.75954437, 43.54902267, 44.33850098, 45.12797928, 45.90584946, 46.69532776, 47.496418 , 48.29750443, 49.08698273, 49.87646103, 50.66593933, 51.45541763, 52.23328781, 53.02276611, 53.80063248, 54.59011078, 55.37958908, 56.16906738, 56.9585495 , 57.7480278 , 58.54911423, 59.33859253, 60.12807083, 60.91754913, 61.69541931, 62.48489761, 63.27437592, 64.0638504 , 64.85333252, 65.65441895, 66.44390106, 67.23337555, 68.02285767, 68.81233215, 69.60181427, 70.37968445, 71.157547 , 71.94702911, 72.75972748, 73.5608139 , 74.35029602, 75.13977051, 75.92925262, 76.71872711, 77.49659729, 78.28607941, 79.07555389, 79.86503601, 80.6545105 , 81.44399261, 82.22185516, 82.99972534, 83.80081177, 84.59029388, 85.37976837, 86.16925049, 86.97033691, 87.75981903, 88.54929352, 89.33877563, 90.12825012, 90.91773224, 91.70720673, 92.49668884, 93.28616333, 94.07564545, 94.86511993, 95.65460205, 96.44407654, 97.23355865, 98.02303314, 98.80090332, 99.59038544, 100.36825562, 101.16934204, 101.97042847, 102.77151489, 103.56099701, 104.33886719, 105.11672974, 105.90621185, 106.69568634, 107.48516846, 108.27464294, 109.06412506, 109.85360718, 110.64308167, 111.42095184, 112.21042633, 113.01152039, 113.78938293, 114.57886505, 115.37995148, 116.16943359, 116.95890808, 117.75999451, 118.54947662, 119.33895111, 120.11682129, 120.90630341, 121.69577789, 122.48526001, 123.2747345 , 124.07582855, 124.8536911 , 125.64317322, 126.44425964, 127.24534607, 128.02322388, 128.80108643, 129.59056091, 130.3800354 , 131.16952515, 131.95899963, 132.74847412, 133.52635193, 134.32743835, 135.11691284, 135.90638733, 136.69587708, 137.4969635 , 138.28643799, 139.07591248, 139.86538696, 140.65487671, 141.4443512 , 142.23382568, 143.02331543, 143.81278992, 144.59065247, 145.38012695, 146.1696167 , 146.97070312, 147.76017761, 148.53804016, 149.33914185, 150.11700439, 150.90647888, 151.68435669, 152.47383118, 153.2749176 , 154.07600403, 154.85388184, 155.63174438, 156.40960693, 157.21069336, 158.01179504, 158.80126953, 159.59074402, 160.38021851, 161.15809631, 161.93595886, 162.73704529, 163.52653503, 164.32762146, 165.11709595, 165.91818237, 166.70765686, 167.49714661, 168.28662109, 169.06448364, 169.85395813, 170.64344788, 171.43292236, 172.22239685, 173.01187134, 173.81297302, 174.60244751, 175.38031006, 176.1697998 , 176.97088623, 177.76036072, 178.53822327, 179.32771301, 180.1171875 , 180.91827393, 181.70774841, 182.50883484, 183.29832458, 184.08779907, 184.86566162, 185.64353943, 186.42140198, 187.2224884 , 188.02357483, 188.82466125, 189.62576294, 190.41523743, 191.20471191, 191.98257446, 192.76045227, 193.54992676, 194.33940125, 195.12889099, 195.90675354, 196.69622803, 197.47410583, 198.26358032, 199.06466675, 199.85414124, 200.65522766, 201.45632935, 202.23419189, 203.02366638, 203.81314087, 204.60263062, 205.3921051 , 206.18157959, 206.9594574 , 207.73731995, 208.53840637, 209.3394928 , 210.12898254, 210.91845703, 211.70793152, 212.49740601, 213.28689575, 214.07637024, 214.86584473, 215.64370728, 216.43319702, 217.22267151, 218.012146 , 218.80163574, 219.57949829, 220.38058472, 221.18167114, 221.97114563, 222.76063538, 223.55010986, 224.32797241, 225.10585022, 225.95336914, 226.83573914, 227.71809387, 228.61206055, 229.50602722], dtype=float32), 2.463263750076294)
Beatogram & Beats Loudness http://essentia.upf.edu/documentation/reference/std_Beatogram.html
I'm not sure what I'm doing wrong here:
beatsLoudness = ess.BeatsLoudness()
beatogram = ess.Beatogram()
beatsLoudness(songs[1])
(array([], dtype=float32), [])
Tempo Detection in Librosa
signal, sr = librosa.load(myLib[1], sr=44100)
/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 frame = frame[s_start - n_prev : ]
onsets = librosa.onset.onset_strength(signal)
tempo = librosa.beat.estimate_tempo(onsets, sr=sr)
print round(tempo)
145.0
/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 return result[:max_size]
Correct according to Echo Nest:
#Query tempo from the Echo Nest API
from pyechonest import song as ensong
results = ensong.search(artist='jay-z',title='holy grail')
holy_grail = results[0]
print 'tempo:',holy_grail.audio_summary['tempo'],'duration:',holy_grail.audio_summary['duration']
tempo: 145.04 duration: 338.39955
Let's try a radiohead song:
signal, sr = librosa.load(myLib[3], sr=44100)
/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 frame = frame[s_start - n_prev : ]
onsets = librosa.onset.onset_strength(signal)
tempo = librosa.beat.estimate_tempo(onsets, sr=sr)
print round(tempo)
128.0
/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 return result[:max_size]
results = ensong.search(artist='radiohead',title='lotus flower')
lotus_flower = results[0]
print 'tempo:',lotus_flower.audio_summary['tempo'],'duration:',lotus_flower.audio_summary['duration']
tempo: 128.0 duration: 300.30077
On a scale from 0 to 1, 1 being the most danceable
result = ensong.search(artist='radiohead',title='lotus flower')
lotus_flower = result[0]
print 'On a scale of 0 to 1, Lotus Flower is ',lotus_flower.audio_summary['danceability'], 'daceable according to EN'
On a scale of 0 to 1, Lotus Flower is 0.724149 daceable according to EN
danceability = ess.Danceability()
print danceability(songs[3]) / 3 #normalizing to 1
0.348730484645
for i, song in enumerate(songs):
print myLib[i][55:], 's danceability is', danceability(song) / 3
grooveReady.wav s danceability is 0.467631181081 jayZ.wav s danceability is 0.48052239418 mozart.wav s danceability is 0.384332537651 radiohead.wav s danceability is 0.348730484645 strauss.wav s danceability is 0.265775263309