Could you help me understand why audio playback works in Builder mode but fails in Code mode?

Hello,

I’m encountering an issue where audio playback works correctly in Builder mode but fails in Code mode. Specifically, I receive the following error message in Code mode: Audio test failed: cannot unpack non-iterable NoneType object

I set audioLib = ['sounddevice'] or audioLib = ['PTB'] in the userPrefs.cfg file.
In Code mode, I use the following test script:

from psychopy import prefs, sound, core
prefs.hardware[‘audioLib’] = [‘sounddevice’] # Also tested with ‘PTB’ and ‘pyo’
prefs.hardware[‘audioDevice’] = ‘Speakers (Realtek(R) Audio)’
print(f"Audio library: {prefs.hardware[‘audioLib’]}“)
print(f"Audio device: {prefs.hardware[‘audioDevice’]}”)

try:
tone = sound.Sound(440, secs=1.0)
tone.play()
core.wait(1.0)
print(“Audio test successful!”)
except Exception as e:
print(f"Audio test failed: {e}")

It would be great if someone could answer the following questions:

  1. Why does the sounddevice backend fail to initialize properly in Code mode?
  2. Are there any additional steps I need to take to ensure the audio device is correctly configured for Code mode?

Thanks.

Try setting more parameters in your sound object.

1 Like

Hi wakecarter,

Thanks for your reply and suggestion. Adding more parameters and enforcing stereo output solved the issue!