AttributeError: '_MasterStream' object has no attribute 'handle'

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2023.2.1
Standard Standalone? (y/n) y
What are you trying to achieve?:
I’m building an experiment template where two images are displayed along with a sound.

What did you try to make it work?:
The sound component does play my audio files (.ogg and in 44100 Hz) when individual files are selected as constants, but it gives error when I put in a variable set in a spreadsheet as the file to play (‘set every repeat’ selected). Variables and filenames in the spreadsheet are accurate and have their extensions. The spreadsheet containing the sound and image variables is selected in the trial loop. Images are shown as expected.

What specifically went wrong when you tried that?:
Below is the full error message.

Generating PsychoPy script...

## Running: C:\Users\Suevin\Desktop\Work\LIDL\PsychoPy\PsychoPy template\experiment\template_lastrun.py ##
1825.4191     INFO     Loaded monitor calibration from ['2022_01_11 12:48']
C:\Program Files\PsychoPy\lib\site-packages\numpy\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:
C:\Program Files\PsychoPy\lib\site-packages\numpy\.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll
C:\Program Files\PsychoPy\lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
  warnings.warn("loaded more than 1 DLL from .libs:"
C:\Program Files\PsychoPy\lib\site-packages\scipy\__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.4
using PyQt5
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
WARNING: pytables package not found. ioHub functionality will be disabled.
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
C:\Program Files\PsychoPy\lib\site-packages\numpy\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:
C:\Program Files\PsychoPy\lib\site-packages\numpy\.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll
C:\Program Files\PsychoPy\lib\site-packages\numpy\.libs\libopenblas64__v0.3.21-gcc_10_3_0.dll
  warnings.warn("loaded more than 1 DLL from .libs:"
WARNING: pytables package not found. ioHub functionality will be disabled.
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate 
Traceback (most recent call last):
PTB-ERROR: Seems the requested audio sample rate 48000.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open:     Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio('Open' [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
PTB-ERROR: Desired audio parameters for device -1 unsupported by audio device: Invalid sample rate 
PTB-ERROR: Seems the requested audio sample rate 48000.000000 Hz is not supported by this combo of hardware and sound driver.
Error in function Open:     Usage error
Failed to open PortAudio audio device due to unsupported combination of audio parameters.
PsychPortAudio:Open: Usage:

pahandle = PsychPortAudio('Open' [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);
C:\Program Files\PsychoPy\lib\site-packages\scipy\__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.24.4
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 227, in __init__
    audio.Stream.__init__(self, device_id=deviceID, mode=mode+8,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 97, in __init__
    self.handle = PsychPortAudio('Open', device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Suevin\Desktop\Work\LIDL\PsychoPy\PsychoPy template\experiment\template_lastrun.py", line 934, in <module>
    run(
  File "C:\Users\Suevin\Desktop\Work\LIDL\PsychoPy\PsychoPy template\experiment\template_lastrun.py", line 363, in run
    sentence = sound.Sound('A', secs=-1, stereo=True, hamming=True,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 332, in __init__
    self.setSound(value, secs=self.secs, octave=self.octave,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 440, in setSound
    _SoundBase.setSound(self, value, secs, octave, hamming, log)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\_base.py", line 168, in setSound
    self._setSndFromNote(value.capitalize(), secs, octave,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\_base.py", line 207, in _setSndFromNote
    self._setSndFromFreq(thisFreq, secs, hamming=hamming)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\_base.py", line 223, in _setSndFromFreq
    self._setSndFromArray(outArr)
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 515, in _setSndFromArray
    self.track = audio.Slave(self.stream.handle, data=self.sndArr,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 622, in stream
    label, s = streams.getStream(sampleRate=self.sampleRate,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 140, in getStream
    return self._getStream(sampleRate,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 187, in _getStream
    self[label] = _MasterStream(sampleRate, channels, blockSize,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\backend_ptb.py", line 248, in __init__
    audio.Stream.__init__(self, mode=mode+8,
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 97, in __init__
    self.handle = PsychPortAudio('Open', device_id, mode,
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <function Stream.__del__ at 0x0000020E09EFE820>
  warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
1.7466     WARNING     Monitor specification not found. Creating a temporary one...
ioHub Server Process Completed With Code:  0
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 236, in __del__
    self.close()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 146, in close
    raise err
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 139, in close
    PsychPortAudio('Close', self.handle)
AttributeError: '_MasterStream' object has no attribute 'handle'
################ Experiment ended with exit code 1 [pid:26664] #################
1855.2329     INFO     Loaded monitor calibration from ['2022_01_11 12:48']

Any help is appreciated. Thank you!

Hello,
Could you please share your experiment here?

Chen

This is the experiment folder (I deleted the old one as it might had wrong audio files).
experiment.zip (2.3 MB)

I tried to use older versions of PsychoPy but it’s all the same; they cannot play audio files provided as variables and I can’t seem to use any other audio libraries than ptb.

Hello,

you requested a sample rate to 48000 Hz but provided stimuli with sampling frequency of 44100 Hz? At last the error message suggests that. Also, some libraries, e.g. pytable, can not be loaded.

Best wishes Jens

I tried switching files to have sampling rate of 48000 Hz and it still didn’t work. My guess is that it doesn’t have to do with sampling rates since the audio files played normally when specified as constants.

Hi @vinibini @JensBoelte @Chen
I’m reviving this discussion because I’m encountering a similar error and trying to find a solution. Here’s the error message I’m receiving:

Running: C:\Users\remy1\Desktop\tasks\task1\Task1_A-SSS-F_lastrun.py 
PTB-ERROR: Desired audio parameters for device 9 seem to be unsupported by audio device: Invalid sample rate

Traceback (most recent call last):
PTB-ERROR: Seems the requested audio sample rate 48000.000000 Hz is not supported by this combo of hardware and sound driver. Error in function Open: Usage error Failed to open PortAudio audio device due to unsupported combination of audio parameters. Prevalidation failure. 

PsychPortAudio:Open: Usage: 
pahandle = PsychPortAudio('Open' [, deviceid][, mode][, reqlatencyclass][, freq][, channels][, buffersize][, suggestedLatency][, selectchannels][, specialFlags=0]);

Traceback (most recent call last):
  File "C:\Users\remy1\Desktop\tasks\task1\Task1_A-SSS-F_lastrun.py", line 3405, in <module>
    setupDevices(expInfo=expInfo, thisExp=thisExp, win=win)
  File "C:\Users\remy1\Desktop\tasks\task1\Task1_A-SSS-F_lastrun.py", line 303, in setupDevices
    deviceManager.addDevice(
  File "C:\Program Files\PsychoPy\lib\site-packages\psychopy\hardware\manager.py", line 253, in addDevice
    raise ManagedDeviceError(
psychopy.hardware.manager.ManagedDeviceError: Failed to open PortAudio audio device due to unsupported combination of audio parameters. Prevalidation failure. 

Exception ignored in: <function Stream.__del__ at 0x00000253915BC160>
Traceback (most recent call last):
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 236, in __del__
    self.close()
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 146, in close
    raise err
  File "C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py", line 139, in close
    PsychPortAudio('Close', self.handle)
AttributeError: 'Stream' object has no attribute 'handle'

The error seems to indicate an issue with the requested audio sample rate (48000 Hz) not being supported by the combination of my hardware and sound driver. I’m using a Creative Live! A3 sound card, and my experiment includes two microphone components, with all audio files set to 48 kHz.

Does anyone have insights into how to resolve this? Is it possible to force PsychoPy to use a different configuration, or is this a compatibility issue with PortAudio?

Thanks in advance for your help!

Hello

You have correctly identified the error. The requested sampling frequency is not supported. Try switching to 44100 Hz.

If you want to play sound, all sound files must be at the sampling rate supported by your hardware on this operating system.

Best wishes Jens

1 Like

Hi @JensBoelte
just a quick update: I have two microphone components, and when I disable them, the experiment works without any errors. I also double-checked all the files (48kHz, 24-bit). So, I believe the error is related to the microphone component. do you think resample to 44.1 kHz could solve the issue?

Hello

All sound-components, microphone, play sound aso., must have the same sampling frequency kHz) and resolution if you can adjust that. For instance, my microphones only suport 48 kHz 16 bit. So, I would create a toy-version of my experiment and test it before resampling all audio files.

Best wishes Jens

1 Like

Hi again @JensBoelte
I tried 48 kHz , 16 and 24 bit and im still getting the same error, I don’t know what to check other than that. im trying also with a toy-version (demo) with some not all audio-files.
any more suggestions ? what to check ?
my laptop is dell windows 11, and sound card is creative life a3 , and mic is ( Rode PodMic)

Hello

Have you ever got the microphone component working without any other sound component?

Best wishes Jens

Hi , actually i didn’t try it yet, i will try to do it today and keep you updated if it works

hello again @JensBoelte
Here’s what I tried:

  1. I created a demo experiment with only the microphone and excluded other sound objects, but the error persisted.
  2. I tested different sampling rates, including 48 kHz and 44.1 kHz, but the crashes continued in both cases.
  3. I swapped out the microphone for another one to rule out compatibility issues, but the problem remained the same.
    I’ve noticed that the issue seems tied to the sound card. When I use the Creative Live! A3, the system crashes, but it works perfectly when I switch to the Focusrite Scarlett 2i2 USB. One key difference is that the Scarlett supports 2-channel audio in its settings, while the Creative card defaults to 4 channels with no option to change it.
    Could the 4-channel configuration of the Creative Live! A3 be causing the crashes? If so, is there any way to work around this limitation? Thanks again for your help!

Hello @ali_alsheikh

Congratulations on finding your problem and its solution.

I do not have a Creative Live! A3 or a Focusrite Scarlett 2i2 USB. I do not know if there is a workaround for the Creative Live! A3.

I have to say that I am a little surprised to read that the Creative always defaults to four channels with no option to change this. The sound card has three inputs, 2 combo inputs and a mobile device input. The XLR connections are mono by default. What does setting the combo input to line or instrument do?

You might have to use the Focusrite.

Best wihes Jens