Error with auditory stimuli experiments

Hi all,

I have a Thinkpad T14g5 laptop running Linux Debian:
Linux bll4 6.12.27-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.27-1 (2025-05-06) x86_64 GNU/Linux

I have installed Psychopy 2025.1.0 on a python3.10 virtual environment.
Visual experiments work fine, including those with movies (importantly, audio in movies, e.g. in the “MovieStim.py” demo, is reproduced correctly).

However, auditory experiments do not run.
For example, when I try to run the “soundStimuli.py” demo, I get the following error report:

##------------------------------------------------------------------------------------------------------------------------

Running: /opt/python3.10_venv/lib/python3.10/site-packages/psychopy/demos/coder/stimuli/soundStimuli.py

PTB-INFO: Trying to suspend potentially running PulseAudio server… … status 0
PTB-INFO: Using PortAudio V19.7.0-devel, revision unknown
Using ptb (with [‘portaudio’]) for sounds
PTB-INFO: Will use the following logical slave-channel → master-channel mappings for sound output to audio stream 1:
1 → 1 : 2 → 2 :

PTB-INFO: New virtual audio slave device with handle 1 opened and attached to parent device handle 0 [master 0].
PTB-INFO: For 2 channels playback.
PTB-INFO: Real samplerate 44100.000000 Hz. Input latency 0.000000 msecs, Output latency 10.158730 msecs.
Expression ‘ret’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 1742
Expression ‘AlsaOpen( hostApi, parameters, streamDir, &pcm )’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 1774
Exception ignored in: <function Stream.del at 0x7f5a86e1e560>
Traceback (most recent call last):
File “/opt/python3.10_venv/lib/python3.10/site-packages/psychtoolbox/audio.py”, line 236, in del
self.close()
File “/opt/python3.10_venv/lib/python3.10/site-packages/psychtoolbox/audio.py”, line 146, in close
raise err
File “/opt/python3.10_venv/lib/python3.10/site-packages/psychtoolbox/audio.py”, line 139, in close
PsychPortAudio(‘Close’, self.handle)
AttributeError: ‘Stream’ object has no attribute ‘handle’
PTB-INFO: Closing handle 1.
Expression ‘ret’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 1742
PTB-INFO: Closing handle 0.
PTB-INFO: Trying to resume potentially suspended PulseAudio server… … status 0
Expression ‘AlsaOpen( hostApi, parameters, streamDir, &pcm )’ failed in ‘src/hostapi/alsa/pa_linux_alsa.c’, line: 1774
Exception ignored in: <function Stream.del at 0x7f5a86e1e560>
Traceback (most recent call last):
File “/opt/python3.10_venv/lib/python3.10/site-packages/psychopy/demos/coder/stimuli/soundStimuli.py”, line 25, in
tick = sound.Sound(800, secs=0.01, sampleRate=44100, stereo=True) # sample rate ignored because already set
File “/opt/python3.10_venv/lib/python3.10/site-packages/psychopy/sound/backend_ptb.py”, line 128, in init
speaker = SpeakerDevice(speaker)
File “/opt/python3.10_venv/lib/python3.10/site-packages/psychopy/hardware/speaker.py”, line 112, in init
self.createStream()
File “/opt/python3.10_venv/lib/python3.10/site-packages/psychopy/hardware/speaker.py”, line 247, in createStream
raise ConnectionError(
ConnectionError: Failed to setup a PsychToolBox audio stream for device HD-Audio Generic: ALC257 Analog (hw:1,0) (0.0).
##-------------------------------------------------------------------------------------------------------------------------

This is then followed by this log info:

##-------------------------------------------------------------------------------------------------------------------------
0.4728 INFO Trying to load audio library: ptb
0.6485 DEBUG Opening message catalog /opt/python3.10_venv/lib/python3.10/site-packages/psychopy/localization/../app/locale/en_US/LC_MESSAGE/messages.mo for locale en_US
0.7494 INFO Loaded psychtoolbox audio version 3.0.19.696976567
0.7498 INFO sound is using audioLib: ptb
0.8704 DEBUG Found speaker device: HD-Audio Generic: ALC257 Analog (hw:1,0) (0.0)
0.8859 INFO New audio device 0 with handle 0 opened as PortAudio stream:
0.8859 INFO For 2 channels Playback: Audio subsystem is ALSA, Audio device name is HD-Audio Generic: ALC257 Analog (hw:1,0)
0.8859 INFO Real samplerate 44100.000000 Hz. Input latency 0.000000 msecs, Output latency 10.158730 msecs.
0.8860 INFO Created stream for speaker device: HD-Audio Generic: ALC257 Analog (hw:1,0) (0.0)
0.8998 EXP : sampleRate = 44100
0.8998 EXP : channels = None
0.9008 DEBUG Converted audio clip from mono to stereo
0.9012 EXP Sound set volume 0.800
0.9013 DEBUG Found speaker device: HD-Audio Generic: ALC257 Analog (hw:1,0) (0.0)
######## Experiment ended with exit code 1 [pid:22024] #########
##-------------------------------------------------------------------------------------------------------------------------

Digging a little bit into the problem, I have discovered that the error in the “soundStimuli.py” demo is specifically caused by the line:

##-------------------------------------------------------------------------------------------------------------------------
tick = sound.Sound(800, secs=0.01, sampleRate=44100, stereo=True) # sample rate ignored because already set
##-------------------------------------------------------------------------------------------------------------------------

In fact, a simpler script with just one sound stimulus works fine. For example:

##-------------------------------------------------------------------------------------------------------------------------
import sys
from psychopy import logging, prefs
logging.console.setLevel(logging.DEBUG)
prefs.hardware[‘audioLib’] = [‘ptb’]
from psychopy import sound, core

print(‘Using %s (with %s) for sounds’ % (sound.audioLib, sound.audioDriver))

highA = sound.Sound(‘A’, octave=3, sampleRate=44100, secs=0.8, stereo=True)
highA.setVolume(0.8)

highA.play()
core.wait(4.8)
highA.play()
core.wait(4.4)
highA.play()
core.wait(4.6)

core.quit()
##-------------------------------------------------------------------------------------------------------------------------

Any ideas on how I could fix this problem?

Thank you and all the best,
Marco

Hello there,

I’m having the same issue with Ubuntu 24.04-LTS with ALC257 and PsychoPy 2025.1.1, PTB keeps failing, and I can’t run the “soundStimuli.py” … PTB fails with “AlsaOpen(…) failed” and “Failed to setup a PsychToolBox audio stream”.

Also the same happens when i try with a simpler script with just one stimulus…

Did you find any way to workaround this issue?

Thank you,
Lukas.

Hi Lukas,

no, unfortunately I have not found any workarounds for this.

Even if I am now on a freshly upgraded Linux Debian system (Trixie, released on 2025, August 9; Linux bll4 6.12.41+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.41-1 (2025-08-12) x86_64 GNU/Linux),

and despite an upgrade to Psychopy 2025.1.1, the problem persists.

It would be great to have some feedback from the Psychopy’s developers.

Best,
Marco