I’ve been testing things out and the same computer (Legion 5) can play sounds with its internal speakers if I use ‘sounddevice’, ‘pyo’ or ‘pygame’ for the ‘audioLib pref’, when running the same script as @alexanderpei, kind of similar to what @sol described. Trying to play the very same sound with PTB produces the same error as mention earlier.
Another thing I noticed, which is more problematic in my case, is that when I use the PTB engine the Windows audio volume setting is overridden when using an external device with its own drivers. It doesn’t matter whether I set the volume to 1% or 100% in Windows - the experiment still plays the audio at the exact same volume. This happens with the ‘EIZO FlexScan EV2451’ monitor I mentioned earlier. This monitor uses ‘NVIDIA High Definition Audio’ for handling audio. I could only find this somewhat similar thread about PTB itself and NVIDIA HDA drivers, and the PTB developer there suggested that something might be wrong with the Windows installation itself, but in my case the Windows installation is very fresh, and it’s specifically PTB that’s having issues. pysound etc all respect the Windows volume setting.
Actually, I now had a look at Windows ‘control panel->sound->manage sound devices->EV2451->advanced’. If I there disable ‘allow programs to take full control of this unit’, then attempting to run the experiment with PTB and the external monitor’s audio now also produces the error
AttributeError: '_MasterStream' object has no attribute 'handle. Since this setting is already active for the Legion 5 built-in speakers however, I can’t use this to make PTB work with the built-in speakers, but maybe it will help to understand what’s happening.
You may need to use a different sound card if audio timing is critical.
I don’t think this is really the issue. If I plug in my really cheap in-ear headphones to the computer, I can use them with PTB just fine (and with them, for whatever reason, PsychoPy does respect the Windows audio volume setting), in spite of them relying on the same sound card and drivers as my built-in speakers.
PTB is doing something really, really odd here.