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