How to Record My MAC's Internal Sound, Not the Microphone!, Using Avcapturesession

How to record my Mac's internal sound, not the microphone!, using AVCaptureSession?

I have not found an easy way to do it but it turns out that it is possible to make the original code record the audio given that there is another software installed on my machine: Soundflower.

Soundflower is an open source kernel extension for MacOS, designed to create a virtual audio output device that can also act as an input.

Given that the Soundflower is installed, one can use configure the macOS using the Applications / Utilities / Audio MIDI Setup app to send the audio to both virtual and real audio devices. This way the code above captures the audio from the Soundflower but you can still hear it on your normal audio output device.

The setup of the Applications / Utilities / Audio MIDI Setup application is described here: How can I send my computer's audio to multiple outputs?.

AVCaptureSession for audio in simulator

The AVCaptureDevice class is not implemented on the simulator (as of this writing at least, maybe it will change in the future).

Try e.g.

NSLog(@"%@", [AVCaptureDevice devices]);

which will produce an empty list on the simulator (but will list all capture devices if compiled and run on a real iDevice).

This kind of functionality needs to be tested on a real device anyway (due to the hardware detail dependency, such as latency and sample formats supported), so for testing purposes it is not that important to have device support in the simulator. But it would indeed be nice to have it for demo purposes.

To have a demo running on the simulator, maybe you can mock the capture input. If you really want to spend some time on it, maybe you can fallback on the AVAudioRecorder for the simulator (I never used AVAudioRecorder, so I can't tell if it does or does not work on the simulator, but from your question I read that it does).

macOS/swift Capture Audio with AVCaptureSession

It's called for me. You don't show how you use it, but maybe your AudioCaptureSession is going out of scope and being deallocated.



Related Topics



Leave a reply



Submit