Archive for category The Echo Nest

Getting the Hotttest Artists in any genre with The Echo Nest API

If you spend a few hours listening to broadcast radio it becomes pretty evident who the most popular pop artists are.  You can’t go too long before you hear a song by Justin Timberlake, Rihanna, Bruno Mars or P!nk.  The hotttest pop artists get lots of airplay.  But what about all the other music out there?  Who are the hotttest gothic metal artists? Who are the most popular Texas blues artists?   Those are the kind of questions we try to answer with today’s Echo Nest demo:  The Hotttest Artists

Screenshot_3_29_13_1_04_PM

This app lets you select from among over 400 different genres from a cappella to Zydeco and see who are the hotttest artists in that genre.  The output includes a brief bio and image of the artist, and of course you can listen to any artist via Rdio.   The app is an interesting way to explore all of the different genres out there and sample some different types of music.  The source is available on github. The whole thing including all Javascript, html and CSS is less than 500 lines.

Try out the Hotttest Artist app  and be sure to check out all of the other Echo Nest demos on our demo page.

 

Leave a Comment

Getting Artist Images with the Echo Nest API

This week I’ve been writing a few web apps to demonstrate how to do stuff with The Echo Nest API.   One app shows how you can use The Echo Nest API to get artist images.  The app is nice and simple. Type in the name of an artist and it will show you 100 images of the artist.

Screenshot_3_27_13_7_37_AM

The core code to get the images is here:

function fetchImages(artist) {
    var url = 'http://developer.echonest.com/api/v4/artist/images';

    var args = { 
            format:'json', 
            api_key: 'MY-API-KEY',
            name: artist,
            results: 100, 
    }; 

    info("Fetching images for " + artist);
    $.getJSON(url, args,
            function(data) {
                $("#results").empty();
                if (! ('images' in data.response)) {
                    error("Can't find any images for " + artist);
                } else {
                    $.each(data.response.images, function(index, item) {
                        var div = formatItem(index, item);
                        $("#results").append(div);
                    });
                }
            },
            function() {
                error("Trouble getting blog posts for " + artist);
            }
        );
}

The full source is on github.

With jQuery’s getJSON call, it is quite straightforward to retrieve the list of images from The Echo Nest for formatting and display.

The most interesting bits for me was learning how to make square images regardless of the aspect ratio of the image, without distorting them. This is done with a little CSS magic. Each image div gets a class like so:

        .image-container {
            width: 240px;
            height: 240px;
            background-size: cover;
            background-image:"http://example.com/url/to/image.png";
            background-repeat: no-repeat;
            background-position: 50% 50%;
            float:left;
        }

Try out the Artist Image demo , marvel at the square images and be sure to visit the Echo Nest Demo page to see all of the other demos I’ve been posting this week.

Leave a Comment

Using speechiness to make stand-up comedy playlists

One of the Echo Nest attributes calculated for every song is ‘speechiness’.  This is an estimate of the amount of spoken word in a particular track.  High values indicate that there’s a good deal of speech in the track, and low values indicate that there is very little speech.  This attribute can be used to help create interesting playlists.  For example,  a music service like Spotify has hundreds of stand-up comedy albums in their collection.  If you wanted to use the Echo Nest API to create a playlist of these routines you could create an artist-description playlist with a call like so:

http://developer.echonest.com/api/v4/playlist/static?api_key=FILDTEOIK2HBORODV&description=comedy&type=artist-description

However, this call wouldn’t generate the playlist that you want. Intermixed with stand-up routines would be comedy musical numbers by Tenacious D, The Lonely Island or “Weird Al”.  That’s where the ‘speechiness’ attribute comes in. We can add a speechiness  filter to our playlist call to give us spoken-word comedy tracks like so:

http://developer.echonest.com/api/v4/playlist/static?api_key=FILDTEOIK2HBORODV&description=comedy&type=artist-description&min_speechiness=.9

It is a pretty effective way to generate comedy playlists.

I made a demo app that shows this called The Comedy Playlister.   It generates a Spotify playlist of comedy routines.

Screenshot_3_20_13_5_58_AM-2

It does a pretty good job of finding comedy.  Now I just need some way of filtering out Larry The Cable Guy.  The app is on line here: The Comedy Playlister.  The source is on github.

Leave a Comment

How the Bonhamizer works

I spent this weekend at Music Hack Day San Franciso. Music Hack Day is an event where people who are passionate about music and technology get together to build cool, music-related stuff. This San Francisco event was the 30th Music Hack Day with around 200 hackers in attendance. Many cool hacks were built. Check out this Projects page on Hacker League for the full list.

Screenshot_2_17_13_9_49_AM-4

My weekend hack is called The Bonhamizer. It takes just about any song and re-renders it as if John Bonham was playing the drums on the track. For many tracks it works really well (and others not so much). I thought I’d give a bit more detail on how the hack works.

Data Sources

For starters, I needed some good clean recordings of John Bonham playing the drums. Luckily, there’s
set of 23 drum out takes from the “In through the out door” recording session. For instance, there’s
this awesome recording of the drums for “All of my Love”. Not only do you get the sound of Bonhmam
pounding the crap out of the drums, you can hear him grunting and groaning. Super stuff. This particular
recording would become the ‘Hammer of the Gods’ in the Bonhamizer.


From this set of audio, I picked four really solid drum patterns for use in the Bonhamizer.

Of course you can’t just play the drum recording and any arbitrary song recording at the same time and expect the drums to align with the music. To make the drums play well with any song a number of things need to be done (1) Align the tempos of the recordings, (2) Align the beats of the recordings, (3) Play the drums at the right times to enhance the impact of the drums.

To guide this process I used the Echo Nest Analyzer to analyze the song being Bonhamized as well as the Bonham beats. The analyzer provides a detailed map for the beat structure and timing for the song and the beats. In particular, the analyzer provides a detailed map of where each beat starts and stops, the loudness of the audio at each beat, and a measure of the confidence of the beat (which can be interpreted as how likely the logical beat represents a real physical beat in the song).

Aligning the tempos  (We don’t need no stinkin’ time stretcher)

Perhaps the biggest challenge of implementing the Bonhamizer is to align the tempo of the song and the Bonham beats. The tempo of the ‘Hammer of the Gods’ Bonham beat is 93 beats per minute. If fun.’s Some Nights is at 107 beats per minute we have to either speed Bonham up or slow fun. down to get the tempos to match.

Since the application is written in Javascript and intended to run entirely in the browser,  I don’t have access to server side time stretching/shifting libraries like SoundTouch or Dirac. Any time shifting needs to be done in Javascript. Writing a real-time (or even an ahead-of-time) time-shifter in Javascript is beyond what I could do in a 24 coding session. But with the help of the Echo Nest beat data and the Web Audio API there’s a really hacky (but neat) way to adjust song tempos without too many audio artifacts.

The Echo Nest analysis data includes the complete beat timing info. I know where every beat starts and how long it is. With the Web Audio API I can play any snippet of audio from an MP3, with millisecond timing accuracy. Using this data I can speed a song up by playing a song beat-by-beat, but adjusting the starting time and duration of each beat to correspond to the desired tempo. If I want to speed up the Bonham beats by a dozen beats per minute, I just play each beat about 200 ms shorter than it should be. Likewise, if I need to slow down a song, I can just let each beat play for longer than it should before the next beat plays. Yes, this can lead to horrible audio artifacts, but many of the sins of this hacky tempo adjust will be covered up by those big fat drum hits that will be landing on top of them.

I first used this hacky tempo adjustment in the Girl Talk in a Box hack.  Here’s a few examples of songs with large tempo adjustments.  In this  example,  AWOLNation’s SAIL is sped up by 25% you can hear the shortened beats.

Screenshot_2_21_13_3_27_AM

And in this example with Sail slowed down by 25% you can hear double strikes for each beat.

I use this hacky tempo adjust to align the tempo of the song and the Bonham beats, but since I imagine that if a band had John Bonham playing the drums they would be driven to play a little faster, so I make sure that I speed on the song a little bit when I can.

Speeding up the drum beats by playing each drum beat a bit shorter than it is supposed to play gives pretty good audio results. However, using the technique to slow beats down can get a bit touchy. If a beat is played for too long, we will leak into the next beat. Audibly this sounds like a drummer’s flam. For the Bonhamizer this weakness is really an advantage. Here’s an example track with the Bonham beats slowed down enough so that you can easily hear the flam.

When to play (and not play) the drums

If the Bonhamizer overlaid every track with Bonham drums from start to finish, it would not be a very good sounding app.  Songs have loud parts and soft parts, they have breaks and drops, they have dramatic tempo changes.  It is important for the Bonhamizer to adapt to the song. It is much more dramatic for drums to refrain from striking during the quiet a capella solos and then landing like the Hammer of the Gods when the full band comes in as in this fun. track.

There are a couple of pieces of data from the Echo Nest analysis that I can use to help decide when to the drums should play.  First, there’s detailed loudness info.  For each beat in the song I retrieve information on how loud the beat is.  I can use this info to find the loud and the quiet parts of the song and react accordingly.   The second piece of information is  the beat confidence.  Each beat is tagged with a confidence level by the Echo Nest analyzer. This is an indication of how sure the analyzer is that a beat really happened there.  If a song has a very strong and steady beat, most of the beat confidences will be high. If a song is frequently changing tempo, or has weak beat onsets then many of the beat confidence levels will be low, especially during the tempo transition periods.  We can use both the loudness and the confidence levels to help us decide when the drums should play.

For example, here’s a plot that shows the beat confidence level for the first few hundred beats of Some Nights.

Screenshot_2_21_13_3_59_AM

The red curve shows the confidence level of the beats.  You can see that the confidence ebbs and flows in the song.  Likewise we can look at the normalized loudness levels at the beat level, as shown by the green curve in the plot below:

Screenshot_2_21_13_4_03_AM

We want to play the drums during the louder and high confidence sections of the song, and not play them otherwise.  However, if just simply match the loudness and confidence curves we will have drums that stutter start and stop, yielding a very unnatural sound.  Instead, we need to filter these levels so that we get a more natural starting and stopping of the drums.    The filter needs to respond quickly to changes – so for instance, if the song suddenly gets loud, we’d like the drums to come in right away, but the filter also needs to reject spurious changes – so if the song is loud and confident for only a few beats, the drums should hold back.  To implement this I used a simple forward looking runlength filter.   The filter looks for state changes in the confidence and loudness levels. If it sees one and it looks like the new state is going to be stable for the near future, then the new state is accepted, otherwise it is rejected.  The code is simple:

When the filter is applied we get a nice drum transitions – they start when the music gets louder and the tempo is regular and they stop when its soft or the tempo is changing or irregular:

Screenshot_2_20_13_10_46_AM

This above plot shows the confidence and loudness levels for the Some Nights by Fun. The blue curve  shows when the drums play.  Here’s a detailed view of the first 200 beats:

Screenshot_2_20_13_10_41_AM

You can see how transient changes in loudness and confidence are ignored, while longer term changes trigger state changes in the drums.

Note that some songs are always too soft or most of the beats are not confident enough to warrent adding drums.  If the filter rejects 80% of the song, then we tell the user that ‘Bonzo doesn’t really want to play this song’.

Aligning the song and the beats

At this point we now have tempo matched the song and the drums and have figured out when to and when not to play the drums. There’s just a few things left to do.  First thing, we need to make sure that each of the song and drum beats in a bar lines up so the both the song and drums are playing the same beat within a bar (beat 1, beat 2, beat 3,  beat 4, beat 1 …).  This is easy to do since the Echo Nest analysis provides bar info along with the beat info.  We align the beats by finding the bar position of the starting beat in the song and shifting the drum beats so that the bar position of the drum beats align with the song.

A seemingly more challenging issue is to deal with mismatched time signatures.  All of the Bonham beats are in 4-4 time, but not all songs are in 4.  Luckily, the Echo Nest analysis can tell us the time signature of the song.  I use a simple but fairly effective strategy. If a song is in 3/4 time I just drop one of the beats in the Bonham beat pattern to turn the drumming into a matching 3/4 time pattern.  It is 4 lines of code:

if (timeSignature == 3) {
    if (drumInfo.cur % 4 == 1) {
        drumInfo.cur+=1;
    }
 }

Here’s an example with Norwegian Wood (which is in 3/4 time).  This approach can be used for more exotic time signatures (such as 5/4 or 7/4) as well. For songs in 5/4, an extra Bonham beat can be inserted into each measure. (Note that I never got around to implementing this bit, so songs that are not in 4/4 or 3/4 will not sound very good).

Playing it all

Once we have aligned tempos, filtered the drums and aligned the beats, it is time to play the song. This is all done with the Web Audio API, which makes it possible for us to play the song beat by beat with fine grained control of the timing.

Issues + To DOs

There are certainly a number of issues with the Bonhamizer that I may address some day.

I’d like to be able to pick the best Bonham beat pattern automatically instead of relying on the user to pick the beat.  It may be interesting to try to vary the beat patterns within a song too, to make things a bit more interesting.  The overall loudness of the songs vs. the drums could be dynamically matched. Right now, the songs and drums play at their natural volume. Most times that’s fine, but sometimes one will overwhelm the other.   As noted above, I still need to make it work with more exotic time signatures too.

Reception

The Bonhamizer has been out on the web for about 3 days but in that time about 100K songs have been Bonhamized. There have been positive articles in The Verge Consequence of Sound, MetalSucks, Bad Ass Digest and Drummer Zone.  It is big in Japan. Despite all its flaws, people seem to like the Bonhamizer.  That makes me happy.  One interesting bit of feedback I received was from Jonathan Foote (father of MIR). He pointed me to Frank Zappa and his experiments with xenochrony The mind boggles.  My biggest regret is the name. I really should have called it the autobonhamator. But it is too late now … sigh.

All the code for the Bonhamizer is on github. Feel free to explore it, fork and it make your own Peartifier or Moonimator or Palmerizer.

 

 

, ,

2 Comments

The Stockholm Python User Group

In a lucky coincidence I happened to be in Stockholm yesterday which allowed me to give a short talk at the Stockholm Python user Group.  About 80 or so Pythonistas gathered at Campanja to hear talks about Machine Learning and Python.  The first two talks were deep dives into particular aspects of machine learning and Python. My talk was quite a bit lighter. I described the Million Song Data Set and suggested that it would be a good source of data for anyone looking for a machine learning research. I then went on to show a half a dozen or so demos that were (or could be) built on top of the Million Song Data Set. A few folks at the event asked for links, so here you go:

Million Song Data Set

Core Data: Echo Nest analysis for a million songs

Complimentary Data

  • Second Hand Songs – 20K cover songs
  • MusixMatch – 237K bucket-of-words lyric sets
  • Last.fm tags – song level tags for 500K tracks. plus 57 million sim. track pairs
  • Echo Nest Taste profile subset – 1M users, 48M user/song/play count triples

Data Mining Listening Data: The Passion Index

passion

Fun with Artist Similarity Graphs: Boil the Frog

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

Post about In Search of the Click Track and a web app for exploring click tracks

click plot for so lonely by the police

Turning music into silly putty - Echo Nest Remix

The Swinger

Interactive Music

Bangarang Boomerang

Beat Driver-1

Infinite Jukebox

The Infinite Jukebox

 

I really enjoyed giving the talk. The audience was really into the topic and remained engaged through out. Afterwards I had lots of stimulating discussions about the music tech world. The Stockholm Pythonistas were a very welcoming bunch. Thanks for letting me talk.  Here’s a picture I took at the very end of the talk:

swedish pythonistas

, ,

1 Comment

Going Undercover

My Music Hack Day Stockholm hack is ‘Going Undercover‘.  This hack uses the extensive cover song data from SecondHandSongs to construct paths between artists by following chains of cover songs.  Type in the name of  a couple of your favorite artists and Going Undercover will try to find a chain of cover songs that connects the two artists.  The resulting playlist will likely contain familiar songs played by artists that you never heard of before.   Here’s a Going Undercover playlist from Carly Rae Jepsen to Johnny Cash:

 

Screenshot_1_20_13_12_01_PM

For this hack I stole a lot of code from my recent Boil the Frog hack, and good thing I could do that otherwise I would never have finished the hack in time. I spent many hours working to reconcile the Second Hand Songs data with The Echo Nest and Rdio data (Second Hand Songs is not part of Rosetta stone, so I had to write lots of code to align all the IDs up).   Even with leveraging the Boil the Frog code, I had a very late night trying to get all the pieces working (and of course, the bug that I spent 2 hours banging my head on at 3AM was 5 minutes of work after a bit of sleep).

I am pretty pleased with the results of the hack.  It is fun to build a path between a couple of artists and listen to a really interesting mix of music.  Cover songs are great for music discovery, they give you something familiar to hold on to while listening to a new artist.

, , , ,

1 Comment

Boil The Frog

You know the old story – if you put a frog in a pot of cold water and gradually heat the pot up, the frog won’t notice and will happily sit in the pot until the water boils and the frog is turned into frog soup.  This story is at the core of my winter break programming project called Boil the Frog.   Boil the Frog will take you from one music style to another gradually enough so that you may not notice the changes in music style. Just like the proverbial frog sitting in a pot of boiling water, with a Boil the Frog playlist, the Justin Bieber fan may find themselves listening to some extreme brutal death metal such as Cannibal Corpse or Deicide (the musical equivalent to sitting in a pot of boiling water).

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

To use Boil the Frog, you type in the names of any two artists you’ll be given a playlist that connects the two artists. Click on the first artist to start listening to the playlist.  If you don’t like the route taken to connect two artists, you can make a new route by bypassing an offending artist.  The app uses Rdio to play the music.  If you are an Rdio subscriber, you’ll hear full tracks, if not you’ll hear a 30 second sample of the music.

You can create some fun playlists with this app such as:

How does it work? To create this app,  I use  The Echo Nest artist similarity info to build an artist similarity graph of about 100,000 of the most popular artists. Each artist in the graph is connected to it’s most similar neighbors according to the Echo Nest artist similarity algorithm.

image graph

To create a new playlist between two artists, the graph is used to find the path that connects the two artists. The path isn’t necessarily the shortest path through the graph. Instead, priority is given to paths that travel through artists of similar popularity. If you start and end with popular artists, you are more likely to find a path that takes you though other popular artists, and if you start with a long-tail artist you will likely find a path through other long-tail artists. Without this popularity bias many routes between popular artists would venture into back alleys that no music fan should dare to tread.

Once the path of artists is found, we need to select the best songs for the playlist. To do this, we pick a well-known song for each artist that minimizes the difference in energy between this song, the previous song and the next song.   Once we have selected the best songs, we build a playlist using Rdio’s nifty web api.

This is the second version of this app.  I built the first version during a Spotify hack weekend. This was a Spotify app that would only run inside Spotify.  I never released the app (the Spotify app approval process was a bit too daunting for my weekend effort), so I though I’d make a new version that runs on the web that anyone can use.

I enjoy using Boil the Frog to connect up artists that I like. I usually end up finding a few new artists that I like.  For example, this Boil The Frog playlist connecting Deadmau5 and Explosions in the Sky is in excellent coding playlist.

Give Boil the Frog a try and if you make some interesting playlists let me know and I’ll add them to the Gallery.

, ,

15 Comments

The Music We Lost in 2012

It’s the time of the year when music critics make their lists of artists that we passed away or bands that broke up in the last twelve months.  To help them write their retrospectives I’ve put together two lists: One of well-known musicians that died during 2012, and one of well-known bands that called it quits during the year.

Screenshot 12:19:12 4:00 PM-3

 

I made the list using the Echo Nest Artist Search API, restricting the results to artists that had a year ending in 2012.

Lots of great music left us in 2012.  See the lists here:  2012 Music Memoriam

Leave a Comment

How music recommendation works – and doesn’t work

Brian just posted  ’How Music Recommendation works – and doesn’t work‘ over at his Variogr.am blog.  It is a must-read for anyone interested in the state of the art in music recommendation.  Here’s an excerpt:

 Try any hot new artist in Pandora and you’ll get the dreaded:

Pandora not knowing about YUS

This is Pandora showing its lack of scale. They won’t have any information for YUS  for some time and may never unless the artist sells well. This is bad news and should make you angry: why would you let a third party act as a filter on top of your very personal experiences with music? Why would you ever use something that “hid” things from you?

Grab a coffee, sit back and read Brian’s post. Highly recommended.

1 Comment

Visualizing the Structure of Pop Music

The Infinite Jukebox generates plots of songs in which the most similar beats are connected by arcs. I call these plots cantograms. For instance, below is a labeled cantogram for the song Rolling in the Deep by Adele. The song starts at 3:00 on the circle and proceeds clockwise, beat by beat completely around the circle. I’ve labeled the plot so you can see how it aligns with the music. There’s an intro, a first verse, a chorus, a second verse, etc. until the outro and the end of the song.

Rolling in the Deep (labelled) by Adele

One thing that’s interesting is that most of the beat similarity connections occur between the beats in the three instances of the chorus. This certainly makes intuitive sense. The verses have different lyrics, so for the most part they won’t be too similar to each other, but the choruses have the same lyrics, the same harmony, the same instrumentation. They may even be, for all we know may even be exactly the same audio, that perfect performance, cut and pasted three times by the audio engineer to make the best sounding version of the song.

Now take a look at the cantogram for another popular song. The plot below shows the beat similarities for the song Tik Tok by Ke$ha. What strikes me the most about this plot is how similar it looks to the plot for Rolling in the Deep. It has the characteristic longer intro+first verse, some minor inter-verse similarities and the very strong similarities between the three choruses.

Tik Tok by Ke$ha

As we look at more plots for modern pop music we see the same pattern over and over again. In this plot for Lady Gag’s Paparazzi a cantogram we again see the same pattern.

Lady Gaga – Paparazzi

We see it in the plot for Justin Bieber’s Baby:

Justin Bieber – Baby

Taylor Swift’s Fearless has a two verses before the first chorus, shifting it further around the circle, but other than that the pattern holds:

Taylor Swift – Fearless

Now compare and contrast the pop cantograms with those from other styles of music. First up is Led Zeppelin’s Stairway to heaven. There’s no discernable repeating chorus, or global song repetition, the only real long-arc repetition occurs during the guitar solo for the last quarter of the song.

Led Zeppelin – Stairway to Heaven

Here’s another style of music. Deadmau5′s Raise your weapon. This is electronica (and maybe some dubstep). Clearly from the cantogram we can see that is is not a traditional pop song. Very little long arc repetition, with the densest cluster being the final dubstep break.

Deadmau5 – Raise your weapon

Dave Brubeck’s Take Five has a very different pattern, with lots of short term repetition during the first half of the song, while during the second half with Joe Morello’s drum solo there’s a very different pattern.

Dave Brubeck – Take Five

Green Grass and High Tides has yet a different pattern – no three choruses and out here. (By the way, the final guitar solo is well worth listening to in the Infinite Jukebox. It is the guitar solo that never ends).

Green Grass And High Tides by The Outlaws

The progressive rock anthem Roundabout doesn’t have the Pop Pattern

Yes – Roundabout

Nor does Yo-Yo Ma’s performance of the Cello suite No. 1.

01 Cello Suite No.1, 1. Prelude by Yo-Yo Ma

Looking at the pop plots one begins to understand that pop music really could be made in a factory. Each song is cut from the same mold. In fact, one of the most successful pop songs in recent years, was produced by a label with factory in its name. Looking at Rebecca Black’s Friday we can tell right away that it is a pop song:

Friday by Rebecca Black

Compare that plot to this years Youtube breakout, Thanksgiving by Nicole Westbrook, (another Ark Music Factory assembly):

Nicole Westbrook – It’s Thanksgiving (Official Video)

The plot has all the makings of the standard pop song for the 2010s.

In the music information retrieval research community there has been quite a bit of research into algorithmically extracting song structure, and visualizations are often part of this work. If you are interested in learning more about this research, I suggest looking at some of the publications by Meinard Müller and Craig Sapp.

Of course, not every pop song will follow the pattern that I’ve shown here. Nevertheless, I find it interesting that this very simple visualization is able to show us something about the structure of the modern pop song, and how similar this structure is across many of the top pop songs.

update: since publishing this post I’ve updated the layout algorithm in the Infinite Jukebox so that songs start and end at 12 Noon and not 3PM, so the plots you see in this post are rotated 90degrees clockwise from what you would see in the jukebox.

,

11 Comments

Follow

Get every new post delivered to your Inbox.

Join 234 other followers