cpal icon indicating copy to clipboard operation
cpal copied to clipboard

macOS asks for permission to use the microphone when accessing the default output device

Open tautropfli opened this issue 1 year ago • 2 comments

When I run the following code from the terminal on macOS (using cargo run)

use cpal::traits::HostTrait as _;

fn main() {
    let _ = cpal::default_host().default_output_device();
}

I get a microphone permission prompt from macOS:

Screenshot 2024-07-19 at 20 40 58

If you want to reproduce this and the permission prompt does not appear you may have already granted or denied permissions to your terminal. You can easily reset them using tccutil. For example tccutil reset Microphone com.apple.Terminal for macOS' builtin terminal.

This issue was originally reported to Bevy: https://github.com/bevyengine/bevy/issues/13989

I tested this on macOS Ventura (13.6.7).

tautropfli avatar Jul 19 '24 18:07 tautropfli

Note that this is currently resulting in most (all?) Bevy games on macOS asking for microphone permissions 😅 Are there some settings we can pass to cpal to work around this?

janhohenheim avatar Jul 20 '24 21:07 janhohenheim

Any progress on this issue, please?

ayangweb avatar Mar 18 '25 02:03 ayangweb

So I tried your minimal example on my machine with macOS 15.7.2, and before that ran tccutil reset Microphone com.apple.Terminal. Can't reproduce it on latest master... has it since been fixed or is it still occurring for you?

It it does still occur for you, from a code review it could be that is_default_device is the culprit. Please try PR #1070 and report back.

roderickvd avatar Dec 10 '25 21:12 roderickvd

I could not reproduce (using the provided snippet) in Sonoma 14.4.1 either (using the builtin terminal)... I will try some of the Bevy examples to see if that triggers the issue.

EDIT: Tested both cpal 0.16 and 0.15 versions. Bevy examples did not trigger this for me either.

mnmaita avatar Dec 11 '25 10:12 mnmaita

That would be excellent news :) Unfortunately I no longer have any computer running macOS, so I cannot test it on the same hardware that reproduced the behavior in Bevy apps.

janhohenheim avatar Dec 11 '25 11:12 janhohenheim

I've merged that PR without feedback, because I hope to include it in v0.17. From a code review I believe this should cure it, should it still occur - @mnmaita and myself couldn't reproduce it anymore on the provided minimal example. If it still isn't fix for your cases, feel free to reopen.

roderickvd avatar Dec 12 '25 10:12 roderickvd