Hi everyone, I’m trying to create a complex span task in PsychoPy. I have my primary task already set up, but I’m trying to make a secondary task that plays an audio file from my files. It should randomly pull one of my files that says a random number from 1-9.
I have been unable to figure out how to do this. I’ve tried using custom code, but all the code I’ve tried from looking online hasn’t worked. I have my experiment file and my .wav files all in the same folder, but when I try to reference the file in my code, the coder says it can’t find the file. I’m also not sure I’m setting up my Sound Stimulus correctly. Any help would be greatly appreciated. I’m also not opposed to doing it through excel either.
In short, I’m looking for some advice on either how to code this to work, or how to use excel files to make this work. Thanks!
Please could you show images of the relevant bits of your best attempt and the error message? Are you using Builder with code components or coder?
Here is my best attempt, but I will note that this is code I found, so I don’t understand it too well. I am not great at Python. This is what I put in the Begin Routine Tab
from psychopy import sound
sound file names
sound_files = [“1.wav”, “2.wav”, “3.wav”, “4.wav”, “5.wav”, “6.wav”, “7.wav”, “8.wav”, “9.wav”]
Randomly select a sound file
selected_sound = random.choice(sound_files)
Create a Sound object for the selected sound file
selected_sound_object = sound.Sound(selected_sound)
Store the selected sound for later use if needed
Play the selected sound
Wait for the sound to finish playing (adjust the duration if needed)
I got this error message twice:
Tried to create audio stream 22050_2_128 but 48000_2_128 already exists and win32 doesn’t support multiple portaudio streams
And it gives me an alert that there is some unexpected symbol in my Java script, but I have it to where my python automatically converts to the Java script, so I am not sure what to do about that.
Also, I have my sound field set to $sound_files
This suggests that you have sound files with two different bit rates. This should be editable in Audacity, for example.
Personally I never create sound objects in code. Why aren’t you using a sound component?
Thank you for your response. So what do I need to do to fix that? How do I edit those? And I’m not sure how to answer your question haha. I’m new to all of this.
Audacity is free software