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.