Posts Tagged java

Echo Nest Client Library for the Android Platform

The Echo Nest is participating in annual mobdev contest for the Mobile Application Development (mobdev) course at Olin College offered by Mark L. Chang.  Already, our participation is bearing fruit.  Ilari Shafer, one of our course assistants created  a version of the Echo Nest Java client library that runs on Android.  You can fetch it here:  echo-nest-android-java-api [zip].

I spent a few hours yesterday talking to the mobdev class.  The students had lots of great questions and lots of really interesting ideas on how to use the Echo Nest APIs to build interesting mobile apps.  I can’t wait to see what they build in 10 days.

, , ,

Leave a comment

The Echo Nest gets ready for Boston Music Hack Day

We’ve been extremely busy this week at the Echo Nest getting ready for the Boston Music Hack Day.  Not only have we been figuring out menus, panel room assignments, and dealing with a waitlist, we’ve also been releasing a set of new API features.  Here’s a quick rundown of what we’ve done:

  • get_images – a frequent request from developers – we now have an API method that will let you get images for an artist.   Note that we are releasing this method as a sneak preview for the hack day – we have images for over 60 thousand artists, but we will be aggressively adding more images  over the next few weeks (60 thousand artists is a lot of artists, but we’d like to have lots more).  We’ll also be expanding our sources of images to include many more sources. The results of the get_images are already good. 95% of the time you’ll get images. Over the next few weeks, the results will get even better.
  • get_biographies – another frequent request from developers – we now have a get_biographies API method that will return a set of artist biographies for any artist.  We currently have biographies for about a quarter million artists – and just as with get_images – we are working hard to expand the breadth and depth of this coverage.  Nevertheless, with coverage for a quarter million artists, 99.99% of the time when you ask for a biography we’ll have it.
  • get_similar – we’ve expanded the number of similar artists you can get back from get_similar from 15 to 100.  This gives you lots more info for building playlisting and music discovery apps.
  • buckets – one issue that our developers have had was that to fill out info on an artist often took a number of calls to the Echo Nest – one to get similars, one to get audio, one for video, familiarity, hotttnesss etc.  To fill out an artist page it could take half a dozen calls.  To reduce the number of calls needed to get artist information we’ve added a ‘bucket’ parameter to the search_artist, the get_similar and the get_profile calls.  The bucket parameter allows you to specify which additional artist info should be returned in the call.  You can specify ‘audio,’ ‘biographies,’ ‘blogs,’ ‘familiarity,’ ‘hotttnesss,’ ‘news,’ ‘reviews,’ ‘urls,’, ‘images’  or ‘video’ and whenever you get artist data back you’ll get the specified info included.    For example with the call:
    http://developer.echonest.com/api/get_profile
          ?api_key=EHY4JJEGIOFA1RCJP
          &id=music://id.echonest.com/~/AR/ARH6W4X1187B99274F
          &version=3
          &bucket=familiarity
          &bucket=hotttnesss
    

    will return an artist block that looks like this:

    <artist>
        <name>Radiohead</name>
        <id>music://id.echonest.com/~/AR/ARH6W4X1187B99274F</id>
        <familiarity>0.899230928024</familiarity>
        <hotttnesss>0.847409181874</hotttnesss>
    </artist>

There’s another new feature that we are starting to roll out. It’s called Echo Source – it allows the developer to get content (such as images, audio, video etc.) based upon license info.  Echo Source is a big deal and deserves a whole post – but that’s going to have to wait until after Music Hack Day. Suffice it to say that with Echo Source you’ll have a new level of control over what content the Echo Nest API returns.

We’ve updated our Java and Python libraries to support the new calls.  So grab yourself an API key and start writing some music apps.

, , ,

2 Comments

Where is my JSpot?

I like Spotify.  I like Java.  So I combined them.  Here’s a Java client for the new Spotify metadata API:  JSpot

This client lets you do things like search for a track by name and get the Spotify ID for the track so you can play the track in Spotify.  This is useful for all sorts of things like building web apps that use Spotify to play music, or perhaps to build a Playdar resolver so you can use Spotify and Playdar together.

Here’s some sample code that prints out the popularity and spotify ID for all versions of Weezer’s  ‘My Name Is Jonas’.

    Spotify spotify = new Spotify();
    Results<Track> results = spotify.searchTrack("Weezer",  "My name is Jonas");
    for (Track track : results.getItems()) { 
       System.out.printf("%.2f %s \n", track.getPopularity(), track.getId());
    }

This prints out:

0.75


0.00


0.09

If you have Spotify and you click on those links, and those tracks are available in your locale you should hear Weezer’s nerd anthem.

You can search for artists, albums and tracks and you can get all sorts of information back such as release dates for albums, countries where the music can be played, track length, popularity for artists, tracks and albums.  It is very much a 0.1 release. The search functionality is complete so its quite useful, but I haven’t implemented the ‘lookup’ methods yet.   There some javadocs.  There’s a jar file: jspot.jar.  And it is all open source: jspot at google code.

, , , ,

3 Comments

Updated Java client for the Echo Nest API

We’ve pushed out a new version of the open source Java client for the Echo Nest API.    The new version provides support for the different versions of the Echo Nest analyzer.  You can use the traditional,  but somewhat temperamental version 1 of the analyzer, or the spiffy new, ultra-stable version 3 of the analyzer.  By default, the Java client uses the new analyzer version, but if you need your application to work the exactly the same way that it did six months ago you can always use the older version.

Here’s a bit of Java code that will print out the tempo of all the songs in a directory:

void showBPMS(File dir) throws EchoNestException {
     TrackAPI trackAPI = new TrackAPI();
     File[] files = dir.listFiles();
     for (File f : files) {
         if (f.getAbsolutePath().toLowerCase().endsWith(".mp3")) {
             String id = trackAPI.uploadTrack(f, true);
             System.out.printf("Tempo 6%.3f %s\n",
                 trackAPI.getTempo(id).getValue(), f.getAbsoluteFile());
         }
     }
}

Running this code on a folder containing the new Breaking Benjamin album yields this output:

Tempo  85.57 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/01 - Fade Away.mp3
Tempo 108.01 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/02 - I Will Not Bow.mp3
Tempo 168.81 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/03 - Crawl.mp3
Tempo 156.75 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/04 - Give Me A Sign.mp3
Tempo  85.51 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/05 - Hopeless.mp3
Tempo  68.34 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/06 - What Lies Beneath.mp3
Tempo 116.94 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/07 - Anthem Of The Angels.mp3
Tempo  85.50 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/08 - Lights Out.mp3
Tempo 125.77 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/09 - Dear Agony.mp3
Tempo  94.99 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/10 - Into The Nothing.mp3
Tempo 160.38 /Users/plamere/Music/Amazon MP3/Breaking Benjamin/Dear Agony/11 - Without You.mp3

You can download the new Java client from the echo-nest-java-api code repository.  The new version is: echo-nest-java-api-1.2.zip

, , , , ,

Leave a comment

New Echo Nest Java client released

We’ve just released version 1.1 of the Echo Nest Java Client.  The Java Client makes it easy to access the Echo Nest APIs from a Java program.  This release fixes some bugs and improves caching support.   Here’s a snippet of Java code that shows how you can use the API to find similar artists for the band ‘Weezer’:

 ArtistAPI artistAPI = new ArtistAPI(MY_ECHO_NEST_API_KEY);
 List<Artist> artists = artistAPI.searchArtist("Weezer, false);
 if (artists.size() > 0) {
     for (Artist artist : artists) {
          List<Scored<Artist>> similars =
                artistAPI.getSimilarArtists(artist, 0, 10);
          for (Scored<Artist> simArtist : similars) {
               System.out.println("   " + simArtist.getItem());
          }
      }
  }

Also included in the release is a command line shell that lets you interact with the Echo Nest API.   You can start it up from the command line like so:

    java  -DDECHO_NEST_API_KEY=YOUR_API_KEY -jar EchoNestAPI.jar

Here’s an example session:

Welcome to The Echo Nest API Shell
 type 'help'
nest% help
0) alias - adds a pseudonym or shorthand term for a command
1) chain - execute multiple commands on a single line
2) delay - pauses for a given number of seconds
3) echo - display a line of text
4) enid - gets the ENID for an arist
5) gc - performs garbage collection
6) getMaxCacheTime - gets the cache time
7) get_audio - gets audio for an artist
8) get_blogs - gets blogs for an artist
9) get_fam - gets familiarity for an artist
10) get_hot - gets hotttnesss for an artist
11) get_news - gets news for an artist
12) get_reviews - gets Reviews for an artist
13) get_similar - finds similar artists
14) get_similars - finds similar artists to a set of artists
15) get_urls - gets Reviews for an artist
16) get_video - gets video for an artist

( .. commands omitted  ..)

53) trackTatums - gets the tatums of a track
54) trackTempo - gets the overall Tempo of a track
55) trackTimeSignature - gets the overall time signature of a track
56) trackUpload - uploads a track
57) trackUploadDir - uploads a directory of tracks
58) trackWait - waits for an analysis to be complete
59) version - displays version information
nest%

nest% get_similar weezer
Similarity for Weezer
 1.00 The Smashing Pumpkins
 0.50 Ozma
 0.33 Fountains of Wayne
 0.25 Jimmy Eat World
 0.20 Veruca Salt
 0.17 The Breeders
 0.14 Nerf Herder
 0.13 The Flaming Lips
 0.11 Death Cab for Cutie
 0.10 Rivers Cuomo
 0.09 The Rentals
 0.08 Size 14
 0.08 Nada Surf
 0.07 Third Eye Blind
 0.07 Chopper One
nest%

nest% get_fam Decemberists
Familiarity for The Decemberists 0.8834854
nest%
nest% trackUpload  "09 When I'm Sixty-Four.MP3"
ID: baad7cab21b853ea5ead4db0a12b1df8
nest% trackDuration
Duration: 157.96104
nest%
nest% trackTempo
140.571 (0.717)
nest%

If you are interested in playing around with the Echo Nest API but don’t want to code up your own application, typing in webservice URLs by hand gets pretty old, pretty quickly. The Echo Nest shell gives you a simpler way to try things out.

, , ,

1 Comment

The first music app in the Java App Store?

At the JavaOne keynote this morning, James Gosling and Jonathan Schwartz gave a demo of the new Java App store in front of 20,000 Java developers.    The Java App store is new online store for Java apps.  It’s just like the iPhone App store for Java.  Oh .. and it has about a billion potential shoppers.  One of the very first apps in the store  (and as far as I can tell, the only music app) is an application called Music Explorer FX.  This is a soon to be released Java FX application designed to help you explore the world of music.  I’ve had the opportunity to play with the Music Explorer – it is really quite cool. (and it makes heavy use of the Echo Nest API, which makes it doubly cool).  The developer of the application, Sten Anderson has written a teaser about the app on his blog.  As he says, stay tuned for to find out when the app will be available.

, , , , , ,

Leave a comment

Removing accents in artist names

If you write software for music applications, then you understand the difficulties in dealing with matching artist names.   There are lots of issues: spelling errors, stop words (‘the beatles’ vs. ‘beatles, the’ vs ‘beatles’),  punctuation (is it “Emerson, Lake and Palmer” or “Emerson, Lake & Palmer“),  common aliases (ELP, GNR, CSNY, Zep), to name just  a few of the issues. One common problem is dealing with international characters.   Most Americans don’t know how to type accented characters on their keyboards so when they are looking for Beyoncé they will type ‘beyonce’.    If you want your application to find the proper artist for these queries you are going to have deal with these missing accents in the query.  One way to do this is to extend the artist name matching to include a check against a version of the artist name where all of the accents have been removed.   However, this is not so easy to do –  You could certainly  build  a mapping table of all the possible accented characters, but that is prone to failure. You may neglect  some obscure character mapping  (like that funny ř in Antonín Dvořák).

Luckily, in Java 1.6 there’s a pretty reliable way to do this.  Java 1.6 added a Normalizer class to the java. text package.  The Normalize class allows you to apply Unicode Normalization to strings.  In particular you can apply Unicode decomposition that will replace any precomposed character into a base character and the combining accent.  Once you do this, its a simple string replace to get rid of the accents.  Here’s a bit of code to remove accents:

    public static String removeAccents(String text) {
          return Normalizer.normalize(text, Normalizer.Form.NFD)
               .replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
    }

This is nice and straightforward code, and has no effect on strings that have no accents.

Of course ‘removeAccents’ doesn’t solve all of the problems – it certainly won’t help you deal with artist names like ‘KoЯn’ nor will it deal with the wide range of artist name misspellings.   If you are trying to deal normalizing aritist names   you should read  how Columbia researcher Dan Ellis has approached the problem.   I suspect that someday,   (soon, I hope) there will be a magic music web service  that will solve this problem once and for all and you”ll never again have to scratch our head at why you are listening to a song by Peter, Bjork and John, instead of a song by Björk.

, ,

4 Comments

The BPM Explorer

Last month I wrote about using the Echo Nest API to analyze tracks to generate plots that you can use to determine whether or not a machine is responsible for setting the beat of a song.   I received many requests to analyze tracks by particular  artists, far too many for me to do without giving up my day job.   To satisfy this pent up demand for click track analysis I’ve written an application called the BPM Explorer that you let you create your own click plots.  With this application you can analyze any song in your collection, view its click plot and listen to your music, synchronized with the plot.  Here’s what the app looks like:

Check out the application here:  The Echo Nest BPM Explorer.  It’s written in Processing and deployed with Java Webstart, so it (should) just work.

My primary motiviation for writing this application was to check out the new Echo Nest Java Client to make sure that it was easy to use from Processing.   One of my secret plans is to get people in the Processing community interested in using the Echo Nest API.  The Processing community is filled with some  ultra-creative folks that have have strong artistic, programming and data visualization skills.   I’d love to see more song visualizations like this and this that are built using the Echo Nest APIs.  Processing is really cool – I was able to write the BPM explorer in just a few hours (it took me longer to remember how to sign jar files for webstart than it did to write the core plotter).    Processing strips away all of the boring parts of writing graphic programming (create a frame,  lay it out with a gridbag, make it visible,  validate, invalidate, repaint, paint arghh!). For processing, you just write a method ‘draw()’ that will be called 30 times a second.   I hope I get the chance to write more Processing programs.

Update: I’ve released the BPM Explorer code as open source – as part of the echo-nest-demos project hosted at google-code.  You can also browse the read  for the BPM Explorer.

, , , ,

11 Comments

New Java Client for the Echo Nest API

Today we are releasing a Java client library for the Echo Nest developer API.   This  library gives the Java programmer  full access to the Echo Nest developer API. The API includes artist-level methods such as getting artist news, reviews, blogs, audio, video, links,  familiarity, hotttnesss, similar artists, and so on.  The API also includes access to the renown track analysis API that will allow you to get a detailed musical analysis of any music track. This analysis includes loudness, mode, key, tempo, time signature, detailed beat structure, harmonic content, and timbre information for a track.

To use the API you need to get an Echo Nest developer key (it’s free) from developer.echonest.com.   Here are some code samples:

// a quick and dirty audio search engine
   ArtistAPI artistAPI = new ArtistAPI(MY_ECHO_NEST_API_KEY);

   List<Artist> artists = artistAPI.searchArtist("The Decemberists", false);
   for (Artist artist : artists) {
       DocumentList<Audio> audioList = artistAPI.getAudio(artist, 0, 15);
       for (Audio audio : audioList.getDocuments()) {
          System.out.println(audio.toString())
       }
   }
// find similar artists for weezer
   ArtistAPI artistAPI = new ArtistAPI(MY_ECHO_NEST_API_KEY);
   List<Artist> artists = artistAPI.searchArtist("weezer", false);
    for (Artist artist : artists) {
          List<Scored<Artist>> similars = artistAPI.getSimilarArtists(artist, 0, 10);
          for (Scored<Artist> simArtist : similars) {
              System.out.println("   " + simArtist.getItem().getName());
          }
     }

// Find the tempo of a track
    TrackAPI trackAPI = new TrackAPI(MY_ECHO_NEST_API_KEY);
    String id = trackAPI.uploadTrack(new File("/path/to/music/track.mp3"), false);
    AnalysisStatus status = trackAPI.waitForAnalysis(id, 60000);
    if (status == AnalysisStatus.COMPLETE) {
       System.out.println("Tempo in BPM: " + trackAPI.getTempo(id));
    }

There are some nifty bits in the API.  The API will cache data for you so frequently requested data (everyone wants the latest news about Cher) will be served up very quickly. The cache can be persisted, and the shelf-life for data in the cache can be set programmatically (the default age is one week).  The API will (optionally) schedule requests to ensure that you don’t exceed your call limit.   For those that like to look under the hood, you can turn on tracing to see what the method URL calls look like and see what the returned XML looks like.

If you are interested in kicking the tires of the Echo Nest API and you are a Java or Processing programmer, give the API a try.

If you have any questions / comments or problems abut the API  post to the Echo Nest Forums.

, ,

1 Comment

track upload sample code

One of the biggest pain points users have with the Echo Nest developer API is with the track upload method.  This method lets  you upload a track for analysis (which can be subsequently retrieved by a number of other API method calls such as get_beats, get_key, get_loudness and so on).   The track upload, unlike all of the other of The Echo Nest methods requires you to construct a multipart/form-data post request. Since I get a lot of questions about track upload I decided that I needed to actually code my own to get a full understanding of how to do it – so that (1) I could answer detailed questions about the process and (2) point to my code as an example of how to do it.   I could have used a library (such as the Jakarta http client library) to do the heavy lifting but I wouldn’t have learned a thing nor would I have some code to point people at.  So I wrote some Java code (part of the forthcoming Java Client for the Echo Nest web services) that will do the upload.

You can take a look at this post method in its google-code repository. The tricky bits about the multipart/form-data post is getting the multip-part form boundaries just right.  There’s a little dance one has to do with the proper carriage returns and linefeeds, and double-dash prefixes and double-dash suffixes and random boundary strings.  Debugging can be a pain in the neck too, because if you get it wrong,  typically the only diagnostic one gets is a ‘500 error’ which means something bad happened.

Track upload can also be a pain in the neck because you need to wait 10 or 20 seconds for the track upload to finish and for the track analysis to complete.  This time can be quite problematic if you have thousands of tracks to analyze.  20 seconds * one thousand tracks is about 8 hours.  No one wants to wait that long to analyze a music collection.  However, it is possible to short circuit this analysis.  You can skip the upload entirely if we already have performed an analysis on your track of interest.   To see if an analysis of a track is already available you can perform a query such as ‘get_duration’ using the MD5 hash of the audio file.  If you get a result back then we’ve already done the analysis and you can skip the upload and just use the MD5 hash of your track as the ID for all of your queries.   With all of the apps out there using the track analysis API, (for instance, in just a week, donkdj has already analyzed over 30K tracks) our database of pre-cooked analyses is getting quite large – soon I suspect that you won’t need to perform an upload of most tracks (certainly not mainstream tracks). We will already have the data.

, , , ,

7 Comments