| Reference | Downloads | Github

How do I add music to a routine?

OS (Mac):
PsychoPy version (3):

I want to add a 15s music clip to one of the routines in my experiment. There are no loops, its just a randomized series of three different routines.

So far I have tried to add a sound in the settings category of the 15s sound. I replaced “Sound A” with a path that leads to the sound file in a folder on my desktop. I got an error.

Then I tried to take the sound file out of the folder and put it on my desktop but it still didn’t work.

I then removed the “sound” thingy completely from the routine and just added a custom code because someone suggested that. I added in the Begin Routine tab "background_sound = sound.Sound (‘file name’)
And then a stop in the End Routine tab


What am I missing? Is there an easier way to get sound into my routine?

Thank you very much!

I just got you want to put a music for your routine, Why not Audio component? Just put one of them in the Routine and leave duration blank for endless playing and give a relative address to your audio file, I think your addressing to the audio file is wrong due to the image above and check your file extension maybe PsychoPy can not play AUP files.

The error here is simply that the file isn’t where you are telling PsychoPy it is located, or that it isn’t named what you think it is named.

Once you get it into the right location and PsychoPy tries to open it, there may then be another issue that it won’t know what a .aup file is. That isn’t a standard sound format.

I changed the format to a wav file but I don’t know how it got the location wrong? It’s just a file on my desktop so I typed in Desktop/(NameOfFile) Where can I find the right format?

Oh I fixed the problem! It was really dumb, I realized that I had to type in /Users/(myname)/Desktop/(File)
:slight_smile: Thanks for your tips guys!

You should really use relative paths (i.e. relative to where your .psyexp file is), rather than absolute paths. That way you can move your experiment folder, or even run it from another computer, and everything will still work.

i.e. if the sound file is in the same folder as the .psyexp file, it can just be referred to by name. To keep things tidy, if it is in a sub-folder of that folder (called, say sounds), then it can be referred to like this: sounds/nameOfFile.wav

1 Like