1

I'm trying to set up an AudioQueue to stream audio from the microphone on an iPhone.

I create my audio engine:

var audioEngine = AVAudioEngine()

And my audio queue:

    // Serial dispatch queue used to analyze incoming audio buffers.
    let analysisQueue = DispatchQueue(label: "com.apple.AnalysisQueue")


    // Install an audio tap on the audio engine's input node.
    audioEngine.inputNode.installTap(onBus: 0,
                                     bufferSize: 8192, // 8k buffer
                                     format: inputFormat) { buffer, time in

        // Analyze the current audio buffer.
        analysisQueue.async {
        }
    }

Whenever I run the code on the simulator or the device, I get the following crash:

*** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: inputNode != nullptr || outputNode != nullptr'

I was following some Apple sample code while making this; somewhat confused. Any help appreciated!

EDIT: this question from a few days ago seems to point to a similar issue: AVAudioEngine.connect crash on hardware not simulator

narner
  • 2,908
  • 3
  • 26
  • 63
  • First result in Google for `required condition is false: inputNode != nullptr || outputNode != nullptr`: https://forums.developer.apple.com/thread/44833 – Alejandro Iván Oct 22 '19 at 01:08

1 Answers1

0

I somehow missed this thread while googling; but thanks to @SOreadytohelp I got it working -- just add

audioEngine.mainMixerNode

right above

do {
    // Start the stream of audio data.
    try audioEngine.start()
} catch {
    print("Unable to start AVAudioEngine: \(error.localizedDescription)")
}
narner
  • 2,908
  • 3
  • 26
  • 63
  • HI @narner, just call the above line of code and do nothing? If that, it will show warning `Expression of type 'AVAudioMixerNode' is unused`. – trunghvbk Jul 05 '23 at 07:56