| Reference | Downloads | Github

Sound doesn't work in PsychoJS

Sorry but I didn’t get an answer to my last thread. I really don’t know what to do.

Description of the problem: Ok I have a SoundComponent in my Builder Experiment and want to change which sounds get played through a code component.(reason being that one out of 5 sound files should be randomly played for the user)

Now I have no Idea how to accomplish this in PsychoJS since the setSound function doesn’t seem to work and neither does putting a $audioString in the Sound field and then assigning it my “audio/file.mp3” string.

  1. You can’t do MP3s at all in PsychoJS (it’s technically proprietary and the sound decoding library PsychoJS uses does not support it). Converting it to .wav is probably your best bet.
  2. I am unsure if this is even possible right now. I know you can’t create sound objects in a code component online, but it may also be that you can’t get it to load a sound from a code component either. If you set a sound variable in a “begin experiment” code pane, does that work?

Oh ok thank you that is good to know!

Hmm I mean that would explain why none of my attempts are working. By set a sound variable do you mean soundComponent.setSound(“audio.wav”)?

Yes. I’m not sure that you can use setSound at all in a code component. I may be wrong, I haven’t tried, but my impression is that the way sounds are loaded online may not work with that.

No that doesn’t work sadly.

I now am trying to get it to work by having a conditions.csv file and having all my audio files in there but it doesn’t seem to be possible to just use one of the rows and not all of them.

That may be possible. See this thread: ReferenceError: slice is not defined