Skip to content

[bug] Access the microphone fron Rust on macos #9928

Closed
@jafioti

Description

@jafioti

Describe the bug

I'm trying to record audio from rust, using cpal on macos. It seems to work correctly when the app is in dev mode, or built but not signed. Once the app is signed, even with the following Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSMicrophoneUsageDescription</key>
	<string>Request microphone access for voice input</string>
</dict>
</plist>

the permission popup does not appear and the microphone does not record any audio.

Is it possible to access the microphone from rust, or does it need to be done on the JS side?

Reproduction

Create a new app with an Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>NSMicrophoneUsageDescription</key>
	<string>Request microphone access for voice input</string>
</dict>
</plist>

and use cpal to start recording:

let device = cpal::default_host()
    .devices()
    .unwrap()
    .find(|d| d.name().unwrap() == "MacBook Pro Microphone")
    .unwrap();
let config = device.default_input_config().unwrap();
let sample_rate = config.sample_rate().0;
let channels = config.channels();

let clip = Arc::new(Mutex::new(Some(vec![])));
let clip_2 = clip.clone();

let stream = device
    .build_input_stream(
        &config.into(),
        move |data, _| write_input_data(data, &clip_2),
        move |err| eprintln!("an error occurred on stream: {err}"),
        None,
    )
    .unwrap();

stream.play().unwrap();

Expected behavior

This should request access to the microphone, show the recording icon in the rop right and start recording audio from the microphone, but when the app is built and signed none of that happens.

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.5.0 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (environment override by RUSTUP_TOOLCHAIN)
    - node: 22.2.0
    - npm: 10.8.0

[-] Packages
    - tauri [RUST]: 2.0.0-beta.20
    - tauri-build [RUST]: 2.0.0-beta.16
    - wry [RUST]: 0.40.0
    - tao [RUST]: 0.28.0
    - tauri-cli [RUST]: 2.0.0-beta.16
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-beta.16

[-] App
    - build-type: bundle
    - CSP: default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'; connect-src ipc: http://ipc.localhost
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: SolidJS
    - bundler: Vite

Stack trace

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions