Sound not playing with PTB, but code does not return error

Dear psychopy users,
I an running an experiment on a new laptop (dell precision 3551, realtek audio), and I don’t understand why sounds (using PTB as audioLib) don’t play (see code snippet below; works perfectly on my dell xps), despite the code returning no error. Any idea? Please note that I am using Psychopy 3.2.4

from psychopy.hardware import keyboard
from psychopy.preferences import prefs
prefs.hardware['audioLib'] = ['PTB']
from psychopy import sound

mySound = sound.Sound('A', secs = 0.08)
mySound.play()
core.quit()

EDIT:
adding win.flip() before mySound.play() solves the issue. Any idea why?

@Servant_Mathieu with that simple example, it looks like you are quitting the experiment before the sound has had a change to play. Adding a sleep command before quitting should also give the sound a chance to play

from psychopy.hardware import keyboard
from psychopy.preferences import prefs
prefs.hardware['audioLib'] = ['PTB']
from psychopy import sound, core
import time

mySound = sound.Sound('A', secs = 0.08)
mySound.play()
time.sleep(1)
core.quit()

@dvbridges
Ok I’ve got it. I thought the .play() command would block the code flow until the sound is actually played, but that’s not the case. One remaining problem I have is that the sound is not always the same when I run the code several times. Sometimes it is attenuated. Any idea why?

Not sure tbh, could be that it is slow to load the initial audio. Does the same happen if you loop over the sound a few times? e.g.,

for i in range(10):
    mySound.play()

Also ensure your audio latency mode is set to “aggressive”:

prefs.hardware['audioLatencyMode'] = 3

Doesn’t solve the problem. When the code runs, the sound is always the same. But if I run the code several time, the sound is sometimes louder (without changing the volume of course). The same happens when I use headphones, or if I specify the sample rate of the synthesized tone.