Error 'Stream' object has no attribute 'handle'

Windows 10
PsychoPyv2021.2.3

Hello!
I have been getting the following error message when trying to test run my experiment on my computer–‘stream’ object has no attribute ‘handle’. I am not sure what this means, or how to fix it. Has anyone had a similar issue, and found a solution? Thank you!

Exception ignored in: <bound method Stream.del of <psychtoolbox.audio.Stream object at 0x0000014DCC4EDF98>>
Traceback (most recent call last):
File “C:\Program Files\lib\site-packages\psychtoolbox\audio.py”, line 236, in del
self.close()
File “C:\Program Files\lib\site-packages\psychtoolbox\audio.py”, line 146, in close
raise err
File “C:\Program Files\lib\site-packages\psychtoolbox\audio.py”, line 139, in close
PsychPortAudio(‘Close’, self.handle)
AttributeError: ‘Stream’ object has no attribute ‘handle’

Experiment ended.

Do you have a microphone component?

1 Like

Thank you! I seem to have missed this thread.
Changing to 44.1 kHz (CD) did not work, but changing to the DVD setting did–no idea why.

Thanks for the suggested solution.

But how can I include multiple microphones in Psychopy Builder? I need several microphones in different routines in my experiment.

Thanks.

Hi There,

Are the multiple microphones connected to different physical microphones? or are you making several recordings throughout the study from the same microphone (but with different components?)

Thanks!
Becca

Hi Becca,
I have single physical microphone.
I’m going to make several recordings throughout my experiment in different routines. So I add one microphone component in one routine, add another microphone component in another routine, resulting in several microphones in my experiment.
But it works only when I include one microphone component in one routine, when I include more than one, it gives the error:

given audio library ptb:

PTB-ERROR: Failed to open audio device 7. PortAudio reports this error: Invalid device
PTB-ERROR: Desired audio parameters likely unsupported by audio device.
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
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]);
Traceback (most recent call last):
File “U:\psyuser\exp\mic\mic_testing\mic_testing_lastrun.py”, line 198, in
sampleRateHz=48000, maxRecordingSize=24000.0
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\microphone.py”, line 483, in init
channels=self._channels)
File “C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py”, line 101, in init
flags)
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <bound method Stream.del of <psychtoolbox.audio.Stream object at 0x0000022CAFEDF320>>
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’

given audio library pyo:

PTB-INFO: Using modified PortAudio V19.6.0-devel, revision unknown
PTB-INFO: New audio device 7 with handle 0 opened as PortAudio stream:
PTB-INFO: For 2 channels Capture: Audio subsystem is Windows WASAPI, Audio device name is External Microphone (Synaptics HD Audio)
PTB-INFO: Real samplerate 48000.000000 Hz. Input latency 10.000000 msecs, Output latency 0.000000 msecs.
PTB-ERROR: Failed to open audio device 7. PortAudio reports this error: Invalid device
PTB-ERROR: Desired audio parameters likely unsupported by audio device.
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
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]);
1.7193 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘pyo’] (in that order).
Traceback (most recent call last):
File “U:\psyuser\exp\mic\mic_testing\mic_testing_lastrun.py”, line 198, in
sampleRateHz=48000, maxRecordingSize=24000.0
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\microphone.py”, line 483, in init
channels=self._channels)
File “C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py”, line 101, in init
flags)
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <bound method Stream.del of <psychtoolbox.audio.Stream object at 0x000001740D476978>>
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’

Ah interesting OK what happens if you go to experiment settings :gear: > Audio > Audio library > select a library that is not PTB ?

I got the same error message:

given sounddevice:

PTB-INFO: Using modified PortAudio V19.6.0-devel, revision unknown
PTB-INFO: New audio device 7 with handle 0 opened as PortAudio stream:
PTB-INFO: For 2 channels Capture: Audio subsystem is Windows WASAPI, Audio device name is External Microphone (Synaptics HD Audio)
PTB-INFO: Real samplerate 48000.000000 Hz. Input latency 10.000000 msecs, Output latency 0.000000 msecs.
PTB-ERROR: Failed to open audio device 7. PortAudio reports this error: Invalid device
PTB-ERROR: Desired audio parameters likely unsupported by audio device.
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
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]);
1.4262 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘sounddevice’] (in that order).
Traceback (most recent call last):
File “U:\psyuser\exp\mic\mic_testing\mic_testing_lastrun.py”, line 198, in
sampleRateHz=48000, maxRecordingSize=24000.0
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\microphone.py”, line 483, in init
channels=self._channels)
File “C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py”, line 101, in init
flags)
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <bound method Stream.del of <psychtoolbox.audio.Stream object at 0x00000215BB2E6B00>>
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’

Experiment ended.

given pygame:

PTB-INFO: Using modified PortAudio V19.6.0-devel, revision unknown
PTB-INFO: New audio device 7 with handle 0 opened as PortAudio stream:
PTB-INFO: For 2 channels Capture: Audio subsystem is Windows WASAPI, Audio device name is External Microphone (Synaptics HD Audio)
PTB-INFO: Real samplerate 48000.000000 Hz. Input latency 10.000000 msecs, Output latency 0.000000 msecs.
PTB-ERROR: Failed to open audio device 7. PortAudio reports this error: Invalid device
PTB-ERROR: Desired audio parameters likely unsupported by audio device.
PTB-ERROR: This could be, e.g., due to an unsupported combination of audio sample rate, audio channel count/allocation, or audio sample format.
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]);
1.3870 WARNING We strongly recommend you activate the PTB sound engine in PsychoPy prefs as the preferred audio engine. Its timing is vastly superior. Your prefs are currently set to use [‘pygame’] (in that order).
Traceback (most recent call last):
File “U:\psyuser\exp\mic\mic_testing\mic_testing_lastrun.py”, line 198, in
sampleRateHz=48000, maxRecordingSize=24000.0
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\microphone.py”, line 483, in init
channels=self._channels)
File “C:\Program Files\PsychoPy\lib\site-packages\psychtoolbox\audio.py”, line 101, in init
flags)
Exception: Failed to open PortAudio audio device due to unsupported combination of audio parameters.
Exception ignored in: <bound method Stream.del of <psychtoolbox.audio.Stream object at 0x000002461C59EBA8>>
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’

Experiment ended.

OK please can you try this:

In your mic components > Hardware tab > Sample Rate (Hz) > select DVD Audio (48Hz)

I think if you do this for all mic components it should work

mic_testing.psyexp (39.3 KB)

I set the samplerate as DVD Audio (48Hz) in my experiment.

I uploaded a demo, could you please help me to check? thanks a lot!

Hi There,

This ran through perfectly my end with no error messages. I am running on windows 10 and PsychoPy version 2022.1.2, can you tell us more about your operating system and version?

Thanks,
Becca

Hi, I run on Windows 10 and Psychopy version 2021.2.3.

Thanks.

Thanks a lot Becca, I update to the new version and my demo works now!

However, in my real experiment which includes 3 microphone components in 3 routines (disA_learningTrial1_mic, disA_learningTrial2_mic, disA_learningTrial3_mic), it gives the error when it goes to line 244, i.e., the 2nd microphone:

############ Running: U:\psyuser\exp\OR test\5.0\OR_5.0_lastrun.py #############
229.8509 INFO Loaded monitor calibration from [‘2022_01_10 22:12’]
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.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
C:\Program Files\PsychoPy\lib\site-packages\numpy.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll
warnings.warn(“loaded more than 1 DLL from .libs:”
Traceback (most recent call last):
File “U:\psyuser\exp\OR test\5.0\OR_5.0_lastrun.py”, line 244, in
disA_learningTrial2_mic = sound.microphone.Microphone(
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\sound\microphone.py”, line 478, in init
self._stream = audio.Stream(
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 0x000001C62F9CE8B0>
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’
################ Experiment ended with exit code 1 [pid:12056] #################
242.2718 INFO Loaded monitor calibration from [‘2022_01_10 22:12’]

I cannot run it with 2 microphones, either, but can run it with one single microphone, although still some warning messages:

############ Running: U:\psyuser\exp\OR test\5.0\OR_5.0_lastrun.py #############
736.5604 INFO Loaded monitor calibration from [‘2022_01_10 22:12’]
pygame 2.1.0 (SDL 2.0.16, Python 3.8.10)
Hello from the pygame community. Contribute - pygame wiki
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.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
C:\Program Files\PsychoPy\lib\site-packages\numpy.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll
warnings.warn(“loaded more than 1 DLL from .libs:”
0.9951 WARNING Monitor specification not found. Creating a temporary one…
ioHub Server Process Completed With Code: 0
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.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
C:\Program Files\PsychoPy\lib\site-packages\numpy.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll
warnings.warn(“loaded more than 1 DLL from .libs:”
################ Experiment ended with exit code 0 [pid:21280] #################
811.8305 INFO Loaded monitor calibration from [‘2022_01_10 22:12’]

Hi There,

So pleased to hear the demo works! but sorry your existing experiment is throwing errors. What happens if you start building something from scratch in the new release? does that work with 2 mics? (remembering to adjust the sampling frequency of each component)

Thanks,
Becca

Thanks, will try that!

Hi Nat,
I’m reviving this topic because I’m getting the exact same error.
Did you manage to fix the problem in the end? If yes, could you please share the solution?

I would really appreciate. Thank you in advance!