Is it possible to get only audio from ScreenCaptureKit?

I'm creating app that listening other app's sound. in this use case, screen data is not needed.

but if I don't call SCStream#addStreamOutput(_, type: .screen, ...), console shows this error:

[ERROR] _SCStream_RemoteVideoQueueOperationHandlerWithError:701 stream output NOT found. Dropping frame

currently I'm setting SCStreamConfiguration#minimumFrameInterval to large value (e.g. 0.1fps) as workaround, but it would be good if i can completely disable screen capture for best performance.

there is any way to disable screen capture and only captures apps audio?

Answered by rinsuki in 812255022

finally We have a solution... for macOS 14.2 or later (but it isn't ScreenCaptureKit).

you can use AudioHardwareCreateProcessTap https://developer.apple.com/documentation/coreaudio/4160724-audiohardwarecreateprocesstap .

somewhat developer.apple.com doesn't have a any description, but SDK header files does. so all your need is read header file, instead of developer.apple.com/documentation

or you might be want to read example source code, https://github.com/insidegui/AudioCap (note: this isn't mine project)

well, it still lacks some features (on Public API), like get current permission status.

If your app aren't on App Store, you might be able to use TCC private API instead, but cleary not recommended.

Did you find a solution for this? I'm also hoping to capture audio only without the video data.

You can, but you also have to capture screen and just filter the samples out in the callback.

choose output type - audio in DidOutputSampleBuffer function and use avassetwriter to write the system audio buffer

The error you're seeing, stream output NOT found. Dropping frame, is related to memory management. Your stream output object has been cleared from the memory. Make sure you put it in an instance variable - self.output = streamOutput

Accepted Answer

finally We have a solution... for macOS 14.2 or later (but it isn't ScreenCaptureKit).

you can use AudioHardwareCreateProcessTap https://developer.apple.com/documentation/coreaudio/4160724-audiohardwarecreateprocesstap .

somewhat developer.apple.com doesn't have a any description, but SDK header files does. so all your need is read header file, instead of developer.apple.com/documentation

or you might be want to read example source code, https://github.com/insidegui/AudioCap (note: this isn't mine project)

well, it still lacks some features (on Public API), like get current permission status.

If your app aren't on App Store, you might be able to use TCC private API instead, but cleary not recommended.

Is it possible to get only audio from ScreenCaptureKit?
 
 
Q