OS: Win10
PsychoPy Standard version: 2021.1.2
Hello! I am trying to create a oral digit span task where sound files say a letter followed by random numbers. I am trying to use the sound component in the builder to make the program play a random sound from my folder. I am using the code component to create a list of the sounds in my folder and make the program chose the sound using “random.choice”.
Here is my code:
Before experiment:
import random
Begin experiment & each frame:
digit1 = random.choice([“1.wav”,“2.wav”,“3.wav”,“4.wav”,“5.wav”,“6.wav”,“7.wav”,“8.wav”,“9.wav”])
In the sound component, I input $digit1 to specify the file.
This method works with the text component when I have values (1,2,3,…) in my list but here the program seems to not want to accept the strings in my list as a file name.
If I set the sound to “constant” I get this error:
digit_1 = sound.Sound(digit1, secs=-1, stereo=True, hamming=True,
NameError: name ‘digit1’ is not defined
If I set the sound to “set every repeat” I get this error:
Traceback (most recent call last):
File “D:…\trial\Trial 4 in 10s_lastrun.py”, line 1755, in
digit_1.setSound(digit1, hamming=True)
File “D:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_ptb.py”, line 428, in setSound
_SoundBase.setSound(self, value, secs, octave, hamming, log)
File “D:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound_base.py”, line 174, in setSound
raise ValueError(msg % value)
ValueError: Sound: bad requested frequency 5
I have very limited python knowledge, so I tried changing the code in some ways, using the print() function, changing how I make my list, changing when the code happens, changing the audio library (program says to use ptb), sadly I am not good enough at coding to find a solution. The problem doesn’t come from my .wav files as they do work in my other program where I don’t randomize the numbers. I would be grateful for any help!