Failed to open PortAudio audio device

Hello everyone,

I’ve tried to play a sound using examples found on the documentation like this:

import psychtoolbox as ptb
from psychopy import core, prefs
prefs.hardware[‘audioLib’] = [‘ptb’,‘pyo’]
from psychopy import sound

mySound = sound.Sound(‘C:\Users\Alex\bang.wav’)
now = ptb.GetSecs()
mySound.play(when=now)
core.wait(5.0)

But I’m getting an error:

Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.

I can use pyo or sounddevice to successfully play the sound, but it says that ptb should be used for speed. Does anyone have a solution for this?

2 Likes

I am having the same issue when I try to use an external audio device. Did you find any solutions to this?

I haven’t found a solution, but I am getting exactly the same error when I use the built-in speakers on a work laptop (lenovo legion 5, which uses Realtek drivers it seems). Using the built-in speakers on an ‘EIZO FlexScan EV2451’ monitor, or Sennheiser 4.40BT headphones, works with no apparent issues.

There’s also a separate thread where a similar issue is reported.

I also get this on my Dell G5 laptop with Realtek audio. I can work around it by changing the Psychopy preferences -> Hardware -> audio latency mode to 0: Latency not important, but I think this has a negative impact on audio playback timing. You may need to use a different sound card if audio timing is critical.

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.

1 Like