cirruslabs / tart

macOS and Linux VMs on Apple Silicon to use in CI and other automations
https://tart.run
Other
3.8k stars 111 forks source link

Pass in Microphone #764

Open Nahiiko opened 6 months ago

Nahiiko commented 6 months ago

Hi,

It seems it's not possible to pass through the microphone (or any audio input) to the VM (tried with sonoma-base only) The Audio Output seems to work fine.

Although #161 seems to point at the fact that it is indeed supported, am I doing something wrong ?

fkorotkov commented 6 months ago

VMs should use whatever is set as output/input in your preferences on the host. Do you have the microphone selected there?

Nahiiko commented 6 months ago

I see what you mean, but it doesn't seem to work for some reason, am on an M1 macbook air, here you can see the host config (you can see my voice being picked up by the mic):

Screenshot 2024-03-24 at 09 41 33

And here sonoma-base's config using tart (no voice being picked up):

Screenshot 2024-03-24 at 09 41 56
fkorotkov commented 6 months ago

I just tried to reproduce and it seems I'm able both to record and output voice inside a VM. I'm using both Sonoma host and guest. Note that guest will always show "Built-in" input/output even though it's donna use what is specified on the host.

Nahiiko commented 6 months ago

Mh, a few questions:

fkorotkov commented 6 months ago

BTW are you running a suspendable VM by any chance? Suspendable VMs don't support audio:

https://github.com/cirruslabs/tart/blob/1a3b862631fe576c62ad2adc023f7971b3f8605f/Sources/tart/VM.swift#L298-L306

Otherwise the default VZHostAudioInputStreamSource and VZHostAudioOutputStreamSink are used.

Nahiiko commented 6 months ago

I run the regular tart run sonoma-base cmd in zsh, also the sound output works fine

edit: updated to sonoma 14.4.1, still got the issue, so not related to that.

edigaryev commented 5 months ago

https://developer.apple.com/documentation/virtualization/audio says:

If your app can configure an audio input device, you must set an NSMicrophoneUsageDescription message in your app’s Info.plist. The system uses this description when asking the user’s permission to enable microphone access. If this message isn’t set or the key isn’t present, the system denies microphone access to your app.

So it seems that we need to ask for a permission first to make the microphone work.

Nahiiko commented 5 months ago

Very interesting !

Or could it be that I need to give mic permission to the terminal ? Trying this asap

edit: it worked ! giving permissions to the terminal in settings :)

Screenshot 2024-05-03 at 13 45 57

Although I don't think that's a good practice long term