Skip to content

Instantly share code, notes, and snippets.

@predakanga
Created April 13, 2012 13:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save predakanga/2376835 to your computer and use it in GitHub Desktop.
Save predakanga/2376835 to your computer and use it in GitHub Desktop.
Echoprint setup and usage

Requirements

For libcodegen

  • Boost >= 1.35
  • zlib

Additional requirements for the codegen binary

  • TagLib
  • ffmpeg - this is called via shell and is not linked into codegen

On Ubuntu or Debian you can install these dependencies with:

sudo apt-get install ffmpeg libboost1.42-dev libtag1-dev zlib1g-dev

On OS-X with homebrew you can use:

brew install ffmpeg boost taglib

Compiling

Checking out the code

Once you have the various requirements installed, you need to check out the code using git clone.

The following is an example of this

~$ git clone -b release-4.12 git://github.com/echonest/echoprint-codegen.git
Cloning into 'echoprint-codegen'...
remote: Counting objects: 665, done.
remote: Compressing objects: 100% (280/280), done.
remote: Total 665 (delta 428), reused 612 (delta 376)
Receiving objects: 100% (665/665), 1.40 MiB | 578 KiB/s, done.
Resolving deltas: 100% (428/428), done.

Once you have the code checked out, you can edit Makefile with your preferred editor to make sure that any configuration variables (such as BOOST_CFLAGS) are correct, and then simply run make to compile the code:

~$ cd echoprint-codegen/
~/echoprint-codegen$ cd src/
~/echoprint-codegen/src$ nano Makefile # edit BOOST_CFLAGS and other variables as necessary
~/echoprint-codegen/src$ make
g++ -Wall -I/opt/local/include `taglib-config --cflags` -fPIC -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG -c -o Codegen.o Codegen.cxx
g++ -Wall -I/opt/local/include `taglib-config --cflags` -fPIC -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG -c -o Fingerprint.o Fingerprint.cxx
g++ -Wall -I/opt/local/include `taglib-config --cflags` -fPIC -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG -c -o MatrixUtility.o MatrixUtility.cxx
g++ -Wall -I/opt/local/include `taglib-config --cflags` -fPIC -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG -c -o SubbandAnalysis.o SubbandAnalysis.cxx
g++ -Wall -I/opt/local/include `taglib-config --cflags` -fPIC -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG -c -o Whitening.o Whitening.cxx
libtool -dynamic -flat_namespace -install_name libcodegen.4.1.2.dylib -lSystem -compatibility_version 4.1 \
-macosx_version_min 10.6 -current_version 4.1.2 -o libcodegen.4.1.2.dylib -undefined suppress \
AudioBufferInput.o AudioStreamInput.o Base64.o Codegen.o Fingerprint.o MatrixUtility.o SubbandAnalysis.o Whitening.o -framework vecLib -framework Accelerate
g++ -Wall -I/opt/local/include `taglib-config --cflags` -fPIC -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG -c -o Metadata.o Metadata.cxx
g++ -Wall -I/opt/local/include `taglib-config --cflags` -fPIC -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG -c -o main.o main.cxx
g++ AudioBufferInput.o AudioStreamInput.o Base64.o Codegen.o Fingerprint.o MatrixUtility.o SubbandAnalysis.o Whitening.o Metadata.o `taglib-config --libs` -lz -lpthread -O3 -DBOOST_UBLAS_NDEBUG -DNDEBUG main.o -o ../echoprint-codegen

Assuming that the process completes with no errors, you should now have an executable, echoprint-codegen with which to generate echoprint codes from just about any audio format; in this case it would be located in the "~/echoprint-codegen" directory.

Usage

Generating echoprint codes

The makefile builds an example code generator that uses libcodegen, called "codegen". This code generator has more features -- it will output ID3 tag information and uses ffmpeg to decode any type of file. If you don't need to compile libcodegen into your app you can rely on this. Note that you need to have ffmpeg installed and accessible on your path for this to work.

./echoprint-codegen billie_jean.mp3 10 30

Will take 30 seconds of audio from 10 seconds into the file and output JSON suitable for querying:

[
{"metadata":{"artist":"Michael Jackson", "release":"Thriller", "title":"Billie Jean", "genre":"", "bitrate":128,"sample_rate":44100, "duration":294, "filename":"billie_jean.mp3", "samples_decoded":330902, "given_duration":30, "start_offset":10, "version":4.12, "codegen_time":0.087329, "decode_time":0.297166}, "code_count":906, "code":"eJztmm2OZacORafEt2E4YGD-Q8jCt1UnXdKlIlVa ..."
]

Querying the Echo Nest

You can POST the output of echoprint-codegen directly to Echo Nest's song/identify server, without any formatting or trimming needed.

The following command uses curl to post the data, which has been stored in the file "post_string" beforehand, and simply displays the result:

curl -F "query=@post_string" http://developer.echonest.com/api/v4/song/identify?api_key=YOUR_KEY
{"response": {"status": {"version": "4.2", "code": 0, "message": "Success"}, "songs": [{"tag": 0, "score": 273, "title": "Billie Jean", "message": "OK (match type 6)", "artist_id": "ARXPPEY1187FB51DF4", "artist_name": "Michael Jackson", "id": "SOJIZLV12A58A78309"}]}}
(you can also use GET, see the API description)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment