gtzan_root = '../GTZAN' import glob glob.glob(gtzan_root + '/genres/*') genres = [genre[genre.rindex('/') + 1:] for genre in glob.glob(gtzan_root + '/genres/*')] genres gtzan_files = dict() for genre in genres: gtzan_files[genre] = glob.glob(gtzan_root + '/genres/' + genre + '/*.au') from essentia.streaming import * sr = 22050 frameSize = 1024 hopSize = 512 loader = MonoLoader(sampleRate=sr) frameCutter = FrameCutter(frameSize = frameSize, hopSize = hopSize) w = Windowing(type = 'hann') spec = Spectrum() centroid = Centroid() rolloff = RollOff() flux = Flux() zcr = ZeroCrossingRate() rms = RMS() # Texture windows textureTime = 1.0 # seconds textureSize = int(textureTime * sr/float(hopSize)) textureWindowCutters = [] textureWindowMeans = [] textureWindowVars = [] for i in range(5): textureWindowCutters.append(FrameCutter(frameSize = textureSize, hopSize = textureSize)) textureWindowMeans.append(Mean()) textureWindowVars.append(Variance()) pool = essentia.Pool() loader.audio >> frameCutter.signal frameCutter.frame >> w.frame >> spec.frame spec.spectrum >> centroid.array spec.spectrum >> rolloff.spectrum spec.spectrum >> flux.spectrum frameCutter.frame >> zcr.signal frameCutter.frame >> rms.array # We won't store the individual features in the pool #centroid.centroid >> (pool, 'lowlevel.centroid') #rolloff.rollOff >> (pool, 'lowlevel.rolloff') #flux.flux >> (pool, 'lowlevel.flux') #zcr.zeroCrossingRate >> (pool, 'lowlevel.zcr') #rms.rms >> (pool, 'lowlevel.rms') # We will keep the testure windows centroid.centroid >> textureWindowCutters[0].signal rolloff.rollOff >> textureWindowCutters[1].signal flux.flux >> textureWindowCutters[2].signal zcr.zeroCrossingRate >> textureWindowCutters[3].signal rms.rms >> textureWindowCutters[4].signal features = ['lowlevel.centroid', 'lowlevel.rolloff', 'lowlevel.flux', 'lowlevel.zcr', 'lowlevel.rms'] for i in range(5): textureWindowCutters[i].frame >> textureWindowMeans[i].array textureWindowCutters[i].frame >> textureWindowVars[i].array # textureWindowMeans[i].mean >> (pool, '%s_mean'%features[i]) # textureWindowVars[i].variance >> (pool, '%s_var'%features[i]) gtzan_files.keys() gtzan_features = dict() feature_pools = [] pool = essentia.Pool() #for genre in gtzan_files.keys(): genre = 'metal' for audiofile in gtzan_files[genre][:10]: loader.configure(filename = audiofile) pool = essentia.Pool() for i in range(5): textureWindowMeans[i].mean >> (pool, '%s_mean'%features[i]) textureWindowVars[i].variance >> (pool, '%s_var'%features[i]) essentia.run(loader) feature_pools.append(pool) for i in range(5): textureWindowMeans[i].mean.disconnect( (pool, '%s_mean'%features[i]) ) textureWindowVars[i].variance.disconnect( (pool, '%s_mean'%features[i]) ) len(feature_pools) pool1 = feature_pools[1] pool1.containsKey('lowlevel.centroid_mean') pool1['lowlevel.centroid_mean'] len(pool1['lowlevel.centroid_mean']) from keys import mykey from pyechonest import config config.ECHO_NEST_API_KEY=mykey import json json.loads('{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"}, "artist": {"hotttnesss": 0.941778, "id": "ARX6TAQ11C8A415850", "name": "Lady Gaga"}}}') from pyechonest import track ls /home/andres/Music/Messiaen/Turangalila\ Symphonie track_info = track.track_from_filename('/home/andres/Music/Messiaen/Turangalila Symphonie/08 AudioTrack 08.mp3') track_info dir(track_info) track_info.analysis_url import urllib2 import json response = urllib2.urlopen(track_info.analysis_url) data = json.load(response) data.keys() data['track'].keys() analysis = track_info.get_analysis() type(analysis) # Not working? from pyechonest import song results = song.search(artist="Led Zeppelin", title='Rock and Roll', results=3, buckets=['audio_summary']) results version1 = results[0] version1 dir(version1) for v in results: print v.song_hotttnesss, version1.audio_summary f = urllib2.urlopen("http://api.7digital.com/1.2/track/preview?trackid={0}&oauth_consumer_key={1}".format(7digital_id,key)) fh = open('./test.mp3', 'wb') fh.write(f.read()) fh.close() f.close() # from http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/getartist.py import sys import logging import musicbrainz2.webservice as ws import musicbrainz2.model as m logging.basicConfig() logger = logging.getLogger() logger.setLevel(logging.DEBUG) artist_id = '' q = ws.Query() try: # The result should include all official albums. # inc = ws.ArtistIncludes( releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM), tags=True, releaseGroups=True) artist = q.getArtistById(artist_id, inc) except ws.WebServiceError, e: print 'Error:', e sys.exit(1) print "Id :", artist.id print "Name :", artist.name print "SortName :", artist.sortName print "UniqueName :", artist.getUniqueName() print "Type :", artist.type print "BeginDate :", artist.beginDate print "EndDate :", artist.endDate print "Tags :", ', '.join([t.value for t in artist.tags]) print if len(artist.getReleases()) == 0: print "No releases found." else: print "Releases:" for release in artist.getReleases(): print print "Id :", release.id print "Title :", release.title print "ASIN :", release.asin print "Text :", release.textLanguage, '/', release.textScript print "Types :", release.types if len(artist.getReleaseGroups()) == 0: print print "No release groups found." else: print print "Release groups:" for rg in artist.getReleaseGroups(): print print "Id :", rg.id print "Title :", rg.title print "Type :", rg.type print # # Using the release IDs and Query.getReleaseById(), you could now request # those releases, including the tracks, release events, the associated # DiscIDs, and more. The 'getrelease.py' example shows how this works. # # EOF import pylast #At http://code.google.com/p/pylast/ from keys import lastfm_api_key, lastfm_api_secret, lastfm_username, lastfm_password # You have to have your own unique two values for API_KEY and API_SECRET # Obtain yours from http://www.last.fm/api/account for Last.fm API_KEY = lastfm_api_key API_SECRET = lastfm_api_secret # In order to perform a write operation you need to authenticate yourself username = lastfm_username password_hash = pylast.md5(lastfm_password) network = pylast.LastFMNetwork(api_key = API_KEY, api_secret = API_SECRET, username = username, password_hash = password_hash) # now you can use that object every where artist = network.get_artist("The Beatles") #artist.shout("<3") track = network.get_track("Iron Maiden", "The Nomad") #track.love() #track.add_tags(("awesome", "favorite")) # type help(pylast.LastFMNetwork) or help(pylast) in a python interpreter to get more help # about anything and see examples of how it works artist.get_listener_count() albums = artist.get_top_albums() help(albums[0]) help(albums[0].item) for album in albums: print album.item.get_title() + ', ', import urllib2 import json artist = 'The Beatles' ret_format = 'json' query_url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getTags&artist=%s&user=%s&api_key=%s&format=json' % (artist, lastfm_username, lastfm_api_key) response = urllib2.urlopen(query_url) data = json.load(response) artist_enc = urllib2.quote(artist) artist_enc query_url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getTags&artist=%s&user=%s&api_key=%s&format=json' % (artist_enc, lastfm_username, lastfm_api_key) response = urllib2.urlopen(query_url) data = json.load(response) data artist = 'Lady Gaga' artist_enc = urllib2.quote(artist) artist_enc query_url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getTags&artist=%s&user=%s&api_key=%s&format=json' % (artist_enc, lastfm_username, lastfm_api_key) response = urllib2.urlopen(query_url) data = json.load(response) data artist = 'The Beatles' artist_enc = urllib2.quote(artist) artist_enc query_url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getTopTags&artist=%s&user=%s&api_key=%s&format=json' % (artist_enc, lastfm_username, lastfm_api_key) response = urllib2.urlopen(query_url) data = json.load(response) data for tag in data['toptags']['tag']: print tag for tag in data['toptags']['tag']: print tag['name'], ':', int(tag['count']) artist = 'The Beatles' artist_enc = urllib2.quote(artist) artist_enc query_url = 'http://ws.audioscrobbler.com/2.0/?method=artist.getTopTracks&artist=%s&user=%s&api_key=%s&format=json' % (artist_enc, lastfm_username, lastfm_api_key) response = urllib2.urlopen(query_url) data = json.load(response) #data data.keys() data['toptracks'].keys() len(data['toptracks']['track']) for track in data['toptracks']['track']: print "'%s', "%track['name'] data['toptracks']['track'][0].keys() track_name = data['toptracks']['track'][0]['name'] track_enc = urllib2.quote(track_name) query_url = 'http://ws.audioscrobbler.com/2.0/?method=track.getTopTags&track=%s&user=%s&api_key=%s&format=json' % (track_enc, lastfm_username, lastfm_api_key) response = urllib2.urlopen(query_url) tags_data = json.load(response) tags_data track_name = data['toptracks']['track'][0]['name'] track_enc = urllib2.quote(track_name) query_url = 'http://ws.audioscrobbler.com/2.0/?method=track.getTopTags&artist=%s&track=%s&user=%s&api_key=%s&format=json' % (artist_enc, track_enc, lastfm_username, lastfm_api_key) response = urllib2.urlopen(query_url) tags_data = json.load(response) tags_data