Unspecified Javascript Error Related to Sounds

I haven’t counted the number of files, but I did notice that the list of resources which are loaded does not seem to include the sound files, only the images.

I’m trying to create another version of the experiment without the large collection of images for the main experiment, for faster debugging. I’ll post a link as soon as it’s created.

Here is the smaller version of the experiment

Have you looked at Experiment Settings / Online in Builder?

Resources that PsychoPy knows it needs are automatically loaded into memory at the start of the experiment. However, any that are defined in code or in Excel files that are themselves defined in code need to be manually added (either there or on the fly).

Ok, in the small version I just posted I’ve fixed some bugs and re-confirmed it’s running locally. Now when I load that into Pavlovia I can see that it’s definitely loading all the correct resources, but I’m still getting the same error.

Can you set it to running and post the run link here so I can take a look?

Posting the link to the gitlab allows me to see the code but I’d have to fork and create my own version to actually test it.

Here ya go

Selected rows for practiceTrials and mainTrials should be 0:1 not 0

Does it work if you remove your sound codes?

scorrect = new Sound(‘sounds/550.mp3’);
sincorrect = new Sound(‘sounds/270.mp3’);
stimeout = new Sound(‘sounds/375.mp3’);

Personally (and I’ve put this in my crib sheet) I recommend defining sounds using components and them playing and stopping them in code.

Yes, it works if I comment out those lines. However, I had previously set it up with sounds as components but had run into the problem that components can only be played once per routine, and I would like to be able to replay the same sound every time a key is pressed. Is there a way to do that with components?

Here’s how I do it.

You could simply try switching new Sound() to new Audio()

OK! I really, really thought that was going to work, and I got very close. But then I got this error message:

Uncaught (in promise) DOMException: The media resource indicated by the src attribute or assigned media provider object was not suitable.

I tried wav files too, that also didn’t work.

Maybe I need to specify the path to the file as a URL? How do I figure out what that URL should be?

The path should be either just the name or sounds/fileName.mp3 as you had it.

However, I notice that your Python just has numbers. Have a look at my Music Box demo to see that you can play sounds online with frequencies (but not letter notes without translation).

Yes, I am just trying to play conditional feedback sounds. I’ve just looked at your music box solution and it seems like it requires that the sound lasts for the entire routine, right? That will require some significant restructuring of my experiment.

You should be able to start and stop the sound in code once it has been created. What I wasn’t able to do was change the note of a sound (setSound) within a single routine. However, since you only have three sounds you should be able to create them all and play/stop the relevant ones.

Start/stop of the sound using code did not work for my purposes. I am trying to play the feedback sound from the previous trial at the beginning of the next trial, but only for the first 0.1 sec, without stopping the rest of the trial. When I did this in code it would not play consistently (it is a reaction time experiment), and when I tried to have a separate routine that played feedback with the stimulus onscreen it started dropping frames.

So ultimately I’ve concluded that there’s no way to choose between some kind of ISI and playing very short sounds consistently. I’ve therefore chosen to just have the ISI and only give feedback on some trials.

This seems like a pretty important missing feature in psychoJS that it’s impossible to play a simple tone for a specified duration without either a dedicated routine or a code component which may or may not be executed in a timely manner. But oh well, I have something that works well enough now.

I feel like a demo coming on.

Would a minimal version of this be, say, a fixation cross followed by a simple choice eg left and right arrow with a feedback sound at the beginning of the next routine during the fixation cross? I might try one sound as mp3 and the other as a pure frequency.

Yep, although to really address all the issues the feedback sound should be conditional on the response.

1 Like

Try this


I’ve coded all the notes used in Music Box to make a game version. Press the letter of the note that appears and it will play at the start of the next routine (with the specified duration, sharp and octave). If you press the wrong note then you’ll hear the note you press.