If this template helps then use it. If not then just delete and start from scratch.
OS (e.g. Win10): 11 PsychoPy version (e.g. 1.84.x): 22.5 Standard Standalone? (y/n) If not then what?: What are you trying to achieve?:
I am trying to add an audio file in some trials using a random uniform distribution, but I am not sure about the code I have to use for it.
What did you try to make it work?:
I have already tried with np.random.uniform. It works for the random uniform distribution, but I do not know how to add the audio file.
What specifically went wrong when you tried that?:
Include pasted full error message if possible. “That didn’t work” is not enough information.
I have tried this code. However, the sound is played in all the trials and not just in the 25% of them. Also, I need that the audio should be played with a delay of 0.75 ms. That’s why there is that delay condition. I can’t figure out how to make that my audio will play only in the 25% of the trials.
This is the code written in ‘Begin Routine’. And in ‘Begin Experiment’ is just import random.
r = random.random()
tone = ‘ondasin.wav’
if r < 0.25:
value = 1
vol = 1
value = 0
vol = 0
delay = random.random()/2 + 0.25
Ok, you shouldn’t import the random library when using the Builder. It will import all the libraries it needs. With the approach you have chosen, you determine the probability of each trial being played or not. But you write that you want the sound to be played in 25% or all trials. This is different.
Suppose you have 12 trials and you want a sound to play in 25% of the trials, you write this in the Begin Experiment tab of a code component:
Thank you so much. I will try this code. The delay is constant. There are two sound objects that will play at the same time. The first one contains 108 audios and, the second one is the sound I want to be played randomly in the 25% of trials of the first object of sounds (the 108 audios). So, after one audio, from the 108, there must be a delay of 0.75ms before the second one is presented.
Also, I want these audios to sound regardless of whether the participant answers or not. Thank you so much