Freesound2  API client for freesound.org


Introduction


Freesound.org is a collaborative database of sound samples licensed under Creative Commons, supported by the Music Technology Group at Universitat Pompeu Fabra (Barcelona). In its current implementation, Freesound.org provides a web API based on REST principles. The general documentation for the API can be found at http://www.freesound.org/docs/api/. This quark provides a client for accessing the Freesound API from within SuperCollider. For the moment, only the Sound resource is supported. Prospective users are requested to apply for an API key at http://www.freesound.org/api/apply/. Being a web API, this form expects you to fill information about a hypothetical web application, but there is no restriction for using the API for music creation or performance. For general discussion about the API, join the google group: http://groups.google.com/group/freesound-api.


The API provides several response formats, but JSON is generally preferred. This quark provides a convenience wrapper around most of the functionality by requesting resources via curl, and mapping JSON responses to SC Dictionary objects. 


Examples


// The API key should be set before any request

Freesound2.api_key="<your_api_key_here>";


// get sound by id

f = FS2Sound.get_sound(127529);


// result is a dictionary, inclusing tags and other metadata

f.keys().postln;

f[\tags].postln;

f[\description].postln;

f[\original_filename].postln;


// retrieve the original sound file

f.retrieve("/tmp/",{"done!".postln});


// retrieve a compressed preview, 'hq' or 'lq' qualities and 'mp3' or 'ogg' formats are supported

f.retrieve_preview("/tmp",{"done!".postln},"lq","ogg");


// get content-based descriptors statistics for the sound.

// http://www.freesound.org/docs/api/resources.html#sound-analysis-resource

a = f.get_analysis(showAll:true);


// get a specific descriptor

a = f.get_analysis("/lowlevel/spectral_centroid");


// retrieve the descriptors frame by frame (download a big JSON file)

f.retrieve_analysis_frames("/tmp/", {"done!".postln})


// get similar sounds according the content-based descriptors

f.get_similar()



// search sounds using the Solr query synatx. 

// See: http://www.freesound.org/docs/api/resources.html#sound-search-resource

r = FS2Sound.search((q:'supercollider'));

r[\sounds].postln;

f = FS2Sound.newFrom(r[\sounds][0]);