コード例 #1
0
def get_en_feats(filename):
    """
    Given a filename from the Tzanetakis dataset, go get the Echo Nest
    features for that file. Features are basically per segment,
    but we have the start time of beats and bars
    INPUT:
       - filename    Tzanetakis file full filename
    OUTPUT:
       - pitches           numpy array (12 x nSegs)
       - segs start time   array
       - beats start time  array
       - bars start time   array
       - duration          in seconds
    """
    entrack = track.upload(filename)
    segs = entrack.segments
    # pitches
    pitches = [s['pitches'] for s in entrack.segments]
    pitches = np.array(pitches).T
    # seg start
    seg_start = np.array([s['start'] for s in entrack.segments])
    # beats start
    beat_start = np.array([b['start'] for b in entrack.beats])
    # bars start
    bar_start = np.array([b['start'] for b in entrack.bars])
    # return
    return pitches, seg_start, beat_start, bar_start, entrack.duration
コード例 #2
0
def get_en_feats(filename):
    """
    Given a filename from the Tzanetakis dataset, go get the Echo Nest
    features for that file. Features are basically per segment,
    but we have the start time of beats and bars
    INPUT:
       - filename    Tzanetakis file full filename
    OUTPUT:
       - pitches           numpy array (12 x nSegs)
       - segs start time   array
       - beats start time  array
       - bars start time   array
       - duration          in seconds
    """
    entrack = track.upload(filename)
    segs = entrack.segments
    # pitches
    pitches = [s['pitches'] for s in entrack.segments]
    pitches = np.array(pitches).T
    # seg start
    seg_start = np.array([s['start'] for s in entrack.segments])
    # beats start
    beat_start = np.array([b['start'] for b in entrack.beats])
    # bars start
    bar_start = np.array([b['start'] for b in entrack.bars])
    # return
    return pitches, seg_start, beat_start, bar_start, entrack.duration
コード例 #3
0
def main():	
    # For each hottt artist...
    for a in artist.get_top_hottt_artists():
        print a.name
        # Get the latest 15 mp3 files EN's crawlers have found
        for audio in a.audio():
            try:
                # Analyze the URL of the file 
                t = track.upload(audio["url"])
                # And print the BPM
                print audio["title"] + " -- " + str(t.tempo["value"])  + " bpm"  # show the tempo
            # You'll see a lot of API Error 5s because mp3 URLs are very transient. Just catch them and move on.
            except util.EchoNestAPIError:
                print "Problem analyzing " + audio["url"]
                pass
コード例 #4
0
def main():
    # For each hottt artist...
    for a in artist.get_top_hottt_artists():
        print a.name
        # Get the latest 15 mp3 files EN's crawlers have found
        for audio in a.audio():
            try:
                # Analyze the URL of the file
                t = track.upload(audio["url"])
                # And print the BPM
                print audio["title"] + " -- " + str(
                    t.tempo["value"]) + " bpm"  # show the tempo
            # You'll see a lot of API Error 5s because mp3 URLs are very transient. Just catch them and move on.
            except util.EchoNestAPIError:
                print "Problem analyzing " + audio["url"]
                pass
コード例 #5
0

    # songfile
    songfile = os.path.abspath(sys.argv[1])
    tmpfilemat = os.path.abspath(sys.argv[2])
    if tmpfilemat[-4:] != '.mat':
        tmpfilemat += '.mat'
    if os.path.isfile(tmpfilemat):
        os.remove(tmpfilemat)

    # first encode song with tzanetakis code from HackDay
    TZAN.filename_to_beatfeat_mat(songfile,savefile=tmpfilemat)
    print 'song encoded to matfile'

    # then retrieve stuff from EchoNest
    track = trackEN.upload(songfile)
    identifier = string.split(track.identifier,'/')[-1]
    print 'EN identifier =',identifier
    a,b,c,d,e = EXTRAS.get_our_analysis(identifier)
    segstart, chromas, beatstart, barstart, duration = a,b,c,d,e
    if segstart == None:
        print 'EN gave us None, must start again'
        sys.exit(0)
    analysis_dict = {'segstart':segstart,'chromas':chromas,
                     'beatstart':beatstart,'barstart':barstart,
                     'duration':duration}
    del a,b,c,d,e,segstart,chromas,beatstart,barstart,duration
    print 'analysis retrieved from Echo Nest'
    

    # features from online (positive=False to compare with old school method)