Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Search sounds and start loading them
let pageCounter = 0;
const freesoundMaxPageSize = 150;
const pagesToGet = Math.ceil(maxResults / freesoundMaxPageSize);
const extraDescriptors = [
'lowlevel.mfcc.mean',
'sfx.tristimulus.mean',
'tonal.hpcp.mean',
];
const promises = [];
while (pageCounter < pagesToGet) {
const maxPageResults = (pageCounter + 1 !== pagesToGet) ?
Math.min(maxResults, freesoundMaxPageSize) :
maxResults - (pageCounter * freesoundMaxPageSize);
freesound.setToken(sessionStorage.getItem('appToken'));
promises.push(freesound.textSearch(query, {
page: pageCounter + 1,
page_size: maxPageResults,
group_by_pack: 0,
filter,
fields: 'id,previews,name,analysis,url,username,duration,tags,license,download,similar_sounds',
descriptors: extraDescriptors.join(),
sort: sorting,
}));
pageCounter += 1;
}
return Promise.all(promises);
}
export function miniSearch(query, maxDuration) {
const pageSize = 1;
const promises = [];
freesound.setToken(sessionStorage.getItem('appToken'));
promises.push(freesound.textSearch(query, {
page_size: pageSize,
filter: `duration:[0%20TO%20${maxDuration}]`,
}));
return Promise.all(promises);
}