0

I am developing an android application using JAVA. All I want is to

  1. record a song and generate its hash(CODE), then query the echoprint server for a match.
  2. If a match is not found, then upload it to the server (ingest) for future references.

I have been able to achieve the first part. Can someone suggest me about the second part in JAVA? (P.S. : I've seen how to do it using python codes - but that won't be helpful in my case.)

Another question, may I achieve the second objective with the global echoprint server? Or, do I need to set up one of my own?

The references I've used are:

http://masl.cis.gvsu.edu/2012/01/25/android-echoprint/

https://github.com/gvsumasl/EchoprintForAndroid

Arijit
  • 420
  • 7
  • 14

1 Answers1

0

To insert a song into the echoprint server database, all you need to do is call the ingest method. Basically, it is only a HTTP POST request with correct json body. Here is a Scala code (Java would be very similar) that I am using for that:

import EasyJSON.JSON
import EasyJSON.ScalaJSON
import dispatch.Defaults.executor
import dispatch._
class EchoprintAPI {

  val API_URL = "http://your.api.server"

  def queryURL(code: String) = url(s"$API_URL/query?fp_code=$code")

  def query(code: String): scala.concurrent.Future[ScalaJSON] = {
    jsonResponse(queryURL(code))
  }

  def ingest(json: ScalaJSON, trackId: String): scala.concurrent.Future[ScalaJSON] = {
    val metadata = json("metadata")
    val request = url(s"$API_URL/ingest").POST
      .addParameter("fp_code", json("code").toString)
      .addParameter("artist", metadata("artist").toString)
      .addParameter("release", metadata("release").toString)
      .addParameter("track", metadata("title").toString)
      .addParameter("codever", metadata("version").toString)
      .addParameter("length", metadata("duration").toString)
      .addParameter("genre", metadata("genre").toString)
      .addParameter("bitrate", metadata("bitrate").toString)
      .addParameter("source", metadata("filename").toString)
      .addParameter("track_id", trackId)
      .addParameter("sample_rate", metadata("sample_rate").toString)
    jsonResponse(request)
  }

  def delete(trackId: String): scala.concurrent.Future[ScalaJSON] = {
    jsonResponse(url(s"$API_URL/query?track_id=$trackId").DELETE)
  }

  protected def jsonResponse(request: dispatch.Req): scala.concurrent.Future[EasyJSON.ScalaJSON] = {
    val response = Http(request OK as.String)
    for (c <- response) yield JSON.parseJSON(c)
  }
} 

To generate the fingerprint code, you can use echoprint-codegen command line call or use the Java JNI integration with C lib

Daniel Cukier
  • 11,502
  • 15
  • 68
  • 123
  • Thanks - I'll try it out. Do I need to setup my own server for this? Or can I do this with the global database of echoprint, as well? – Arijit May 06 '14 at 20:11
  • When you said "query the echoprint server for a match" I thought you were referring to your own server. If you are using Echonest servers, then the process is a little bit different, but YES, you can upload tracks there. Check the API documentation, which is different from the open source echoprint-server http://developer.echonest.com/docs/v4/song.html#identify – Daniel Cukier May 07 '14 at 13:15