Archive for category code

Roadtrip Mixtape

Over the last few years I’ve made a number of 1,000+ mile road trips as I shuttle kids to colleges in far away places. Listening to music has always been a big part of these trips.  I thought it’d be nice to be able to listen to music by local artists when driving through a particular region, so I spent a few weekends creating an app called Roadtrip Mixtape that populates a roadtrip playlist with artists that are from the region you are driving through.

To create a playlist, type your starting and ending cities for your roadtrip.  The app will use Google’s directions to plan the best route between the two cities.  The route will then be broken into 15 minute playlist legs. Each playlist leg is populated by 15 minutes worth of music by nearby artists.

The beginning of each leg is represented by a green ball. You can click on the ball to see what artists will be played during that leg.  The app plays music via Rdio using their nifty Web  Player API.  If you are an Rdio subscriber you can listen to full streams, and if not you get to hear 30 second samples.  One bit of interesting info that I show for a route is the ‘Avg distance’.  This shows the average distance to each artist on the roadtrip. If this number is low, you are traveling through a musically dense part of the world, and if it is high,  you are traveling in a sparse musical region. For instance, for a roadtrip from Boston to New York the average artist distance is 3 miles (about as low as it goes).   However, if you are traveling from Omaha to Denver, the average artist distance is 81 miles.

You can also click anywhere on the map to see and listen to nearby artists.   For example, if you click on Shreveport you’ll see something like this:

When you click the ‘Hear here’ button, you’ll get a playlist of the hotttest artists from Shreveport.

Listening to nearby artists is quite fun. There’s potential from some extreme sonic whiplash as you drive near a brutal death metal band and then a pop vocalist from the 1950s

The Technical Bits
To build the app I used the new artist location data from The Echo Nest.  This (still in beta) feature, allows you to retrieve the location of any artist.  Here’s an example API call that retrieves the artist location for Radiohead:

http://developer.echonest.com/api/v4/artist/profile?api_key=N6E4NIOVYMTHNDM8J&name=radiohead&format=json&bucket=artist_location

For this app, I collected the locations for the top 100,000 or so most popular artists in the Rdio catalog.  These artists were from about 15,000 different cities.  I used geopy along with the Yahoo Placefinder geocoder to find the latitude and longitude for each of these cities.  For the mapping and route finding, I used version 3.9 of the Google maps API.   For music playback I used the Rdio Web Playback API.   With the tight integration between the Echo Nest and Rdio ID spaces it was easy to go from a geolocated Echo Nest artist to a list of Rdio track IDs for songs by that artist.

The Bad Bits
As a web app that relies on the flash-based Rdio web player,  Roadtrip Mixtape  is not really a mobile app.  It won’t play music on an iPhone or iPad, so the best way to actually use this app on the road is probably to bring along your tethered laptop.  Not the best user experience.  Thus, my next weekend project will be to learn a little bit of iOS programming a make a version of this app that runs on an iPhone and an iPad.  Stay tuned for the next version.

, , , ,

2 Comments

What is the most musical city in the United States?

There are many cities in the United States that are known for their music. Cities like Nashville, Detroit, Seattle and New Orleans have played a major part in the musical history and development of this country.  But what is the most musical city? Which city has spawned the most musical artists? To answer this question I used the soon-to-be-released artist location data from The Echo Nest artist API.  I gathered up the top 50,000 or so U.S. artists, found their city of origin and tallied the number of artists per city.  From this tally I calculated the number of artists per 1,000 inhabitants in each city. The more artists per 1000 inhabitants, the more musical the city.

Using the artists per 1k inhabitants, we can easily find the top 25 most musical cities in the United States:

# Artists per 1,000 inhabitants Artists Population City
1 3.14 111 35355 Beverly Hills, CA
2 2.26 1651 732072 San Francisco, CA
3 1.68 894 530852 Nashville, TN
4 1.64 936 571281 Boston, MA
5 1.54 651 422908 Atlanta, GA
6 1.53 53 34703 Charlottesville, VA
7 1.48 817 552433 Washington, DC
8 1.39 513 367773 Minneapolis, MN
9 1.37 740 540513 Portland, OR
10 1.32 51 38601 Burlington, VT
11 1.24 4789 3877129 Los Angeles, CA
12 1.22 15 12314 Muscle Shoals, AL
13 1.20 683 569369 Seattle, WA
14 1.11 755 678368 Austin, TX
15 1.05 75 71253 Bloomington, IN
16 1.05 50 47529 Chapel Hill, NC
17 1.05 47 44916 Olympia, WA
18 1.00 13 12945 Princeton, NJ
19 0.95 182 190886 Richmond, VA
20 0.94 11 11678 Hendersonville, NC
21 0.87 12 13769 Malibu, CA
22 0.87 88 100975 Denton, TX
23 0.86 179 207970 Orlando, FL
24 0.86 86 100158 Berkeley, CA
25 0.85 114 133874 Orange, CA

I find the results to be pretty interesting.  Beverly Hills, the tiny city at the heart of the entertainment world is #1.  San Francisco is the most musical of all large cities, followed closely by Nashville. Among, the most musical of small cities is Muscle Shoals AL  which, according to Wikipedia, is famous for its contributions to American popular music.  Less musical than expected are New Orleans (rank 36),  NYC (rank 37), Detroit (rank 52).

Among the least musical cities in the U.S. are my hometown (Manchester NH), with only one artist in the top 50,000 U.S. based artist for the 100K inhabitants.  The least musical large city in the U.S. is Kansas City KS, with only 7 top-50k artists for their nearly half million inhabitants. Luckily Kansas City residents can drive a few miles to Kansas city Missouri (with its 194 musicians for its 442k inhabitants) when they get tired of their own seven artists.

You can see the full list of cities with population greater than 5,000 ordered by their musicality here:  The Most Musical Cities in the United States.  I’d love to do this for all the cities in the world, but I can’t find a good source of city population data for world cities. If you know of one let me know.

I’m rather exited about this upcoming release of artist location data in our API. It will open the doors for a whole bunch of interesting applications, such as road trip playlisters that play music by artists local to the city you are near, contextual playlisters that will favor artists from your home town, or music exploration apps that will let you explore music from a particular region of the world.  I can’t wait to see what people build with this data. Stay tuned, I’ll post when the API is released.

 

19 Comments

Rethink Music Hackers’ Weekend

This weekend was Rethink Music Hacker’s Weekend where 100 or so music hackers gathered at the Microsoft NERD to not just rethink music, but to rebuild it.  There were  about two dozen hacks built, showing a wide range of creativity. Some of my favorites are:

Kinect Bomba  -As in the latin style of music called “Bomba”, the dancer is in control of the band and music.  The virtual band is the kinect — the dancer(s) can create sweet, live beat-locked music over any mp3 (using echonest-remix), remixes, and even control a virtual looper pedal.

Hiptapes - HipTapes is a music marketing APP enables artists to create custom QR codes and push dynamic content to fans via posters, flyers, CDs, etc. HipTapes mobile app scans the QR code & enables users to instantly stream, bookmark or buy music tracks, purchase concerts tickets, discounted merchandise or leave a message on artist’s Facebook page.

Hipsterer – Figures out how hipster you are? (I knew about this site before it was cool).

Jam Page - Hi-resolution listener analytics for artists.

 

Texture Learning - A simple genetic algorithm learns the short-time fourier transform of a target static texture. The approximation gradually acquires information about the target sound via repeated semi-random modifications to the spectrogram. Phase and magnitude are learned separately. The learning process is sonified and visualized such that the gradual evolution of the sound from silence to target can be seen and heard. Experimentation with several control parameters results in varied output.

Byrds and the Bee Gees – finds the playlist that your parents could of have used on the night you were conceived.  Totally fun app. Toughest part is trying to decide if my dad was ‘smooth back then’.

Lyrical Sonnet Awesome –  My favorite hack. Totally origina. Uses  lyricfind.com’s API to make a sonnet generator! In Iambic pentameter! The sonnets are in the rhyme scheme of Shakespeare. ABABCDCDEFEFGG, and you can choose key words to populate the themes. Here’s an example:

  • Too long values we let them blend and fade
  • And with the awesome power they struck
  • You’re like a long, cool glass of lemonade
  • It’s Knoc-turn’al with a capital K
  • Something cool, set one up for me
  • If you turn away, oh, honey, please stay
  • The center of attention, cool Moe Dee
  • I want to take you cool places tonight
  • Are you still mad I kicked you out of bed?
  • What befalls us in the heat of the night?
  • I keep a cool head, I keep a cool head
  • That I was mad if they were sane, you see
  • The blues my naughty sweetie gives to me.
     Totally crude website for the sonnet generator here

Map of Music styles this is my hack – an interactive map of 1000s of music styles, allowing you to explore through the world of music.

See the full list of hacks on hacker league.  It was a really fun weekend, with lots of very creative hacking!

2 Comments

Map of Music Styles

I spent this weekend at Rethink Music Hackers’ Weekend building a music hack called Map of Music Styles (aka MOMS).  This hack presents a visualization of over 1000 music styles. You can pan and zoom through the music space just like you can with Google maps.  When you see an interesting style of music you can click on it to hear some samples of music of that style.

It is fun to explore all the different neighborhoods of music styles. Here’s the Asian corner:

Here’s the Hip-Hop neighborhood:

And a mega-cluster of ambient/chill-out music:

To build the app, I collected the top 2,000 or so terms via The Echo Nest API. For each term I calculated the most similar terms based upon artist overlap (for instance, the term ‘metal’ and ‘heavy metal’ are often applied to the same artists and so can be considered similar, where as ‘metal’ and ‘new age’ are rarely applied to the same artist and are, therefore, not similar).  To layout the graph I used  Gephi (Its like Photoshop for graphs)  and exported the graph to SVG.  After that it was just a bit of Javascript, HTML, and CSS to create the web page that will let you pan and zoom. When you click on a term, I fetch audio  that matches the style via the Echo Nest and 7Digital APIs.

There are a few non-styles that snuck through – the occasional band name, or mood, but they don’t hurt anything so I let them hang out with the real styles.   The app works best in Chrome. There’s a bug in the Firefox version that I need to work out.

Give it a try and let me know how you like it:    Map of Music Styles

, ,

18 Comments

The Spotify Play Button – a lightening demo

Spotify just released a nifty embeddable play button. With the play button you can easily embed Spotify tracks in any web page or blog.  Since there’s really tight integration between the Spotify and Echo Nest IDs, I thought I’d make a quick demo that shows how we can use the Echo Nest playlist API and the new Spotify Play button to make playlists.

The demo took about 5 minutes to write (shorter than it is taking to write the blog post). It is simple artist radio on a web page.  Give it a go at:  Echo Nest + Spotify Play Button Demo

Here’s what it looks like.

Update: Charlie  and Samuel pointed out that there is a multi-track player too.  I made a demo that uses that too:

The Spotify Play button is really easy to use, looks great. Well done Spotify.

,

4 Comments

Syncing Echo Nest analysis to Spotify Playback

With the recently announced Spotify integration into Rosetta Stone, The Echo Nest now makes available a detailed audio analysis for millions of Spotify tracks.  This audio analysis includes summary features such as tempo, loudness, energy, danceability, key and mode, as well as a set of fine-grained segment features that describe details such as where each bar, beat and tatum fall and the detailed pitch, timbral and loudness content of each audio event in the song.   These features can be very useful for driving Spotify applications that need to react to what the  music sounds like – from advanced dynamic music visualizations like the MIDEM music machine or synchronized music games like Guitar Hero.

I put together a little Spotify App that demonstrates how to synchronize Spotify Playback with the Echo Nest analysis.  There’s a short video here of the synchronization:

video on youtube: http://youtu.be/TqhZ2x86RXs

In this video you can see the audio summary for the currently playing song, as well as a display synchronized ‘bar’ and ‘beat’ labels and detailed loudness, timbre and pitch values for the current segment.

How it works:

To get the detailed audio analysis,  call the track/profile API with the Spotify Track ID for the track of interest. For example, here’s how to get the track for Radiohead’s Karma Police using the Spotify track ID:

http://developer.echonest.com/api/v4/track/profile?api_key=N6E4NIOVYMTHNDM8J&format=json&id=spotify-WW:track:3L7BcXHCG8uT92viO6Tikl&bucket=audio_summary

This returns audio summary info for the track, including the tempo, energy and danceability.  It also includes a field called the analysis_url  which contains an expiring URL to the detailed analysis data. (A very abbreviated excerpt of an analysis is contained in this gist).

To synchronize Spotify playback with the Echo Nest analysis we need to first get the detailed analysis for the now playing track.  We can do this by calling the aforementioned track/profile call to get the analysis_url for the detailed analysis, and then retrieve the analysis (it is stored in JSON format, so no reformatting is necessary).  There is one technical glitch though.  There is no way to make a JSONP call to retrieve the analysis. This prevents you from retrieving the analysis directly into a web app or a Spotify app.  To get around this issue, I built a little proxy at labs.echonest.com that supports a JSONP style call to retrieve the contents of the analysis URL.  For example, the call:

http://labs.echonest.com/3dServer/analysis?callback=foo
&url=http://url_to_the_analysis_json

will return the analysis json wrapped in the foo() callback function.  The Echo Nest does plan to add JSONP support to retrieving analysis data, but until then feel free to use my proxy. No guarantees on support or uptime since it is not supported by engineering. Use at your own risk.

Once you have retrieved the analysis you can get the current bar, beat, tatum and segment info based upon the  current track position, which you can retrieve from Spotify with:    sp.getTrackPlayer().getNowPlayingTrack().position.  Since all the events in the analysis are timestamped, it is straightforward to find a corresponding bar,beat, tatum and segment given any song timestamp.  I’ve posted a bit of code on gist that shows how I pull out the current bar, beat and segment based on the current track position along with some code that shows how to retrieve the analysis data from the Echo Nest.  Feel free to use the code to build your own synchronized Echo Nest/Spotify app.  

The Spotify App platform is an awesome platform for building music apps.  Now, with the ability to use Echo Nest analysis from within Spotify apps,  it is a lot easier to build Spotify apps that synchronize to the music. This opens the door to a whole range of new apps. I’m really looking forward to seeing what developers will build on top of this combined Echo Nest and Spotify platform.

,

Leave a Comment

Writing an Echo Nest + Spotify App

Last week The Echo Nest and Spotify announced an integration of APIs making it easy for developers to write Spotify Apps that take advantage of the deep music intelligence offered by the Echo Nest. The integration is via Project Rosetta Stone (PRS).  PRS is an ID mapping layer in the API that allows developers to use the IDs from any supported music service with the Echo Nest API.   For instance, a developer can request via the Echo Nest playlist API a playlist seeded with a Spotify artist ID and receive Spotify track IDs in the results.

This morning I created a Spotify App that demonstrates how to use the Spotify and Echo Nest APIs together. The app is a simple playlister with the following functions:

  • Gets the artist for the currently playing song in Spotify
  • Creates an artist radio playlist based upon the now playing artist
  • Shows the playlist, allowing the user to listen to any of the playlist tracks
  • Allows the user to save the generated playlist as a Spotify playlist.
The app is functional, but not very pretty. Here’s a screenshot:

The entire app, including all of the HTML, CSS and JavaScript, is 150 lines long.I’ve made all the code available in the github repository SpotifyEchoNestPlaylistDemo.    Here are some of the salient bits. (apologies for the screenshots of code. WordPress.com has poor support for embedding sourcecode. I’ve been waiting for gist embeds for a year)

makePlaylistFromNowPlaying() - grabs the current track from spotify and fetches and displays the playlist from The Echo Nest.

fetchPlayst() - The bulk of the work is done in the fetchPlaylist method.  This method makes a jsonp call to the Echo Nest API to generate a playlist seeded with the Spotify artist.  The Spotify Artist ID needs to be massaged slightly. In the Echo Nest world Spotify artist IDs look like ‘spotify-WW:artist:12341234′ so we convert from the Spotify form to the Echo Nest form with the one liner:

  var artist_id = artist.uri.replace('spotify', 'spotify-WW');

Here’s the code:

The function createPlayButton creates a doc element with a clickable play image, that when clicked, calls the playSong method, which grabs the Spotify Track ID from the song and tells Spotify to play it:

Update: I was using a deprecated method of playing tracks. I’ve updated the code and example to show the preferred method (Thanks @mager).

When we make the playlist call we include a buckets parameter requesting that spotify IDs are returned in the returned tracks. We need to reverse the ID mapping to go from the Echo Nest form of the ID to the Spotify form like so:

Saving the playlist as a spotify playlist is a 3 line function:

Installing and running the app

To install the app, follow these steps:

  • make sure you have a Spotify Developer Account
  • Make a ‘playlister’ directory in your Spotify apps folder (On a mac this is in ~/Spotify/playlister)
  • Get the project files from github
  • Copy the project files into the ‘playlister’ directory. The files are:
    • index.html – the app (html and js)
    • manifest.json – describes your app to Spotify.  The most important bit is the ‘RequiredPermissions’ section that lists ‘http://*echonest.com’. Without this entry, your app won’t be able to talk to The Echo Nest.
    • js/jquery.min.js – jquery
    • styles.css – minimal css for the app
    • play.png – the image for the play button
    • icon.png – the icon for the app

To run the app type ‘spotify:app:playlister’ in the Spotify search bar. The app should appear in the main window.

Wrapping Up

Well, that’s it – a Spotify playlisting app that uses the Echo Nest playlist API to generate the playlist.  Of course, this is just the tip of the iceberg. With the Spotify/Echo Nest connection you can easily make apps that use all of the Echo Nest artist data:  artist news, reviews, blogs, images, bios etc,  as well as all of the detailed Echo Nest song data: tempo, energy, danceability, loudness, key, mode etc.  Spotify has created an awesome music app platform. With the Spotify/Echo Nest connection, this platform has just got more awesome.

Leave a Comment

Waltzify – turn any 4/4 song into a waltz with Echo Nest remix

Tristan Jehan, one of the founders here at the Echo Nest,  has created a Python script that will take a 4/4 song and turn it into a waltz.  The script uses Echo Nest remix, a Python library that lets you algorithmically manipulate music.   Here’s an example of the output of the script when applied  to the song ‘Fame’:

Turning a 4/4 song into a 3/4 song while still keeping the song musical is no easy feat.  But Tristan’s algorithm does a pretty good job.  Here’s what he does:

  • Start with a 4/4 measure
  • Cut the 4/4 measure into 2 bars with 2 beats in each bar
  • Stretch the first beat of each bar by 100%
  • Adjust the tempo to a typical waltz tempo

Here’s a graphic that shows the progression:

 

Here are some more examples:

Tristan has made the waltzifier code available on github.  If you want to make your own waltzes, get  yourself an Echo Nest API key and grab Echo Nest remix and start enjoying the power of 3.

3 Comments

Boil the Frog – the unreleased Spotify Version

Update – You are probably looking for this web-based version of Boil The Frog and the blog post about it.

Screenshot 1:2:13 5:54 AM-3

The rest of this article is about the unreleased Spotify Version of Boil the Frog.

I’m at Music Apps Hack Weekend doing my favorite thing: hacking on music. I’ve just finished my hack called Boil the Frog.  Boil the Frog  is a Spotify App that will create playlists that gradually take you from one music style to another.  It is like the proverbial story of the frog in the pot of water. If you heat the water gradually, the frog won’t notice and will happily sit in the pot until it becomes frog stew.  With Boil the Frog  you can do the same thing musically.  Create a playlist that gradually takes your pre-teen from Miley Cyrus to Miles Davis, or perhaps more perversely the Kenny G fan to Cannibal Corpse.

To build the app I built an artist similarity graph of 100,000 of the most popular artists. I use The Echo Nest artist similarity to connect each artist to its four nearest neighbors. To find the path between any two artists I use a bidirectional Dijkstra shortest path algorithm.  Most paths can be computed in less than 100ms.

The Spotify Apps API is the perfect hacking platform. You can build a Spotify app that has full access to the vast Spotify music catalog and artwork, along with access to the listener’s catalog.   Since the Spotify Apps run in an embedded browser all of your web app programming skills apply.  You can use jQuery, make calls to JSON APIs, use HTML 5 canvas. It is all there. Spotify has done a really good job putting together this platform.  The only downside is that, unlike the web, it is hard to actually release Spotify apps, but the Spotify team is working to make this easier.    I’d love to release Boil the Frog because it is really fun to make playlists that bring you from one music style to another. It is interesting to see what musical neighborhoods you wander through on your way.  For instance, I made a Kenny G to Cannibal Corpse playlist. To get there, the playlist brought me from easy listening, to movie soundtracks and then through video game soundtracks to get to the heavy metal world.  Cool stuff.  If you want to see a playlist between two artists let me  know in the comments and I’ll create and share the playlist with you.

I made a video of Boil the Frog in action.   Check it out:

Update: I’ve just pushed the client code out to github:  https://github.com/plamere/boilthefrog

, , ,

16 Comments

Paul vs. Billboard

Another weekend,  another Music Hack Day.  This weekend I’m at Tokbox headquarters in San Francisco at the 3rd annual Music Hack Day San Francisco, where 200 music hackers are building the future of music.

For my hack, I thought I would try to predict who would win the Grammy awards (the annual music awards presented by The Recording Academy) which is being held this evening.   To do this, I used the Echo Nest APIs to gather of lots of news and blog posts for each nominated artist. I then peered into the articles looking for mentions of the Grammy nominated items.  I tallied up the mentions and combined this with the overall artist hotttnesss to give me a ranked order of each nominated item, which I could then use to create my prediction.

Since Billboard has also made some Grammy predictions, I thought it’d be interesting to do a post-facto comparison on how well each of us predicts the winners – thus the hack title ‘Paul vs. Billboard’.

The hack is online here:  Paul vs. Billboard

Be sure to check out all of the other music hacks being created this weekend:

List of  Music Hackday San Francisco 2012 hacks

, ,

Leave a Comment

Follow

Get every new post delivered to your Inbox.

Join 234 other followers