Artist radio in 10 lines of code

Last week we released Pyechonest, a Python library for the Echo Nest API.  Pyechonest gives the Python programmer access to the entire Echo Nest API including artist and track level methods.  Now after 9 years working at Sun Microsystems, I am a diehard Java programmer, but I must say that I really enjoy the nimbleness and expressiveness of Python.  It’s fun to write little Python programs that do the exact same thing as big Java programs.  For example, I wrote an artist radio program in Python that, given a seed artist, generates a playlist of tracks by wandering around the artists in the neighborhood of the seed artists and gathering audio tracks.   With Pyechonest, the core logic is 10 lines of code:

def wander(band, max=10):
   played = []
   while max:
     if band.audio():
         audio = random.choice(band.audio())
         if audio['url'] not in played:
             play(audio)
             played.append(audio['url'])
             max -= 1
     band = random.choice(band.similar())

(You can see/grab the full code with all the boiler plate in the SVN repository)

This method takes a seed artist (band) and selects a random track from set of audio that The Echo Nest has found on the web for that artist, and if we haven’t already played it, then do so. Then we select a near neighbor to the seed artist and do it all again until we’ve  played the desired number of songs.

For such a simple bit of code, the playlists generated are surprisingly good..Here are a few examples:

Seed Artist:  Led Zeppelin:

(I think the Dale Hawkins version of Susie-Q after  CCR’s Fortunate Son  is just brilliant)

Seed Artist: The Decemberists:

(Note that audio for these examples is audio found on the web – and just like anything on the web the audio could go away at any time)

I think these artist-radio style playlists rival just about anything you can find on current Internet radio sites – which ain’t to0 bad for 10 lines of code.

, , , , , ,

  1. #1 by Daniel Webb on July 16, 2009 - 10:43 am

    I’m holding out for when audio.similar is an option. I’m really impressed by the echonest but my particular penchance is for auto playlist creation and artist.similar won’t ever match audio.similar for smooth playlists.

    Regards
    Daniel Webb

    • #2 by plamere on July 16, 2009 - 10:48 am

      Daniel – I totally agree – song to song similarity will be key for high quality playlist generation – its the kind of technology that we are using with customers now to create coherent playlists – it hasn’t made it into our developer APIs yet, but its coming.

      • #3 by alsothings on July 16, 2009 - 11:15 am

        So, not to hijack the thread or anything, but as someone who has done a bit of mucking about with remix and audio sim in various other contexts, it would be super rad if remix (or more generally pyechonest) had a similarity measure that was generically applicable up and down the event hierarchy. This would enable things like auto correlation at the beat or bar level, or the generation of remixes based on say how dissimilar a beat/bar is from its parent or the whole song…
        I’ve been toying with implementing this client side in the meantime, though it would be a bit slower.

      • #4 by plamere on July 16, 2009 - 11:19 am

        Ben (aka alsothings) – good idea. The best way to make this happen is to add it as an issue on the remix site

      • #5 by Ben on July 16, 2009 - 11:36 am

        Done and done.

        sorry about the handle confusion up there, I just started using OpenID and it auto-logged me in to some wordpress thing that didn’t know my name. I think I fixed it, but I don’t get to find out till I hit submit…

  2. #6 by BitPerfect on July 16, 2009 - 5:59 pm

    Might be a good idea to have your zip archive open in its own directory, rather than spraying files all over the enclosing directory.

    • #7 by brian on July 16, 2009 - 6:36 pm

      bitperfect — which zip file? The pyechonest distribution? I didn’t know it did that. I can fix that if that’s what your talking about.

      • #8 by brian on July 16, 2009 - 6:40 pm

        yeah, it was doing that. bitperfect, i just fixed it. thanks for the tip

  1. Crear un Random Playlist con artistas relacionados
Follow

Get every new post delivered to your Inbox.

Join 1,203 other followers

%d bloggers like this: