How do I forward audio from the default input to the default output on MacOS?

I'm trying to write a very simple MacOS application that is supposed to forward audio from the default input to the default output. The idea is to understand how to use AVAudioEngine properly, but unfortunately I can't find a way to make this work.


Here's the code:


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    _engine = [AVAudioEngine new];
    [_engine connect:_engine.inputNode to:_engine.outputNode format:nil];
    [_engine prepare];
    NSError *error;
    [_engine startAndReturnError:&error];
}


When I run this code I get the following log messages in the console output:


2019-12-30 15:56:00.552046+0000 Audio Test[880:25101] [plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x600000254280> F8BB1C28-BAE8-11D6-9C31-00039315CD46
2019-12-30 15:56:00.566981+0000 Audio Test[880:25101]  HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine
2019-12-30 15:56:00.568909+0000 Audio Test[880:25101] [ddagg]        AggregateDevice.mm:790   couldn't get default input device, ID = 0, err = 0!
2019-12-30 15:56:00.582217+0000 Audio Test[880:25101] [avae]            AVAEInternal.h:88    required condition is false: [AVAudioEngine.mm:1055:CheckCanPerformIO: (canPerformIO)]

Sorry if this is not properly formatted, but I'm blind and the forums are very quirky to use with VoiceOver.

Accepted Reply

The solution turned out to be rather simple, I just had to add the com.apple.security.device.audio-input entitlement, the NSMicrophoneUsageDescription Info.plist key, and use AVCaptureDevice to request for permission to use the microphone. The error messages are still logged to the console, but it works.

  • Dog bless you... was throwing myself at this error for the past two days lmao

Add a Comment

Replies

The solution turned out to be rather simple, I just had to add the com.apple.security.device.audio-input entitlement, the NSMicrophoneUsageDescription Info.plist key, and use AVCaptureDevice to request for permission to use the microphone. The error messages are still logged to the console, but it works.

  • Dog bless you... was throwing myself at this error for the past two days lmao

Add a Comment