Audio Passthrough

Hi,

I'm trying to pass audio through from an input directly to the built-in speakers in a macOS app. It's to go along with passing through video to the form. I have successfully populated an AVCaptureDevice object and then initialised an AVCaptureDeviceInput from it. I've then added it as an input to my session. Am I missing something to actually output the session to the speakers though?

Thanks, Jimmy

-(void) initCaptureSession {
    session = [[AVCaptureSession alloc] init];

    if ([session canSetSessionPreset : AVCaptureSessionPresetHigh])
        [session setSessionPreset : AVCaptureSessionPresetHigh];

    if (@available(macOS 10.14, *)) {
        if ([AVCaptureDevice authorizationStatusForMediaType: AVMediaTypeVideo] == AVAuthorizationStatusNotDetermined)
        {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                if (granted) {
                    //self.videoConsentState = PrivacyConsentStateGranted;
                }
                else {
                    //self.videoConsentState = PrivacyConsentStateDenied;
                }}];
        }
    } else {
        // Fallback on earlier versions
    }

    AVCaptureDevice *device = nil;
    AVCaptureDeviceInput *device_input = nil;

    NSArray *devices = [AVCaptureDevice devicesWithMediaType : AVMediaTypeVideo];

    for (AVCaptureDevice *dev in devices){
        if ([dev.localizedName isEqualToString:@"USB Video"]){
            device = dev;
        }
    }

    if (device != nil){
        device_input = [[AVCaptureDeviceInput alloc] initWithDevice : device error : nil];

        [session addInput : device_input];
    }
   
    if (@available(macOS 10.14, *)) {
        if ([AVCaptureDevice authorizationStatusForMediaType: AVMediaTypeAudio] == AVAuthorizationStatusNotDetermined)
        {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
                if (granted) {
                    //self.microphoneConsentState = PrivacyConsentStateGranted;
                }
                else {
                    //self.microphoneConsentState = PrivacyConsentStateDenied;
                }}];
        }
    } else {
        // Fallback on earlier versions
    }

    AVCaptureDevice *audioDevice = nil;
    AVCaptureDeviceInput *audioDevice_input = nil;

    NSArray *audioDevices = [AVCaptureDevice devicesWithMediaType : AVMediaTypeAudio];

    for (AVCaptureDevice *dev in audioDevices){
        if ([dev.localizedName isEqualToString:@"USB Digital Audio"]){
            audioDevice = dev;
        }
    }

    if (audioDevice != nil){
        audioDevice_input = [[AVCaptureDeviceInput alloc] initWithDevice : audioDevice error : nil];
        [session addInput : audioDevice_input];
    }
}

-(void) setupPreviewLayer {
    self.preview_layer = [[AVCaptureVideoPreviewLayer alloc] initWithSession : session];
    [self.preview_layer setVideoGravity : AVLayerVideoGravityResizeAspectFill];
    [self.preview_layer setFrame : self.view.bounds];
    [self.view.layer addSublayer : self.preview_layer];

    if (![session isRunning]){
        [session startRunning];
    }
}
Audio Passthrough
 
 
Q