Microphone component with errors on Mac (unsolved issue)

OS Mac
PsychoPy version latest

What are you trying to achieve?:
Microphone recording with transcription turned off. Otherwise default settings.

What specifically went wrong when you tried that?:

Running: /Users/bwinston/Documents/2104/retrieval/psil_movie_retrieval_lastrun.py ##
763.1078 INFO Loaded monitor calibration from [‘2019_11_11 14:00’]
2022-08-03 11:24:40.924 python[29772:2947297] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
||PaMacCore (AUHAL)|| Error on line 520: err=‘’!dat’‘, msg=Audio Device: Unsupported Format
Traceback (most recent call last):
||PaMacCore (AUHAL)|| Error on line 520: err=’‘!dat’', msg=Audio Device: Unsupported Format
1.3271 WARNING Monitor specification not found. Creating a temporary one…
File “/Users/bwinston/Documents/2104/retrieval/psil_movie_retrieval_lastrun.py”, line 486, in
mic.stop()
File “/Applications/PsychoPy.app/Contents/Resources/lib/python3.8/psychopy/sound/microphone.py”, line 802, in stop
raise AudioStreamError(
psychopy.sound.exceptions.AudioStreamError: Cannot stop a stream that has not been started.
################ Experiment ended with exit code 1 [pid:29772] #################

Potentially same unsolved issue for many people here.

Any help would be appreciated please.

I did manage to diagnose this problem.

Did you have a duration set for the mic component? I suspect you don’t. If you don’t set a specific duration, there is a bug that will throw this error (discussed here: its in the queue for being addressed). If you set a specific duration, you will not get this error. The error is thrown because the default code generated by builder invokes mic.stop() as if a specified duration has been reached even though a duration is not specified.

thanks @abhandari. i think maybe you were referring to the last part of the error? this is not the main issue. even when specifying the start and stop duration, no recording actually takes place, nor is a file created, and i still get

||PaMacCore (AUHAL)|| Error on line 520: err=‘’!dat’‘, msg=Audio Device: Unsupported Format

Hi @bwinston emphasized text - im not familiar with the PaMacCore (AUHAL). That may be a Mac OS version issue. However, I did have the problem of not getting any .wav files saved.

The issue was Mic permissions - Mac OS needs explicit permission for giving mic access to a software. Unfortunately, PsychoPy standalone does not make that request. The workaround is to run Psychopy via the terminal. Something like: /Applications/PsychoPy.app/Contents/MacOS/PsychoPy
When you do that, you will see a mic permission request (as well as any other permission requests) made by Terminal. Once you provide these, you should start seeing saved .wav files.

1 Like

Wow @abhandari you are a wizard! The workaround you provided works. However, I am hesitant to mark this as the solution because booting PsychoPy with Terminal is less than ideal, especially for the research assistants who will be running our study. Do you know any way to make this work with PsychoPy booted normally? For example, maybe PsychoPy can be added manually via the Security & Privacy Menu?

Will be looking into this and will update. However, you’ve clarified that the issue is not the PaMacCore (AUHAUL) but rather PsychoPy not asking for permission to use the microphone (I imagine that would be an easy fix for the devs?)

Best,
Brian

Glad it worked.

No - I’ve tried various things, but there doesn’t seem to be any way to make it work without starting it through the terminal. At least for Big Sur, there is no way to explicitly add an arbitrary app to the app permission list. This is not a problem on Windows or Linux machines. Also, you only need to give permission once.

I’m sure there would be a way to fix for the developers - not sure how to tag them here!

1 Like

Thanks either way for your help. Realize it’s the same unsolved problem here as well.

@Becca @Michael any easy way PsychoPy could request microphone access on Macs? Maybe in a future version?

Thanks all.

That’s very strange! We certainly list mic as one of the required permissions when code-signing in what Apple calls “entitlements” as below. I believe that entitlements list should mean there isn’t even a need for the request in the dialog (ie. it’s already been granted). :thinking:

Alternatively, I don’t suppose it’s simply that the request is made while the window is fullscreen? Anyway, I’ll certainly look into this before the next release

1 Like

Actually…maybe this is an incorrect entitlement request. It looks like there’s an com.apple.security.device.audio-input:

Apple Developer Documentation

as well as there being a ...microphone

Apple Developer Documentation

…so maybe we need both.

Apple, why do you torture us so? :sob:

2 Likes

:man_facepalming: thanks for looking into this. in the meantime, do you see any downsides to running our experiment after launching /Applications/PsychoPy.app/Contents/MacOS/PsychoPy through the terminal?

Look forward to this hopefully working normally in the next release! Cheers

Ah, OK I’ve discovered that the microphone entitlement is only for sandboxed apps (typically for the app store) which PsychoPy actually isn’t, whereas audio-input is for hardened apps (signed and notarised) which PsychoPy is. So, basically Apple created 2 very similar sounding options and we got the wrong one.

Regarding the terminal, it’s annoying but I don’t see any problems with it.

best wishes
Jon