| Reference | Downloads | Github

Why does work once and other instances of it do not work?

import psychopy
from psychopy import visual, core, event, monitors, sound, clock

# Window
window = visual.Window(
    size=(1024, 768), fullscr=True, screen=0, 
    winType='pyglet', allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True, 

beep = sound.Sound(
    value = 'A', secs = 0.2,
    volume = 1.0) #Beep 1
core.wait(1.0) #Beep 2


the first beep i.e BEEP 1 works perfectly fine but for some reason the second beep i.e BEEP 2 doesn’t work and I can’t seem to figure out why. Is there some process related to that I’m missing out?

Which audio library (backend) are you using?

I removed the unnecessary parts from my code.
Also I don’t understand what you’re asking me, I clearly used the sound module from psychopy but the second audio cue just doesn’t work.

There are multiple sound libraries that PsychoPy can use to play sounds as explained here:

In the application preferences you’ll see them, but you can also control them within the script if you prefer.

Also, what version of PsychoPy are you using?

The latest one I suppose, just installed it a week ago. I also solved the issue but don’t know why it’s responding that way, can you try to explain it to me?

After each play(), I added core.wait(2.0) followed by beep.stop() and this worked. But if I put beep.stop() before core.wait(2.0) l it didn’t work.
Any idea why this is happening?

Oh I see, yes. That’s just because you stopped the sound too fast, or because in the original code you posted above your script ended (which also stops the sound) before you had time to hear anything.

If you aren’t very confident with programming I’d really strongly recomend you use the Builder interface. Actually I’d recommend that for most people even if they are competent programmers! I almost never hand-write the code for my experiments. Using Builder would have avoided simple errors like this.

Thanks for the help and I’ll take your suggestion to account.
But I found something that contradicts your reasoning as shown in the description below:
When I did the below it worked fine - any wait time(core.wait()) works and I tried up to 100 ms.

But when I removed the stop, It didn’t work.

From the above, I don’t think this issue has anything to do about the sound being too fast or the program ending. To confirm this I also reduced the duration of the beep to as low as 0.03s and the same thing happend as stated for the above two scripts.

From this I can say that this is probably happening because the play() doesn’t get reset once the sound is over hence stop() needs to be explicitly defined for the sound to reset. If the stop() isn’t defined then once the sound is over it doesn’t get reset hence when is done the second time I hear nothing. Do you think my reasoning makes sense?

That’s conceivable and would probably depend on the sound lib being used, as mentioned above, but I’m surprised this isn’t causing lots of problems for others if true. Anyway, glad you got a fix.

Which audio library (backend) are you using?

Is there a default backend that is defined if I do not choose one?

Open the application and go to Preferences