If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): Windows 11 PsychoPy version (e.g. 1.84.x): v2024.1.5 Standard Standalone? (y/n) If not then what?: y What are you trying to achieve?: I have a large number of audio files I wish to play to about 20 participants, but the audio files are all completely different for each individual participant (180 per participant). However, because I’m running this study online (via Pavlovia), I’m trying to avoid preloading the audio files for all participants before the participant ID has been confirmed (e.g., 001) because it would take ages for the study to load for a participant. I would use the participant ID to only preload and playback audio files which start with the same ID (e.g., 001_audiofile3.wav)
What did you try to make it work?: I tried to add a code component to the first routine of the experiment and type custom code that would override the automatic loading of all audio files in the “additional resources” module (I need to have all the audio files in here for the experiment to playback ANY audio). I alternatively tried using the newer resource manager component to specify I only want to load a subset of files by participant ID since I saw it’s supposed to replace loading of files from the additional resources module, but I don’t think this component can use custom file names/file paths based on the current participant number.
I’ve been going round in circles with this for a few days and haven’t come across a working solution for something that I thought would be relatively simple. Please help if you have any clues!
I should also mention I’m a relative beginner at PsychoPy, any additional non-builder implemented JavaScript goes mostly over my head so any good explanations of JS-coded solutions would be super appreciated!
Is this for an online experiment? If so you can use the resource manager component (which I notice you have already tried - I’ll share some notes below on that) or the static component to load specific resources trial by trial.
Since the resource manager component doesn’t take a variable at the moment (as you describe) a bit of branching might be needed. I am attaching an example .psyexp file (note that the resource manager components in this example do not have the resources - you would need to add resources to the resources field).
In this example group 1 gets one set of resources and group 2 gets another. The first routine looks at which group we are in and decides which loading routine will be used. The loops around the two other routines are turned on/off from that first routine.
Alternatively there are some examples that use a code component (I will attach that here as well) that involves some specific JavaScript. In this example I want to load the mp3 file 'sample_brazil.mp3'
In the Begin Routine tab we initiate the download
// an example of downloading a specific audio file
selectedResource = 'sample_brazil.mp3';
console.log('starting download...')
psychoJS.serverManager.prepareResources([
{
'name': selectedResource,
'path': selectedResource,
'download': true
}
]);
additionalResourceStep = 'DOWNLOAD_STARTED';
In the Each frame tab we wait until this specific resource has downloaded.
//waiting until download complete
if (t >= 0.1)
{
if (additionalResourceStep === 'DOWNLOAD_STARTED')
{
console.log('waiting for ', selectedResource, ' to download');
additionalResourceStep = 'WAITING_FOR_DOWNLOAD';
}
if (additionalResourceStep === 'WAITING_FOR_DOWNLOAD')
{
const additionalResourceStatus = psychoJS.serverManager.getResourceStatus(selectedResource);
// not downloaded yet: flip
if (additionalResourceStatus !== core.ServerManager.ResourceStatus.DOWNLOADED)
{
return Scheduler.Event.FLIP_REPEAT;
}
else
{
console.log(selectedResource, ' is downloaded: present it');
additionalResourceStep = 'DOWNLOADED';
continueRoutine = false;
}
}
}
If you wanted to load a spreadsheet then you would put something like this in a loop and have selectedResource be the column header listing the audio files in your spreadsheet.