AudioQueue records silence

Hi. I'm working my way through chapter 4 of the "Learning Core Audio" book. Before that I tried recording audio using the AudioToolbox with Swift. No matter what I do, I only record silence.

Having tried several examples from different sources I'm pretty sure my source code is not the issue. I enabled "Audio Input" for my target in XCode. I disconnected all external audio inputs and uninstalled a DAW that had created an aggregate I/O device. Still I'm not hearing anything from the file that's supposed to play my recorded audio.

Does anyone have an idea or has faced the issue before? Thanks in advance.
Hello!

I have struggled with this problem too today. I don't know if this is the solution for you, but the symptoms sound similar.

The problem is with sandbox permissions.

You seem to have enabled the sandbox, as well as set the value for Audio Input to 'Yes' for your app.

This is a good step on the way, but not the complete recipe for success.

Next you need to implement in code the process of getting authorisation to use the microphone (or other channels) from the user.

For an absolute dummy proof of concept, you will need this variable and function:

    var autorised = false
    func setupCaptureSession() {
        autorised = true
    }

Then before you do anything to do with the audio input initialisation, add this to the function that sets up the audio:

        switch AVCaptureDevice.authorizationStatus(for: .audio) {
        case .authorized:
            print("Authorised")
setupCaptureSession()
        case .denied:
            print("Denied")
        case .notDetermined:
            AVCaptureDevice.requestAccess(for: .audio) { granted in
                        if granted {
                            self.setupCaptureSession()
                        }
                    }
        case .restricted:
            print("Restricted")
        default:
            print("Unexpected Value")
        }

        while !autorised {
            usleep(250000)
        }

This is absolutely a dummy solution, but it shows the steps needed. I would rather move the audio initialisation code inside the setup function instead of waiting for the authorised value to change.

But wait! This will crash your app with the message that you need to set a usage reason in your applications Info.plist.

The key you are looking for is:
Privacy - Microphone Usage Description

This absolutely needs a value, or your app will crash when you ask for permission to use the microphone. I would suggest to put a proper description to begin with, or you may forget and get the app rejected when you at one point try to submit it to the App Store.

I had silence from the microphone all day. Even turning off the sandbox made no difference. I had to ask the user (me, myself and I) for permission to use the microphone.
AudioQueue records silence
 
 
Q