diff --git a/freesound.js b/freesound.js index dc0b934..43e1312 100644 --- a/freesound.js +++ b/freesound.js @@ -8,9 +8,7 @@ var uris = { base : 'https://'+host+'/apiv2', - textSearch : '/search/text/', - contentSearch: '/search/content/', - combinedSearch : '/sounds/search/combined/', + search : '/search/', sound : '/sounds//', soundAnalysis : '/sounds//analysis/', similarSounds : '/sounds//similar/', @@ -276,21 +274,11 @@ } makeRequest(post_url, success, error, {}, null, 'POST', data); }, - textSearch: function(query, options, success, error){ + search: function(query, options, success, error){ options = options || {}; options.query = query ? query : " "; - search(options,uris.textSearch,success,error,SoundCollection); + search(options,uris.search,success,error,SoundCollection); }, - contentSearch: function(options, success, error){ - if(!(options.target || options.analysis_file)) - throw("Missing target or analysis_file"); - search(options,uris.contentSearch,success,error,SoundCollection); - }, - combinedSearch:function(options, success, error){ - if(!(options.target || options.analysis_file || options.query)) - throw("Missing query, target or analysis_file"); - search(options,uris.contentSearch,success,error); - }, getSound: function(soundId,success, error){ makeRequest(makeUri(uris.sound, [soundId]), success,error,{}, SoundObject); }, diff --git a/test.html b/test.html index 584888e..04d15cc 100644 --- a/test.html +++ b/test.html @@ -10,9 +10,8 @@ window.onload = function(){ - freesound.setToken("YOUR_API_KEY_HERE"); + freesound.setToken(""); // Replace with your API key - var fields = 'id,name,url,analysis,username'; // Example 1 // Example of geeting the info of a sound, queying for similar sounds (content based) and showing some analysis // features. Both similar sounds and analysis features are obtained with additional requests to the api. @@ -37,8 +36,8 @@ // When we have printed some sound info, ask for analysis sound.getAnalysis(null,function(analysis){ msg += "Mfccs:
    "; - for (i in analysis.lowlevel.mfcc.mean){ - msg += "
  • " + analysis.lowlevel.mfcc.mean[i] + "
  • " + for (i in analysis.mfcc){ + msg += "
  • " + analysis.mfcc[i] + "
  • " } msg += "
"; displayMessage(msg,'resp1') @@ -46,7 +45,6 @@ // When we have printed the analysis, ask for similar sounds sound.getSimilar(function(sounds){ msg += "Similar sounds:
    "; - for (i =0;i<=10;i++){ var snd = sounds.getSound(i); msg += "
  • " + snd.id + ": " + snd.url + "
  • " @@ -54,73 +52,66 @@ msg += "
"; displayMessage(msg,'resp1') - }, function(){ displayError("Similar sounds could not be retrieved.")}, - {fields:fields}); + }, function(){ displayError("Similar sounds could not be retrieved.")}, {fields: "id,url"}); }, function(){ displayError("Analysis could not be retrieved.")}, true);// showAll }, function(){ displayError("Sound could not be retrieved.")} ); - // Example 2 - // Example of searching sounds: querying the freesound db for sounds and retrieving lowlevel descriptors + // Example of searching sounds: querying the freesound db for sounds and retrieving some audio descriptors var query = "violoncello" var page = 1 var filter = "tag:tenuto duration:[1.0 TO 15.0]" var sort = "rating_desc" - var descriptors = "lowlevel.spectral_centroid" - freesound.textSearch(query, {page:page, filter:filter, sort:sort, fields:fields, descriptors: descriptors}, + var fields = 'id,name,url,analysis,username,spectral_centroid'; + freesound.search(query, {page:page, filter:filter, sort:sort, fields:fields}, function(sounds){ var msg = "" - msg = "

Searching for: " + query + "

" msg += "With filter: " + filter +" and sorting: " + sort + "
" msg += "Num results: " + sounds.count + "
    " for (i =0;i<=10;i++){ var snd = sounds.getSound(i); - msg += "
  • " + snd.name + " by " + snd.username + " with spectral centroid mean value: " + snd.analysis.lowlevel.spectral_centroid.mean.toString() + "
  • " + msg += "
  • " + snd.name + " by " + snd.username + " with spectral centroid mean value: " + snd.spectral_centroid.toString() + "
  • " } msg += "
" displayMessage(msg,"resp2") },function(){ displayError("Error while searching...")} ); + // Example 3 - // Example of content based searching - var t = '.lowlevel.pitch_salience.mean:1.0 .lowlevel.pitch.mean:440'; - var f = ".lowlevel.pitch.var:[* TO 20] AND .metadata.audio_properties.length:[1 TO 10]"; + // Example of sorting sounds using some audio descriptors target, and filtering using audio descriptors + var sortingTarget = "pitch_salience:1.0,pitch:440" + var filter = "pitch_var:[0 TO 20] AND duration:[1 TO 10] AND tag:single-note"; var page_size = 10; - - freesound.contentSearch({target:t,filter:f, page_size : page_size, fields:fields}, + var fields = 'id,name,url,username,pitch,pitch_salience,pitch_var,duration,tags'; + freesound.search("", {filter:filter, page_size:page_size, fields:fields, sort:sortingTarget}, function(sounds){ var msg = "" - msg = "

Content based searching

" - msg += "Target: " + t +"
" - msg += "Filter: " + f +"
" + msg = "

Searching sounds by specifying audio descriptors as a target, and filtering by audio descriptor values and metadata

" + msg += "Filter: " + filter +"
" msg += "Fields: " + fields +"
" msg += "Num results: " + sounds.count + "
    " - msg += "
  • ---------- PAGE 1 ----------
  • " + msg += "---------- PAGE 1 ----------" for (i in sounds.results){ - msg += "
  • " + sounds.results[i].id+ " | " + - sounds.results[i].name + " | " + sounds.results[i].url + "
  • " + msg += "
    " +  JSON.stringify(sounds.results[i], null, 2) + "
    " } - msg += "
" displayMessage(msg,"resp3") // Once we got the first page of results, go to the following one sounds.nextPage( function(sounds){ - msg += "
  • ---------- PAGE 2 ----------
  • " + msg += "---------- PAGE 2 ----------" for (i in sounds.results){ var j = parseInt(i); - msg += "
  • " + sounds.results[j].id.toString(10) + - " | " + sounds.results[j].name + " | " + sounds.results[j].url + "
  • " + msg += "
    " +  JSON.stringify(sounds.results[j], null, 2) + "
    " } - msg += "
" displayMessage(msg,"resp3") }, function(){ displayError("Error getting next page...")}) - },function(){ displayError("Error while content based searching...")} + },function(e){ console.log(e)} ); @@ -131,7 +122,7 @@ var min_lon = 2.005176544189453; var max_lon = 2.334766387939453; filterString = "geotag:\"Intersects("+min_lon.toFixed(3)+" "+min_lat.toFixed(3)+" "+max_lon.toFixed(3)+" "+max_lat.toFixed(3)+")\""; - freesound.textSearch("",{filter:filterString, fields:fields}, + freesound.search("",{filter:filterString, fields:fields}, function(sounds){ var msg = "" msg = "

Geoquerying

" @@ -149,7 +140,6 @@ displayMessage(msg,"resp4") },function(err){ console.log(err);displayError("Error while geoquerying...")} ); - freesound.getUser("Jovica", function(user){