# Microphone component with errors on Mac (permissions)

**URL:** <https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269>\
**Category:** Builder\
**Created:** [August 3, 2022, 3:26pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269 "2022-08-03T15:26:52Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwinston](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/bwinston/32/14629_2.png) [@bwinston](https://discourse.psychopy.org/u/bwinston)\
**Post date:** [August 3, 2022, 3:26pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/1 "2022-08-03T15:26:53Z")

</div>

**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](https://discourse.psychopy.org/t/how-to-use-microphone-component/24602/5).

Any help would be appreciated please.

---

<div class="post-metadata">

**Author:** ![abhandari](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/abhandari/32/34951_2.png) [@abhandari](https://discourse.psychopy.org/u/abhandari)\
**Post date:** [August 3, 2022, 10:02pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/2 "2022-08-03T22:02:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bwinston](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/bwinston/32/14629_2.png) [@bwinston](https://discourse.psychopy.org/u/bwinston)\
**Post date:** [August 3, 2022, 11:15pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/3 "2022-08-03T23:15:18Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![abhandari](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/abhandari/32/34951_2.png) [@abhandari](https://discourse.psychopy.org/u/abhandari)\
**Post date:** [August 4, 2022, 2:26pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/4 "2022-08-04T14:26:19Z")

</div>

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.

> [@bwinston](#):
>
> `Device`

---

<div class="post-metadata">

**Author:** ![bwinston](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/bwinston/32/14629_2.png) [@bwinston](https://discourse.psychopy.org/u/bwinston)\
**Post date:** [August 4, 2022, 2:57pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/5 "2022-08-04T14:57:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![abhandari](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/abhandari/32/34951_2.png) [@abhandari](https://discourse.psychopy.org/u/abhandari)\
**Post date:** [August 4, 2022, 4:51pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/6 "2022-08-04T16:51:59Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![bwinston](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/bwinston/32/14629_2.png) [@bwinston](https://discourse.psychopy.org/u/bwinston)\
**Post date:** [August 4, 2022, 5:39pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/7 "2022-08-04T17:39:30Z")

</div>

Thanks either way for your help. Realize it’s the same unsolved problem [here](https://discourse.psychopy.org/t/no-sound-from-microphone/25790/12) as well.

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

Thanks all.

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [August 4, 2022, 8:33pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/8 "2022-08-04T20:33:28Z")

</div>

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). 🤔

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

> <https://github.com/psychopy/psychopy/blob/dev/building/entitlements.plist#L19>

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [August 4, 2022, 8:39pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/9 "2022-08-04T20:39:18Z")

</div>

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

[Apple Developer Documentation](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_device_audio-input)

**as well** as there being a `...microphone`

[Apple Developer Documentation](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_device_microphone)

…so maybe we need both.

Apple, why do you torture us so? 😭

---

<div class="post-metadata">

**Author:** ![bwinston](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/bwinston/32/14629_2.png) [@bwinston](https://discourse.psychopy.org/u/bwinston)\
**Post date:** [August 5, 2022, 12:55am UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/10 "2022-08-05T00:55:55Z")

</div>

🤦‍♂️ 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

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [August 8, 2022, 9:27am UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/11 "2022-08-08T09:27:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![frankgarcea](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@frankgarcea](https://discourse.psychopy.org/u/frankgarcea)\
**Post date:** [March 11, 2023, 5:25pm UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/12 "2023-03-11T17:25:31Z")

</div>

Dear Jon,

I’m wondering if there is anything that we need to do to adjust the microphone settings when we get this error?

Some have found their wav files are empty. My picture naming task can run and capture wav files, but it will often freeze mid experiment. Never can I run the experiment three times in a row without a crash. It’s very strange. Yet other experiments requiring a verbal response with the same audio library, microphone, etc., can run successfully without issue.

I’ve documented the issue here: [Saving trial-level audio output in real time](https://discourse.psychopy.org/t/saving-trial-level-audio-output-in-real-time/32962)

I’ve tried using all different kinds of microphones, adjusting the frequency range, changing the audio library, opening PsychoPy within the terminal. I continue to get the same error.

||PaMacCore (AUHAL)|| Error on line 520: err=‘‘what’’, msg=Unspecified Audio Hardware Error

Any input would be much appreciated.

Thanks,  
FG

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [March 13, 2023, 10:02am UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/13 "2023-03-13T10:02:19Z")

</div>

Hi Frank,

I don’t think your crashes are anything to do with the issue listed in this post, which was caused by a permissions issue in MacOS Gatekeeper and is now solved. For your errors, if some experiments run and others don’t the key next step is to work out what the “minimal working demonstration” of the problem is: what experiment is just enough to make the crashes occur? If you take your working experiment and _gradually_ change it into you not working experiment you can hopefully work out the point where it stops working

But I’m closing this thread because I believe the permissions issue for macos is now solved

thanks  
Jon

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [March 13, 2023, 10:03am UTC](https://discourse.psychopy.org/t/microphone-component-with-errors-on-mac-permissions/30269/14 "2023-03-13T10:03:02Z")

</div>


