| Reference | Downloads | Github

Issue playing sounds on Pavlovia

Yesterday I posted a problem I was having in making a trial sound experiment work on Pavlovia, as I was getting the error “ReferenceError: resource is not defined” . Note that there was no issue when I exported the HTML on PsychoPy. I’ve gone through the fixes that other people have made in order to get this to work (checking the index.html pointers, and making sure that .wav is shown in the file names), and generating a new trial auditorytesttues to see if it worked. It doesn’t, and still results in the same error. This error doesn’t occur when just showing images, only sounds. I believe the problem may be to do with how sounds are instructed in the js files - I don’t have a programming background and so this is just my guess. As I cannot upload the js files here perhaps someone could help look at my js files. Alternatively, if it’s possible to point me in the direction of a sound experiments js code that works and I can see whether I can identify what needs to be corrected in mine. Thanks.

HI @JamesW, this issue is being looked at now and we are awaiting a response from the server team. The issue only appeared for 3.1, so you could carry on and try with 3.0.6 just to get things moving, but there fix will come very soon for the latest version.

Thanks @dvbridges subsequent to your comment I’ve downloaded 3.0.6 instead and created a new test experiment at but received an “unknown resource” error. I saw that when I exported to HTML it created a resources folder but didn’t put the sound file in there and so it wasn’t uploaded to gitlab. I’ve subsequently done that but it still generated an “unknown resource” error. I then looked at the javascript files and saw that the sound file didn’t get exported to the folder. I’ve now done that and it works okay now.

Hi @JamesW, can you try again with the latest version? We had confirmation that is was very recently fixed.

Hi @dvbridges I’ve downloaded 3.1.1 but the “unknown resource” error message is still generated - and so am fixing it manually (by putting the sound file in the resources folder, plus adjusting the file name on the js files so that it has the file type “.wav” at the end). Thanks, James

Ok, I was referring to the other issue with the resource error being fixed. Thats odd, I cannot recreate the error. If I add the filename to the sound component (e.g., tone.wav), and then export the html, it collects the file and moves it to resources folder, and writes the correct filename with extension in the JS file. Would you mind sharing a simple example so I can attempt to recreate this error?

Hi @dvbridges I’ve tried again doing it from scratch and it now is adding the files to the resources folder and adding .wav to the end of the file name on javascript. However I’m still getting the Unknown Resource error - I’ve added you on gitlab in case you’re able to take a look thanks

Ah, I think this is an issue with the path separator. You should use forward slash in your file paths when using JS e.g., ExperimentStimuli/Block1/voice_high.wav

Thanks @dvbridges I forgot to do that. I have now deleted the old and created a new experiment in which that’s fixed - but now there’s another error ReferenceError: msg is not defined. Sorry - I know this isn’t related to the original query any more. I’ve gone into the js file and seen that it doesn’t define msg, therefore I’ve added
var msg;
msg = “”;
But the problem is then that although it now runs on Pavlovia, it doesn’t provide feedback to each participant on their response, as it does in PsychoPy, which is coded as follows:
if key_resp_2.corr:
msg = “Correct!”
msg = “Oops! That was wrong”

I’ve looked at the js files but am unsure how to adjust so it does this. I’m not sure whether I’ve done something incorrectly on PsychoPy in the first place that means that although it runs fine offline, it doesn’t online?

Ok, if you are using a code component, you do have to manually translate your python code into JavaScript. Its not too different from Python, and you have the code type menu in the code component to make this possible. If you select “both” as a code type, you see Python and JS side by side. In the code component, try:

// Begin Routine
msg = '';

// End Routine
if (key_resp_2.corr === 1) {
    msg = "Correct";
} else {
    msg = "Oops! That was wrong"

You do not need to use var, because if you define a variable in a code component, PsychoPy will add var outside the function to give it global scope. Anyway, try that and let me know.

Thanks very much @dvbridges - that’s fixed it.

Hi @dvbridges, I am having a similar problem where I have used a code component to insert a background track into each of my trials, but when I piloted on Pavlovia, the background tracks simply did not play. After looking at your comments, I went into the code component and selected “Auto > JS,” so that it translated the Python to JS in the second window on the right. However, now when I pilot on Pavlovia, right at the beginning of the experiment, I get the message: " TypeError: Cannot read property ‘_psychoJS’ of undefined "
Any Advice? Thank you.