psychopy.org | Reference | Downloads | Github

Can't record sound in experiment on PsychoPy

Hello, i’m using PsychoPy 3.2.2 and I want to record sound in my experiment.

The crush that I have is:
1.8660 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’, ‘pyo’, ‘PTB’, ‘sounddevice’] (in that order).
13.7951 WARNING Starting Microphone but sound lib preference is set to be [‘pygame’, ‘pyo’, ‘PTB’, ‘sounddevice’]. Clashes might occur since ‘pyo’ is not preferred lib but is needed for Microphone

But when I change prefs to ‘PTB’, I have this mistake:
11.8420 WARNING Starting Microphone but sound lib preference is set to be [‘PTB’, ‘pygame’, ‘pyo’, ‘sounddevice’]. Clashes might occur since ‘pyo’ is not preferred lib but is needed for Microphone

What should I do to fix the problem?

If I’m not mistaken, the only package, which allows recording sound at the moment is pyo.
In your two attempts, which you show us above, you try to set first pygame, then ptb as your audio libs, which don’t allow audio recording for now (if I’m not mistaken).

Does your experiment still crash if you set your sound lib preference to pyo?
N.b.: What you show us above are warnings, not errors! Does your experiment actually crash, or are you just worried by the warnings and from what you can tell everything is running fine (except for the warnings).

As mistakes I have:

Traceback (most recent call last):
File “C:\Users\Desktop\exp\untitled_lastrun.py”, line 78, in
microphone.switchOn()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\microphone.py”, line 1191, in switchOn
backend_pyo.init(rate=sampleRate)
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_pyo.py”, line 207, in init
devNames, devIDs = get_output_devices()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_pyo.py”, line 109, in get_output_devices
devices = _query_devices()
File “C:\Program Files\PsychoPy3\lib\site-packages\psychopy\sound\backend_pyo.py”, line 86, in _query_devices
info[v.strip().split(": “)[0]] = v.strip().split(”: ")[1]
IndexError: list index out of range

Experiment ended.

Did you get these errors despite setting pyo as your audio lib?

Yes, I have these errors either with pyo or with PTB.

The error seems to be connected to pyo not finding an output device. What did you set as audio device in your preferences?


I do not have any choices here.

Should I set something else except preferences and the microphone in builder? (I am very new to PsychoPy)
On Mac I have the problem:
Traceback (most recent call last):
File “/private/var/folders/32/hcfj7hq51c14f8_5vcw4kjfm0000gn/T/AppTranslocation/B722BD15-21F4-4763-863F-FF3EFFA209EE/d/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/sound/backend_pyo.py”, line 25, in
import pyo
File “pyo/init.pyc”, line 28, in
File “pyo/lib/analysis.pyc”, line 32, in
File “pyo/lib/_core.pyc”, line 58, in
File “pyo/_pyo.pyc”, line 14, in
File “pyo/_pyo.pyc”, line 10, in __load
File “imp.pyc”, line 342, in load_dynamic
ImportError: dlopen(/private/var/folders/32/hcfj7hq51c14f8_5vcw4kjfm0000gn/T/AppTranslocation/B722BD15-21F4-4763-863F-FF3EFFA209EE/d/PsychoPy3.app/Contents/Resources/lib/python3.6/lib-dynload/pyo/_pyo.so, 2): Library not loaded: @loader_path/libportaudio.2.dylib
Referenced from: /private/var/folders/32/hcfj7hq51c14f8_5vcw4kjfm0000gn/T/AppTranslocation/B722BD15-21F4-4763-863F-FF3EFFA209EE/d/PsychoPy3.app/Contents/Resources/lib/python3.6/lib-dynload/pyo/_pyo.so
Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/a1/Downloads/exp/untitled_lastrun.py”, line 18, in
from psychopy import sound, gui, visual, core, data, event, logging, clock, microphone
File “/private/var/folders/32/hcfj7hq51c14f8_5vcw4kjfm0000gn/T/AppTranslocation/B722BD15-21F4-4763-863F-FF3EFFA209EE/d/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/microphone.py”, line 45, in
from psychopy.sound import backend_pyo
File “/private/var/folders/32/hcfj7hq51c14f8_5vcw4kjfm0000gn/T/AppTranslocation/B722BD15-21F4-4763-863F-FF3EFFA209EE/d/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/sound/backend_pyo.py”, line 29, in
raise exceptions.DependencyError(repr(err))
psychopy.exceptions.DependencyError: ImportError(‘dlopen(/private/var/folders/32/hcfj7hq51c14f8_5vcw4kjfm0000gn/T/AppTranslocation/B722BD15-21F4-4763-863F-FF3EFFA209EE/d/PsychoPy3.app/Contents/Resources/lib/python3.6/lib-dynload/pyo/_pyo.so, 2): Library not loaded: @loader_path/libportaudio.2.dylib\n Referenced from: /private/var/folders/32/hcfj7hq51c14f8_5vcw4kjfm0000gn/T/AppTranslocation/B722BD15-21F4-4763-863F-FF3EFFA209EE/d/PsychoPy3.app/Contents/Resources/lib/python3.6/lib-dynload/pyo/_pyo.so\n Reason: image not found’,)

Experiment ended.

Same issue here!
And I’m really desperate, because when I set up the experiment it worked all the time.

Hi, I’ve been constantly meeting the pyo and ptb warnings. Have you figured out how to solve it?

Hi, marcolovoi, Have you solved the ptb/pyo issue in PsychoPy? It constantly reminds me of setting either ptb or pyo as preferred, but when I set either as preferred, warnings will appear that the other one should be preferred.