psychopy.org | Reference | Downloads | Github

Microphone component not working- help

OS (e.g. Win10): Mojave
PsychoPy version (e.g. 1.84.x): 3.2.4
Standard Standalone? (y/n) If not then what?: yes
What are you trying to achieve?: Get my microphone component to work

What did you try to make it work?: I’ve tried changing my audio drivers and system preferences. I’ve made sure my mic actually hooks to my Mac and that my Mac can read it.

What specifically went wrong when you tried that?:
I added my microphone component to my experiment but when I try to run it, it does not work. I get the error below. When I remove the component the program works perfectly. I am new to Psychopy and this is my first experiment so it could be a silly mistake but I cannot figure it out. Please let me know what I must do to get the microphone component to work.
Thanks,

Hannah

Code:
Generating PsychoPy script…

Running: /Users/hannah/Documents/Graduate School/Lab/Prospectus/Pilot study/PsychoPy/Mathexperiment _lastrun.py
2020-01-21 20:01:46.877 python[2026:87308] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Traceback (most recent call last):
File “/Users/hannah/Desktop/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/sound/backend_pyo.py”, line 19, 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(/Users/hannah/Desktop/PsychoPy3.app/Contents/Resources/lib/python3.6/lib-dynload/pyo/_pyo.so, 2): Library not loaded: @loader_path/libportaudio.2.dylib
Referenced from: /Users/hannah/Desktop/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/hannah/Documents/Graduate School/Lab/Prospectus/Pilot study/PsychoPy/Mathexperiment _lastrun.py”, line 18, in
from psychopy import sound, gui, visual, core, data, event, logging, clock, microphone
File “/Users/hannah/Desktop/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/microphone.py”, line 45, in
from psychopy.sound import backend_pyo
File “/Users/hannah/Desktop/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/sound/backend_pyo.py”, line 23, in
raise exceptions.DependencyError(repr(err))
psychopy.exceptions.DependencyError: ImportError(‘dlopen(/Users/hannah/Desktop/PsychoPy3.app/Contents/Resources/lib/python3.6/lib-dynload/pyo/_pyo.so, 2): Library not loaded: @loader_path/libportaudio.2.dylib\n Referenced from: /Users/hannah/Desktop/PsychoPy3.app/Contents/Resources/lib/python3.6/lib-dynload/pyo/_pyo.so\n Reason: image not found’,)

Hi Hannah,

I’ve deleted the other identical post in another thread - it just creates confusion and duplication of effort.

You seem to have done the right things. Despite setting PTB as the preferred audio library, the error is still coming from the pyo library - I’m not sure if that means that PTB isn’t available or if it doesn’t actually handle microphones. @jon might be the best one to give guidance here.

I’m afraid PTB backaned doesn’t support mic yet. It can do (technically) and should have better timing, but I haven’t written that support at the PsychoPy interface yet.

What I’m puzzled by is why the loading of the pyo lib isn’t working on this machine :-/
I wasn’t aware of any issues with that lib in the recent releases

@Michael @jon
Hi Michael and Jon,
I got the microphone component to run on a windows computer so there must have been an issue with using my mac. I am now having a problem with hearing the sound once I record something. I have the .wav files but when I play them there are no sounds. I made sure my audio was set to my headset but I still can’t hear anything. I also tried changing audio device to ‘Headset Earphone (Logitech USB Headset)’ and ‘Headset Earphone (USB Audio Device)’ but neither of those work. Any idea what the issue might be?

Thanks,
Hannah

Capture Capture2


Capture4

Hi @jon, it might be relevant… When I bundle Cecilia5 into an app with py2app, I have to manually change _pyo.so’s external lib paths because py2app puts every dylib in the Frameworks folder. I think you have the same problem here. You can take a look at the Cecilia’s builder script:

1 Like

FYI this does appear to be the problem. In my version of PsychoPy 2020.1.2 on MacOS libportaudio.2 is appears in the folder “Frameworks”. Copying the following list of files to the “lib-dynload/pyo” directory allows me to import pyo without the previous error ("image not found - even when typed to the shell). BUT this does result in a bug where the window doesn’t open, and means that I cannot reopen PsychoPy when I close it and reopen it.

Hoping to take another look at this soon as i am also trying to use the mic component, but posting update here incase helpful.

BeccaScreen Shot 2020-05-12 at 13.06.14

Hi @Hannah96, I was wondering if you were ever able to fix this problem as I’m dealing with the same issue (i.e. pyo image not found error with IOS and empty recordings with Win).

Hi @Marti_na,
I was not able to resolve the issue. I ended up going to a different program. Sorry!

1 Like

Hi @Marti_na , I think the suggestion by @belangeo above is the solution, but it is one that needs implementing on the psychopy source code rather than your local copy :slight_smile: (it is something I was hoping to try and get around to soon as also using the mic on mac!) @jon might be able to advise more if this solution sounds simple to implement?

1 Like

Hi everybody! I was wondering, since I need to use audio recording only to collect data that is not time-sensitive (latency is fine), is there any other option to make it work in PsychoPy3 ? Maybe using other sound libraries I’ve read about like sounddevice or pygame instead of pyo library?

Thanks,
Renato

The plan is to switch to using psychtoolbox lib for this, as we’ve done for audio outputs, which should have superior timing. I just haven’t had time to get there yet. :-/

Thank you @Hannah96, @lpxrh6 and @jon for taking the time to reply!

It seems @belangeo solution is not implementable here because we cannot manually change the source (the file is already complied) (which is probably also why @lpxrh6 attempt to copy the libraries resulted in PsychoPy not reopening).

Thank you all anyway!