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
Draw Mkpointannotation with Title in Mksnapshot Image
How to Keep a Reference to Another Object in the Parameters of the Class
How to Create an Uppercase Version of a String in Swiftui
Uirefreshcontrol() in iOS 11 Glitchy Effect
Pop View Controller Using Screen Edge Pan Gesture Recogniser Not Following the Thumb
Swift Codable - Parse JSON Array Which Can Contain Different Data Type
How to Convert Tuple to Anyobject in Swift
Swift: Make Translucent Overlapping Lines of the Same Color Not Change Color When Intersecting
Consuming a Soap Web Service with Swift
Custom Intialiser on Primitive Types for JSONdecoder
Accessibility (Voice Over) with Sprite Kit
Prevent Redirect Response with Alamofire in Swift
Iterating Over an Nsorderedset
What Is the Slice Compare Logic in Swift
How to Send Data from iPhone to Watchkit in Os2 in Swift